mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-21 10:40:13 +00:00
fix(auth): accept hyphenated agent metadata (#1197)
This commit is contained in:
@@ -25,6 +25,14 @@ func authCheckWithSecret(secret, uuid string) (uint64, error) {
|
||||
return (&authHandler{}).Check(ctx)
|
||||
}
|
||||
|
||||
func authCheckWithHyphenatedSecret(secret, uuid string) (uint64, error) {
|
||||
ctx := metadata.NewIncomingContext(context.Background(), metadata.Pairs(
|
||||
"client-secret", secret,
|
||||
"client-uuid", uuid,
|
||||
))
|
||||
return (&authHandler{}).Check(ctx)
|
||||
}
|
||||
|
||||
// authHandshakeUUID is RFC4122-shaped so it survives the uuid.ParseUUID gate
|
||||
// at the top of check(); setupAuthAgentFixture's "uuid-alice" / "uuid-bob"
|
||||
// only work for callers that bypass check() and exercise the inner helpers.
|
||||
@@ -88,6 +96,18 @@ func setupAuthHandshakeFixture(t *testing.T) func() {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthCheckAcceptsHyphenatedMetadata(t *testing.T) {
|
||||
defer setupAuthHandshakeFixture(t)()
|
||||
|
||||
cid, err := authCheckWithHyphenatedSecret("alice-global", authHandshakeUUID)
|
||||
if err != nil {
|
||||
t.Fatalf("hyphenated metadata must authenticate: %v", err)
|
||||
}
|
||||
if cid != 11 {
|
||||
t.Fatalf("expected server ID 11, got %d", cid)
|
||||
}
|
||||
}
|
||||
|
||||
// setupAuthAgentFixture seeds an in-memory DB and ServerShared with two
|
||||
// servers belonging to different users so we can assert that a secret bound
|
||||
// to user A cannot resolve a server UUID owned by user B.
|
||||
|
||||
Reference in New Issue
Block a user