mirror of
https://github.com/immich-app/immich.git
synced 2025-01-01 08:31: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:
parent
8d44afe915
commit
f03381a5b1
3 changed files with 28 additions and 22 deletions
|
@ -15,7 +15,6 @@ import {
|
||||||
newUserTokenRepositoryMock,
|
newUserTokenRepositoryMock,
|
||||||
sharedLinkStub,
|
sharedLinkStub,
|
||||||
systemConfigStub,
|
systemConfigStub,
|
||||||
userDto,
|
|
||||||
userStub,
|
userStub,
|
||||||
userTokenStub,
|
userTokenStub,
|
||||||
} from '@test';
|
} from '@test';
|
||||||
|
@ -53,6 +52,14 @@ const fixtures = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const oauthUserWithDefaultQuota = {
|
||||||
|
email: email,
|
||||||
|
name: ' ',
|
||||||
|
oauthId: sub,
|
||||||
|
quotaSizeInBytes: 1_073_741_824,
|
||||||
|
storageLabel: null,
|
||||||
|
};
|
||||||
|
|
||||||
describe('AuthService', () => {
|
describe('AuthService', () => {
|
||||||
let sut: AuthService;
|
let sut: AuthService;
|
||||||
let accessMock: jest.Mocked<IAccessRepositoryMock>;
|
let accessMock: jest.Mocked<IAccessRepositoryMock>;
|
||||||
|
@ -502,7 +509,7 @@ describe('AuthService', () => {
|
||||||
loginResponseStub.user1oauth,
|
loginResponseStub.user1oauth,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(userMock.create).toHaveBeenCalledWith(userDto.userWithDefaultStorageQuota);
|
expect(userMock.create).toHaveBeenCalledWith(oauthUserWithDefaultQuota);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ignore an invalid storage quota', async () => {
|
it('should ignore an invalid storage quota', async () => {
|
||||||
|
@ -516,8 +523,9 @@ describe('AuthService', () => {
|
||||||
loginResponseStub.user1oauth,
|
loginResponseStub.user1oauth,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(userMock.create).toHaveBeenCalledWith(userDto.userWithDefaultStorageQuota);
|
expect(userMock.create).toHaveBeenCalledWith(oauthUserWithDefaultQuota);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ignore a negative quota', async () => {
|
it('should ignore a negative quota', async () => {
|
||||||
configMock.load.mockResolvedValue(systemConfigStub.withDefaultStorageQuota);
|
configMock.load.mockResolvedValue(systemConfigStub.withDefaultStorageQuota);
|
||||||
userMock.getByEmail.mockResolvedValue(null);
|
userMock.getByEmail.mockResolvedValue(null);
|
||||||
|
@ -529,10 +537,10 @@ describe('AuthService', () => {
|
||||||
loginResponseStub.user1oauth,
|
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);
|
configMock.load.mockResolvedValue(systemConfigStub.withDefaultStorageQuota);
|
||||||
userMock.getByEmail.mockResolvedValue(null);
|
userMock.getByEmail.mockResolvedValue(null);
|
||||||
userMock.getAdmin.mockResolvedValue(userStub.user1);
|
userMock.getAdmin.mockResolvedValue(userStub.user1);
|
||||||
|
@ -543,7 +551,13 @@ describe('AuthService', () => {
|
||||||
loginResponseStub.user1oauth,
|
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 () => {
|
it('should use a valid storage quota', async () => {
|
||||||
|
@ -557,7 +571,13 @@ describe('AuthService', () => {
|
||||||
loginResponseStub.user1oauth,
|
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, {
|
const storageQuota = this.getClaim(profile, {
|
||||||
key: storageQuotaClaim,
|
key: storageQuotaClaim,
|
||||||
default: defaultStorageQuota,
|
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 || ''}`;
|
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',
|
name: 'User with quota',
|
||||||
quotaSizeInBytes: 42,
|
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 = {
|
export const userStub = {
|
||||||
|
|
Loading…
Reference in a new issue