Skip to content

Commit

Permalink
fix: parse quota claim as number (immich-app#14178)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldietzler authored and yosit committed Nov 21, 2024
1 parent 64b68fa commit 3ba4648
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions server/src/services/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const oauthUserWithDefaultQuota = {
email,
name: ' ',
oauthId: sub,
quotaSizeInBytes: 1_073_741_824,
quotaSizeInBytes: '1073741824',
storageLabel: null,
};

Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions server/src/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 || ''}`;
Expand Down

0 comments on commit 3ba4648

Please sign in to comment.