ci: expand shared package validation and test coverage
- Add lint, formatting, vet, and publish workflow checks - Run Go database tests with PostgreSQL and add Java tests - Make consumer sync opt-in; update docs and Go dependency
This commit is contained in:
1 parent
937f51b4fb
commit
0ff94f9b10
107 files changed
+10124
-410
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -19,7 +20,7 @@ func TestPasswordRoundTrip(t *testing.T) {
|
||||
if VerifyPassword(hash, "wrong password") {
|
||||
t.Fatal("VerifyPassword() accepted the wrong password")
|
||||
}
|
||||
if cost, err := bcrypt.Cost([]byte(hash)); err != nil || cost != BcryptCost {
|
||||
if cost, err := bcrypt.Cost([]byte(strings.TrimPrefix(hash, bcryptScheme))); err != nil || cost != BcryptCost {
|
||||
t.Fatalf("bcrypt cost = %d, error = %v; want %d", cost, err, BcryptCost)
|
||||
}
|
||||
}
|
||||
@@ -67,3 +68,29 @@ func TestResetManagerExpiresCode(t *testing.T) {
|
||||
t.Fatal("Confirm() accepted an expired reset code")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateCredentialsRefusesEmptyHashAndAtUsername(t *testing.T) {
|
||||
if err := validateCredentials("alice", ""); !errors.Is(err, ErrEmptyPasswordHash) {
|
||||
t.Fatalf("empty hash error = %v, want ErrEmptyPasswordHash", err)
|
||||
}
|
||||
if err := validateCredentials("alice@example.com", "hash"); !errors.Is(err, ErrInvalidUsername) {
|
||||
t.Fatalf("@ username error = %v, want ErrInvalidUsername", err)
|
||||
}
|
||||
if err := validateCredentials("alice", "hash"); err != nil {
|
||||
t.Fatalf("valid credentials refused: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHashPasswordUsesTheSharedBcryptCost(t *testing.T) {
|
||||
hash, err := HashPassword("correct horse battery staple")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cost, err := bcrypt.Cost([]byte(strings.TrimPrefix(hash, bcryptScheme)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cost != BcryptCost {
|
||||
t.Fatalf("bcrypt cost = %d, want %d", cost, BcryptCost)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user