Repository navigation
Expand file tree
/
Copy pathidentity_errors_test.go
More file actions
64 lines (61 loc) · 1.81 KB
/
Copy pathidentity_errors_test.go
File metadata and controls
64 lines (61 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package edge
import (
"encoding/json/jsontext"
"errors"
"strings"
"testing"
"github.com/asteroid-computing/go-lambda-edge/identity"
)
func TestClaimsInvocationErrors(t *testing.T) {
_, malformed := identity.ParseClaims(jsontext.Value(`{"secret":`))
_, exceeded := identity.NewClaims(map[string]any{"secret": "value"}, identity.WithClaimsBudget(64))
deep := map[string]any{}
for range 64 {
deep = map[string]any{"secret": deep}
}
_, depth := identity.NewClaims(deep)
for _, tc := range []struct {
name string
cause error
limit bool
}{
{name: "malformed", cause: malformed},
{name: "bytes", cause: exceeded, limit: true},
{name: "depth", cause: depth},
{name: "unexpected", cause: errors.New("secret")},
} {
t.Run(tc.name, func(t *testing.T) {
if tc.cause == nil {
t.Fatal("fixture unexpectedly accepted")
}
err := claimsError(tc.cause)
if !errors.Is(err, ErrIdentity) || errors.Is(err, ErrLimitExceeded) != tc.limit || err.Operation() != "identity" {
t.Errorf("claimsError(%s) category or operation incorrect: %v", tc.name, err)
}
name, maximum, ok := err.Limit()
if ok != tc.limit || tc.limit && (name != "identity_claims" || maximum != 64) {
t.Errorf("claimsError(%s).Limit() = %q, %d, %t", tc.name, name, maximum, ok)
}
if tc.name == "depth" && !errors.Is(err, identity.ErrInvalidClaims) {
t.Error("depth failure lost its structural classification")
}
var visit func(error)
visit = func(cause error) {
if cause == nil {
return
}
if strings.Contains(cause.Error(), "secret") {
t.Errorf("error tree exposed input: %v", cause)
}
if joined, ok := cause.(interface{ Unwrap() []error }); ok {
for _, child := range joined.Unwrap() {
visit(child)
}
return
}
visit(errors.Unwrap(cause))
}
visit(err)
})
}
}