Fixing some transformation and logging sensitive data issues

This commit is contained in:
Collin Duncan 2023-06-28 21:40:29 +02:00
parent d947ad488f
commit 8a1da9925f
No known key found for this signature in database
2 changed files with 49 additions and 10 deletions

View file

@ -2,6 +2,7 @@ import { Exclude, Transform, Type } from 'class-transformer'
import { Dayjs } from 'dayjs'
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'
import dayjs from '../common/dayjs'
import { TransformationType } from 'class-transformer'
@Entity({ name: 'reservations' })
export class Reservation {
@ -17,14 +18,44 @@ export class Reservation {
@Column('varchar', { length: 255, nullable: false })
password: string
@Column('datetime', { nullable: false })
@Column('datetime', {
nullable: false,
transformer: {
to: (value: Dayjs) => value.format(),
from: (value: Date) => dayjs(value),
},
})
@Type(() => Dayjs)
@Transform(({ value }) => dayjs(value).format())
@Transform(({ value, type }) => {
switch (type) {
case TransformationType.PLAIN_TO_CLASS:
return dayjs(value)
case TransformationType.CLASS_TO_PLAIN:
return value.format()
default:
return value
}
})
dateRangeStart: Dayjs
@Column('datetime', { nullable: false })
@Column('datetime', {
nullable: false,
transformer: {
to: (value: Dayjs) => value.format(),
from: (value: Date) => dayjs(value),
},
})
@Type(() => Dayjs)
@Transform(({ value }) => dayjs(value).format())
@Transform(({ value, type }) => {
switch (type) {
case TransformationType.PLAIN_TO_CLASS:
return dayjs(value)
case TransformationType.CLASS_TO_PLAIN:
return value.format()
default:
return value
}
})
dateRangeEnd: Dayjs
@Column('varchar', { length: 32, nullable: false })
@ -56,9 +87,13 @@ export class Reservation {
*/
@Exclude()
public isAvailableForReservation(): boolean {
return dayjs().diff(this.dateRangeStart, 'day') <= 7
return this.dateRangeStart.diff(dayjs(), 'day') <= 7
}
/**
* Get the date which a reservation can be made
* @returns the date from which a reservation is allowed to be made
*/
@Exclude()
public getAllowedReservationDate(): Dayjs {
return this.dateRangeStart

View file

@ -5,6 +5,7 @@ import { EmptyPage } from '../pages/empty'
import dayjs from '../../common/dayjs'
import { Reservation } from '../../reservations/entity'
import { LoggerService } from 'src/logger/service'
import { instanceToPlain } from 'class-transformer'
const baanReserverenRoot = 'https://squashcity.baanreserveren.nl'
@ -100,7 +101,9 @@ export class BaanReserverenService {
}
private async init(reservation: Reservation) {
this.loggerService.debug('Initializing', { reservation })
this.loggerService.debug('Initializing', {
reservation: instanceToPlain(reservation),
})
await this.page.goto(baanReserverenRoot)
const action = this.checkSession(reservation.username)
switch (action) {
@ -142,7 +145,6 @@ export class BaanReserverenService {
throw new RunnerNavigationMonthError(e)
})
}
await this.page
?.waitForSelector(
`td#cal_${date.get('year')}_${date.get('month') + 1}_${date.get(
@ -169,7 +171,9 @@ export class BaanReserverenService {
}
private async selectAvailableTime(reservation: Reservation): Promise<void> {
this.loggerService.debug('Selecting available time', { reservation })
this.loggerService.debug('Selecting available time', {
reservation: instanceToPlain(reservation),
})
let freeCourt: ElementHandle | null | undefined
let i = 0
const possibleDates = reservation.createPossibleDates()
@ -187,7 +191,7 @@ export class BaanReserverenService {
throw new NoCourtAvailableError()
}
this.loggerService.debug('Free court found', { freeCourt })
this.loggerService.debug('Free court found')
await freeCourt.click().catch((e: Error) => {
throw new RunnerCourtSelectionError(e)
@ -197,7 +201,7 @@ export class BaanReserverenService {
private async selectOpponent(id: string, name: string): Promise<void> {
this.loggerService.debug('Selecting opponent', { id, name })
const player2Search = await this.page
?.waitForSelector('tr.res-make-player-2 > td > input')
?.waitForSelector('input:has(~ select[name="players[2]"])')
.catch((e: Error) => {
throw new RunnerOpponentSearchError(e)
})