MCPcopy
hub / github.com/smallstep/cli / TestNew

Function TestNew

token/provision/provision_test.go:24–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22}
23
24func TestNew(t *testing.T) {
25 type args struct {
26 subject string
27 opts []token.Options
28 }
29
30 now := time.Now()
31 want := &Token{
32 claims: token.DefaultClaims(),
33 }
34 wantWithOptions := &Token{
35 claims: token.DefaultClaims(),
36 }
37
38 want.claims.Subject = "test.domain"
39 wantWithOptions.claims.Subject = "test.domain"
40 wantWithOptions.claims.Issuer = "new-issuer"
41 wantWithOptions.claims.ExtraClaims = map[string]interface{}{"sha": "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c"}
42
43 tests := []struct {
44 name string
45 args args
46 want *Token
47 wantErr bool
48 }{
49 {"ok", args{"test.domain", nil}, want, false},
50 {"ok empty options", args{"test.domain", []token.Options{}}, want, false},
51 {"ok with options", args{"test.domain", []token.Options{token.WithIssuer("new-issuer"), token.WithClaim("sha", "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c")}}, wantWithOptions, false},
52 {"fail no subject", args{"", []token.Options{}}, nil, true},
53 {"fail bad option", args{"test.domain", []token.Options{token.WithIssuer("")}}, nil, true},
54 }
55 for _, tt := range tests {
56 t.Run(tt.name, func(t *testing.T) {
57 got, err := New(tt.args.subject, tt.args.opts...)
58 withFixedTime(got, now)
59 if (err != nil) != tt.wantErr {
60 t.Errorf("New() error = %v, wantErr %v", err, tt.wantErr)
61 return
62 }
63 assert.Equal(t, got, tt.want)
64 if !reflect.DeepEqual(got, tt.want) {
65 t.Errorf("New() = %v, want %v", got, tt.want)
66 }
67 })
68 }
69}
70
71func TestToken_SignedString(t *testing.T) {
72 type fields struct {

Callers

nothing calls this directly

Calls 6

DefaultClaimsFunction · 0.92
WithIssuerFunction · 0.92
WithClaimFunction · 0.92
NewFunction · 0.85
withFixedTimeFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…