mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
fix(server): unify profile image errors to prevent user-existence oracle via status code
GET /users/:id/profile-image returned HTTP 400 for an unknown user ID but HTTP 404 when the user existed without a photo, letting callers distinguish the two cases. Both now return 404 so the response is identical regardless of whether the UUID maps to an account.
This commit is contained in:
@@ -179,7 +179,7 @@ describe(UserService.name, () => {
|
|||||||
it('should throw an error if the user does not exist', async () => {
|
it('should throw an error if the user does not exist', async () => {
|
||||||
mocks.user.get.mockResolvedValue(void 0);
|
mocks.user.get.mockResolvedValue(void 0);
|
||||||
|
|
||||||
await expect(sut.getProfileImage(userStub.admin.id)).rejects.toBeInstanceOf(BadRequestException);
|
await expect(sut.getProfileImage(userStub.admin.id)).rejects.toBeInstanceOf(NotFoundException);
|
||||||
|
|
||||||
expect(mocks.user.get).toHaveBeenCalledWith(userStub.admin.id, {});
|
expect(mocks.user.get).toHaveBeenCalledWith(userStub.admin.id, {});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -134,8 +134,8 @@ export class UserService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getProfileImage(id: string): Promise<ImmichFileResponse> {
|
async getProfileImage(id: string): Promise<ImmichFileResponse> {
|
||||||
const user = await this.findOrFail(id, {});
|
const user = await this.userRepository.get(id, {});
|
||||||
if (!user.profileImagePath) {
|
if (!user || !user.profileImagePath) {
|
||||||
throw new NotFoundException('Not found');
|
throw new NotFoundException('Not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user