Artifact 5407551f497a53dcf08bcf1db207f9e0a91fb0d09f1436c0e356f8fdace7ca66:
- File
internal/auth/verify_test.go
— part of check-in
[6273a0750d]
at
2026-07-22 23:03:24
on branch trunk
— fix: correct go.mod module path to go-libfossil (#76) (#117)
* fix: correct go.mod module path to go-libfossil (#76)
The module directive still declared github.com/danmestas/libfossil after the repository was renamed to go-libfossil. pkg.go.dev/godoc scraping matches the declared module path against its hosting path, so the stale path broke SDK doc generation.
Rename the module path across all four in-repo modules (root, the two db/driver submodules, observer/otel, and docs/site) and every internal import, plus the release workflow, the doc-generation script, and the docs.
No tag has been published under the go-libfossil path yet, so the cross-module requires cannot resolve from the proxy. Add replace directives pointing the in-repo requires at their local directories so GOWORK=off builds and the CI matrix resolve without a published version. These replaces are ignored by downstream consumers and can be dropped once new-path tags are cut.
* Guard releases against replace directives; regenerate SDK docs
The go-libfossil rename bridges the in-repo modules with `replace` directives. Go refuses a main module that carries them, so a tag cut while they are present breaks `go install .../cmd/libfossil@<tag>` and every `@version` fetch of the driver submodules. Add a Release workflow step that fails the job before anything is published if any tracked go.mod still contains a replace directive, so the bridge is a CI-enforced TODO rather than a silent landmine. The step comment records what unblocks a release: re-tag the submodules with the corrected module paths, bump the root requires, then drop the replace blocks.
Regenerate the SDK reference docs. The previous pass only substituted URLs over the pre-existing generated files, leaving stale signatures (Repo.Timeline was still documented as taking LogOpts rather than TimelineOpts). Note that gomarkdoc must be run outside a git worktree — inside one it silently strips every source link.
Also reword the README rename note, which read as though the import path had not changed, and re-sort the ncruces require block. (user: [email protected], size: 4317) [annotate] [blame] [check-ins using]
package auth import ( "crypto/sha1" "encoding/hex" "testing" "github.com/danmestas/go-libfossil/internal/xfer" ) // buildLoginCard constructs a LoginCard matching Fossil's protocol. // payload is the raw xfer message bytes that the nonce is derived from. func buildLoginCard(user, password, projectCode string, payload []byte) *xfer.LoginCard { nonce := sha1Hex(payload) sharedSecret := sha1Hex([]byte(projectCode + "/" + user + "/" + password)) signature := sha1Hex([]byte(nonce + sharedSecret)) return &xfer.LoginCard{User: user, Nonce: nonce, Signature: signature} } func sha1Hex(data []byte) string { h := sha1.Sum(data) return hex.EncodeToString(h[:]) } func TestVerifyLoginSuccess(t *testing.T) { d := setupTestDB(t) code := projectCode(t, d) // Create user with known password err := CreateUser(d, code, "alice", "secret123", "ios") if err != nil { t.Fatalf("CreateUser: %v", err) } // Build valid login card payload := []byte("push\nigot abc123\n") card := buildLoginCard("alice", "secret123", code, payload) // Verify should succeed user, err := VerifyLogin(d, code, card) if err != nil { t.Fatalf("VerifyLogin: expected success, got %v", err) } if user.Login != "alice" { t.Errorf("user.Login = %q, want alice", user.Login) } if user.Cap != "ios" { t.Errorf("user.Cap = %q, want ios", user.Cap) } } func TestVerifyLoginWrongPassword(t *testing.T) { d := setupTestDB(t) code := projectCode(t, d) // Create user with known password err := CreateUser(d, code, "alice", "secret123", "o") if err != nil { t.Fatalf("CreateUser: %v", err) } // Build login card with wrong password payload := []byte("push\nigot abc123\n") card := buildLoginCard("alice", "wrongpassword", code, payload) // Verify should fail _, err = VerifyLogin(d, code, card) if err != ErrAuthFailed { t.Errorf("VerifyLogin wrong password: got %v, want ErrAuthFailed", err) } } func TestVerifyLoginUnknownUser(t *testing.T) { d := setupTestDB(t) code := projectCode(t, d) // Build login card for nonexistent user payload := []byte("push\nigot abc123\n") card := buildLoginCard("doesnotexist", "anypassword", code, payload) // Verify should fail _, err := VerifyLogin(d, code, card) if err != ErrAuthFailed { t.Errorf("VerifyLogin unknown user: got %v, want ErrAuthFailed", err) } } func TestVerifyLoginExpired(t *testing.T) { d := setupTestDB(t) code := projectCode(t, d) // Create user err := CreateUser(d, code, "alice", "secret123", "o") if err != nil { t.Fatalf("CreateUser: %v", err) } // Set cexpire to past (2020-01-01) _, err = d.Exec("UPDATE user SET cexpire='2020-01-01 00:00:00' WHERE login='alice'") if err != nil { t.Fatalf("set cexpire: %v", err) } // Build valid login card payload := []byte("push\nigot abc123\n") card := buildLoginCard("alice", "secret123", code, payload) // Verify should fail due to expiration _, err = VerifyLogin(d, code, card) if err != ErrAuthFailed { t.Errorf("VerifyLogin expired: got %v, want ErrAuthFailed", err) } } func TestVerifyLoginNonExpired(t *testing.T) { d := setupTestDB(t) code := projectCode(t, d) // Create user err := CreateUser(d, code, "alice", "secret123", "ios") if err != nil { t.Fatalf("CreateUser: %v", err) } // Set cexpire to future (2030-01-01) _, err = d.Exec("UPDATE user SET cexpire='2030-01-01 00:00:00' WHERE login='alice'") if err != nil { t.Fatalf("set cexpire: %v", err) } // Build valid login card payload := []byte("push\nigot abc123\n") card := buildLoginCard("alice", "secret123", code, payload) // Verify should succeed user, err := VerifyLogin(d, code, card) if err != nil { t.Fatalf("VerifyLogin non-expired: expected success, got %v", err) } if user.Login != "alice" { t.Errorf("user.Login = %q, want alice", user.Login) } } func TestVerifyLoginNilDB(t *testing.T) { defer func() { if r := recover(); r == nil { t.Error("VerifyLogin with nil DB should panic") } }() card := &xfer.LoginCard{User: "alice", Nonce: "abc", Signature: "def"} VerifyLogin(nil, "test-code", card) } func TestVerifyLoginNilCard(t *testing.T) { d := setupTestDB(t) code := projectCode(t, d) defer func() { if r := recover(); r == nil { t.Error("VerifyLogin with nil card should panic") } }() VerifyLogin(d, code, nil) }