fix: email normalization test

This commit is contained in:
bo0tzz
2026-04-16 21:50:37 +02:00
parent b42fdcfca9
commit 9b7f75a407
+11 -9
View File
@@ -757,24 +757,26 @@ describe(AuthService.name, () => {
expect(mocks.oauthLinkToken.create).toHaveBeenCalledTimes(1); expect(mocks.oauthLinkToken.create).toHaveBeenCalledTimes(1);
}); });
it('should normalize the email from the OAuth profile before linking', async () => { it('should normalize the email from the OAuth profile before looking up user', async () => {
const user = UserFactory.create(); const user = UserFactory.create();
const profile = OAuthProfileFactory.create({ email: ' TEST@IMMICH.CLOUD ' }); const profile = OAuthProfileFactory.create({ email: ' TEST@IMMICH.CLOUD ' });
mocks.systemMetadata.get.mockResolvedValue(systemConfigStub.oauthEnabled); mocks.systemMetadata.get.mockResolvedValue(systemConfigStub.oauthEnabled);
mocks.oauth.getProfileAndOAuthSid.mockResolvedValue({ profile }); mocks.oauth.getProfileAndOAuthSid.mockResolvedValue({ profile });
mocks.user.getByEmail.mockResolvedValue(user); mocks.user.getByEmail.mockResolvedValue(user);
mocks.user.update.mockResolvedValue(user); mocks.oauthLinkToken.deleteByEmail.mockResolvedValue();
mocks.session.create.mockResolvedValue(SessionFactory.create()); mocks.oauthLinkToken.create.mockResolvedValue({} as any);
await sut.callback( await expect(
{ url: 'http://immich/auth/login?code=abc123', state: 'xyz789', codeVerifier: 'foobar' }, sut.callback(
{}, { url: 'http://immich/auth/login?code=abc123', state: 'xyz789', codeVerifier: 'foobar' },
loginDetails, {},
); loginDetails,
),
).rejects.toThrow(ForbiddenException);
expect(mocks.user.getByEmail).toHaveBeenCalledWith('test@immich.cloud'); expect(mocks.user.getByEmail).toHaveBeenCalledWith('test@immich.cloud');
expect(mocks.user.update).toHaveBeenCalledWith(user.id, { oauthId: profile.sub }); expect(mocks.user.update).not.toHaveBeenCalled();
}); });
it('should not link to a user with a different oauth sub', async () => { it('should not link to a user with a different oauth sub', async () => {