Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/user/dto/update-password.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsNotEmpty, IsOptional } from 'class-validator';
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';

import { IsPassword } from 'src/common/validate';

Expand All @@ -7,7 +7,7 @@ export class UpdatePasswordDto {
* 旧密码
*/
@IsOptional()
@IsPassword()
@IsString()
oldPassword?: string;

/**
Expand Down
14 changes: 14 additions & 0 deletions test/user.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ describe('User crud (e2e)', () => {
.set('Accept', 'application/json')
.expect(200);

// 旧密码不符合当前强度策略时仍可改密(legacy 用户)
const legacyUserDoc = { ...mockUser(), password: 'abc123' };
const legacyUser = await userService.create(legacyUserDoc);
await request(app.getHttpServer())
.post(`/users/${legacyUser.id}/@updatePassword`)
.send({
oldPassword: 'abc123',
newPassword: '^tR123456',
})
.set('Content-Type', 'application/json')
.set('x-api-key', auth.apiKey)
.set('Accept', 'application/json')
.expect(204);

// username 不合法
await request(app.getHttpServer())
.patch(`/users/${user.id}`)
Expand Down
Loading