mirror of
https://github.com/immich-app/immich.git
synced 2024-12-25 10:43:13 +02: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:
parent
8d44afe915
commit
f03381a5b1
@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -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 || ''}`;
|
||||
|
14
server/test/fixtures/user.stub.ts
vendored
14
server/test/fixtures/user.stub.ts
vendored
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user