feat: deliver authenticated task APIs, SDK and P1 regression
This commit is contained in:
29
platform/auth/token_test.go
Normal file
29
platform/auth/token_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
core "git.yuntuo.hk/k2safe/orbit/model"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTokenAndScope(t *testing.T) {
|
||||
ns := core.ID(strings.Repeat("1", 32))
|
||||
id := core.ID(strings.Repeat("2", 32))
|
||||
secret, digest, err := Issue(ns, id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
token, err := Parse(secret)
|
||||
if err != nil || token.NamespaceID != ns || token.CredentialID != id || token.Digest != digest {
|
||||
t.Fatalf("token round trip: %v", err)
|
||||
}
|
||||
for _, bad := range []string{secret + "=", secret + "\n", "orb1.bad.id.secret", strings.Replace(secret, "orb1.", "orb2.", 1)} {
|
||||
if _, err := Parse(bad); err == nil {
|
||||
t.Fatal("accepted malformed token")
|
||||
}
|
||||
}
|
||||
p := Permissions{Actions: []string{"tasks:read"}, Queues: []string{string(id)}}
|
||||
if p.Validate() != nil || !p.Allows("tasks:read") || p.Allows("tasks:submit") || !p.AllowsQueue(id) || p.AllowsQueue(ns) {
|
||||
t.Fatal("scope mismatch")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user