From a14e01f3e0a69cb0e1319eb71730f1b501808cc0 Mon Sep 17 00:00:00 2001 From: Daniel Dietzler Date: Sat, 16 Nov 2024 22:54:28 +0100 Subject: [PATCH] fix: parse quota claim as number --- server/src/services/auth.service.spec.ts | 8 ++++---- server/src/services/auth.service.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/src/services/auth.service.spec.ts b/server/src/services/auth.service.spec.ts index 3701d3de56877..d34e2673f56ef 100644 --- a/server/src/services/auth.service.spec.ts +++ b/server/src/services/auth.service.spec.ts @@ -53,7 +53,7 @@ const oauthUserWithDefaultQuota = { email, name: ' ', oauthId: sub, - quotaSizeInBytes: 1_073_741_824, + quotaSizeInBytes: '1073741824', storageLabel: null, }; @@ -567,7 +567,7 @@ describe('AuthService', () => { oauthResponse, ); - expect(userMock.create).toHaveBeenCalledWith(oauthUserWithDefaultQuota); + expect(userMock.create).toHaveBeenCalledWith({ ...oauthUserWithDefaultQuota, quotaSizeInBytes: 1_073_741_824 }); }); it('should ignore an invalid storage quota', async () => { @@ -581,7 +581,7 @@ describe('AuthService', () => { oauthResponse, ); - expect(userMock.create).toHaveBeenCalledWith(oauthUserWithDefaultQuota); + expect(userMock.create).toHaveBeenCalledWith({ ...oauthUserWithDefaultQuota, quotaSizeInBytes: 1_073_741_824 }); }); it('should ignore a negative quota', async () => { @@ -595,7 +595,7 @@ describe('AuthService', () => { oauthResponse, ); - expect(userMock.create).toHaveBeenCalledWith(oauthUserWithDefaultQuota); + expect(userMock.create).toHaveBeenCalledWith({ ...oauthUserWithDefaultQuota, quotaSizeInBytes: 1_073_741_824 }); }); it('should not set quota for 0 quota', async () => { diff --git a/server/src/services/auth.service.ts b/server/src/services/auth.service.ts index b0094ae9edba9..0d44fa0562235 100644 --- a/server/src/services/auth.service.ts +++ b/server/src/services/auth.service.ts @@ -1,5 +1,5 @@ import { BadRequestException, ForbiddenException, Injectable, UnauthorizedException } from '@nestjs/common'; -import { isNumber, isString } from 'class-validator'; +import { isString } from 'class-validator'; import cookieParser from 'cookie'; import { DateTime } from 'luxon'; import { IncomingHttpHeaders } from 'node:http'; @@ -226,7 +226,7 @@ export class AuthService extends BaseService { const storageQuota = this.getClaim(profile, { key: storageQuotaClaim, default: defaultStorageQuota, - isValid: (value: unknown) => isNumber(value) && value >= 0, + isValid: (value: unknown) => Number(value) >= 0, }); const userName = profile.name ?? `${profile.given_name || ''} ${profile.family_name || ''}`;