优化结构
This commit is contained in:
@@ -140,6 +140,23 @@ func TestLoginRecordsSuccessBeforeMultipointCacheFailure(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoginResultDoesNotExposePasswordHash(t *testing.T) {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte("secret"), bcrypt.MinCost)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
user := &User{ID: 1, Username: "admin", Password: string(hash), AuthorityID: 888, Enable: 1}
|
||||
security := NewSecurityUsecase(&authenticationSecurityRepo{}, &authenticationCache{}, &authenticationSettings{}, nil)
|
||||
uc := NewAuthenticationUsecase(NewUserUsecase(&authenticationUserRepo{user: user}), security, &authenticationIssuer{}, nil)
|
||||
result, err := uc.Login(context.Background(), &LoginAttempt{Username: "admin", Password: "secret", IP: "127.0.0.1"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.User.Password != "" {
|
||||
t.Fatalf("authentication result retained password hash")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordLoginAllowsMissingAuditRecorder(t *testing.T) {
|
||||
uc := &AuthenticationUsecase{}
|
||||
uc.recordLogin(context.Background(), &LoginAttempt{Username: "admin"}, false, "failed", 0)
|
||||
|
||||
Reference in New Issue
Block a user