Skip to content

High performance self-hosted photo and video management solution.

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

Sam Holtonf03381a5b1a6
diff --git a/server/src/domain/auth/auth.service.spec.ts b/server/src/domain/auth/auth.service.spec.ts
index 12eab5a63c..359b28a00c 100644
--- a/server/src/domain/auth/auth.service.spec.ts
+++ b/server/src/domain/auth/auth.service.spec.ts
@@ -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,
+ });
});
});
diff --git a/server/src/domain/auth/auth.service.ts b/server/src/domain/auth/auth.service.ts
index f0fc4585cc..fe01ef39b6 100644
--- a/server/src/domain/auth/auth.service.ts
+++ b/server/src/domain/auth/auth.service.ts
@@ -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 || ''}`;
diff --git a/server/test/fixtures/user.stub.ts b/server/test/fixtures/user.stub.ts
index e89e97bfd3..e0d9113c65 100644
--- a/server/test/fixtures/user.stub.ts
+++ b/server/test/fixtures/user.stub.ts
@@ -23,20 +23,6 @@ export const userDto = {
name: 'User with quota',
quotaSizeInBytes: 42,
},
- userWithDefaultStorageQuota: {
- email: '[email protected]',
- name: ' ',
- oauthId: 'my-auth-user-sub',
- quotaSizeInBytes: 1_073_741_824,
- storageLabel: null,
- },
- userWithStorageQuotaClaim: {
- email: '[email protected]',
- name: ' ',
- oauthId: 'my-auth-user-sub',
- quotaSizeInBytes: 5_368_709_120,
- storageLabel: null,
- },
};
export const userStub = {