1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 07:01:59 +00:00

feat(server): allow oauth claim to set 0 for no quota (#7581)

* feat(server): allow oauth claim to set 0 for no quota

* PR feedback to remove extra objects from user.stub.ts
This commit is contained in:
Sam Holton 2024-03-02 15:18:56 -05:00 committed by GitHub
parent 8d44afe915
commit f03381a5b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 22 deletions

View file

@ -15,7 +15,6 @@ import {
newUserTokenRepositoryMock,
sharedLinkStub,
systemConfigStub,
userDto,
userStub,
userTokenStub,
} from '@test';
@ -53,6 +52,14 @@ const fixtures = {
},
};
const oauthUserWithDefaultQuota = {
email: email,
name: ' ',
oauthId: sub,
quotaSizeInBytes: 1_073_741_824,
storageLabel: null,
};
describe('AuthService', () => {
let sut: AuthService;
let accessMock: jest.Mocked<IAccessRepositoryMock>;
@ -502,7 +509,7 @@ describe('AuthService', () => {
loginResponseStub.user1oauth,
);
expect(userMock.create).toHaveBeenCalledWith(userDto.userWithDefaultStorageQuota);
expect(userMock.create).toHaveBeenCalledWith(oauthUserWithDefaultQuota);
});
it('should ignore an invalid storage quota', async () => {
@ -516,8 +523,9 @@ describe('AuthService', () => {
loginResponseStub.user1oauth,
);
expect(userMock.create).toHaveBeenCalledWith(userDto.userWithDefaultStorageQuota);
expect(userMock.create).toHaveBeenCalledWith(oauthUserWithDefaultQuota);
});
it('should ignore a negative quota', async () => {
configMock.load.mockResolvedValue(systemConfigStub.withDefaultStorageQuota);
userMock.getByEmail.mockResolvedValue(null);
@ -529,10 +537,10 @@ describe('AuthService', () => {
loginResponseStub.user1oauth,
);
expect(userMock.create).toHaveBeenCalledWith(userDto.userWithDefaultStorageQuota);
expect(userMock.create).toHaveBeenCalledWith(oauthUserWithDefaultQuota);
});
it('should ignore a 0 quota', async () => {
it('should not set quota for 0 quota', async () => {
configMock.load.mockResolvedValue(systemConfigStub.withDefaultStorageQuota);
userMock.getByEmail.mockResolvedValue(null);
userMock.getAdmin.mockResolvedValue(userStub.user1);
@ -543,7 +551,13 @@ describe('AuthService', () => {
loginResponseStub.user1oauth,
);
expect(userMock.create).toHaveBeenCalledWith(userDto.userWithDefaultStorageQuota);
expect(userMock.create).toHaveBeenCalledWith({
email: email,
name: ' ',
oauthId: sub,
quotaSizeInBytes: null,
storageLabel: null,
});
});
it('should use a valid storage quota', async () => {
@ -557,7 +571,13 @@ describe('AuthService', () => {
loginResponseStub.user1oauth,
);
expect(userMock.create).toHaveBeenCalledWith(userDto.userWithStorageQuotaClaim);
expect(userMock.create).toHaveBeenCalledWith({
email: email,
name: ' ',
oauthId: sub,
quotaSizeInBytes: 5_368_709_120,
storageLabel: null,
});
});
});

View file

@ -264,7 +264,7 @@ export class AuthService {
const storageQuota = this.getClaim(profile, {
key: storageQuotaClaim,
default: defaultStorageQuota,
isValid: (value: unknown) => isNumber(value) && value > 0,
isValid: (value: unknown) => isNumber(value) && value >= 0,
});
const userName = profile.name ?? `${profile.given_name || ''} ${profile.family_name || ''}`;

View file

@ -23,20 +23,6 @@ export const userDto = {
name: 'User with quota',
quotaSizeInBytes: 42,
},
userWithDefaultStorageQuota: {
email: 'test@immich.com',
name: ' ',
oauthId: 'my-auth-user-sub',
quotaSizeInBytes: 1_073_741_824,
storageLabel: null,
},
userWithStorageQuotaClaim: {
email: 'test@immich.com',
name: ' ',
oauthId: 'my-auth-user-sub',
quotaSizeInBytes: 5_368_709_120,
storageLabel: null,
},
};
export const userStub = {