docs: record auth hash alignment and validation results
This commit is contained in:
1 parent
22887fef03
commit
f7819904b9
51 files changed
+1792
-542
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package coreconfig
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// contractFile holds the fixtures the Go, Node and Python internal-secret checks must agree on. The
|
||||
// Node and Python suites load the same file; see the "description" field in it.
|
||||
const contractFile = "../../contract/auth-contract.json"
|
||||
|
||||
type internalSecretContract struct {
|
||||
InternalSecret struct {
|
||||
MinLength int `json:"minLength"`
|
||||
Placeholders []string `json:"placeholders"`
|
||||
Cases []struct {
|
||||
Name string `json:"name"`
|
||||
Secret string `json:"secret"`
|
||||
Provided string `json:"provided"`
|
||||
Matches bool `json:"matches"`
|
||||
} `json:"cases"`
|
||||
} `json:"internalSecret"`
|
||||
}
|
||||
|
||||
func TestContractInternalSecret(t *testing.T) {
|
||||
data, err := os.ReadFile(contractFile)
|
||||
if os.IsNotExist(err) {
|
||||
t.Skipf("%s is not part of this checkout", contractFile)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var contract internalSecretContract
|
||||
if err := json.Unmarshal(data, &contract); err != nil {
|
||||
t.Fatalf("decode %s: %v", contractFile, err)
|
||||
}
|
||||
rule := contract.InternalSecret
|
||||
if MinInternalSecretLength != rule.MinLength {
|
||||
t.Fatalf("MinInternalSecretLength = %d, contract says %d", MinInternalSecretLength, rule.MinLength)
|
||||
}
|
||||
for _, placeholder := range rule.Placeholders {
|
||||
if InternalSecretUsable(placeholder) {
|
||||
t.Errorf("placeholder %q is usable, contract says it never gates a route", placeholder)
|
||||
}
|
||||
}
|
||||
for _, entry := range rule.Cases {
|
||||
if got := InternalSecretMatches(entry.Provided, entry.Secret); got != entry.Matches {
|
||||
t.Errorf("%s: InternalSecretMatches = %v, contract says %v", entry.Name, got, entry.Matches)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user