|
|
|
@ -13,82 +13,6 @@ import (
|
|
|
|
|
"gopkg.in/square/go-jose.v2/jwt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestMatchesAudience(t *testing.T) {
|
|
|
|
|
type matchesTest struct {
|
|
|
|
|
a, b []string
|
|
|
|
|
exp bool
|
|
|
|
|
}
|
|
|
|
|
tests := map[string]matchesTest{
|
|
|
|
|
"false arg1 empty": {
|
|
|
|
|
a: []string{},
|
|
|
|
|
b: []string{"https://127.0.0.1:0/sign", "https://test.ca.smallstep.com/sign"},
|
|
|
|
|
exp: false,
|
|
|
|
|
},
|
|
|
|
|
"false arg2 empty": {
|
|
|
|
|
a: []string{"https://127.0.0.1:0/sign", "https://test.ca.smallstep.com/sign"},
|
|
|
|
|
b: []string{},
|
|
|
|
|
exp: false,
|
|
|
|
|
},
|
|
|
|
|
"false arg1,arg2 empty": {
|
|
|
|
|
a: []string{"https://127.0.0.1:0/sign", "https://test.ca.smallstep.com/sign"},
|
|
|
|
|
b: []string{"step-gateway", "step-cli"},
|
|
|
|
|
exp: false,
|
|
|
|
|
},
|
|
|
|
|
"false": {
|
|
|
|
|
a: []string{"step-gateway", "step-cli"},
|
|
|
|
|
b: []string{"https://127.0.0.1:0/sign", "https://test.ca.smallstep.com/sign"},
|
|
|
|
|
exp: false,
|
|
|
|
|
},
|
|
|
|
|
"true": {
|
|
|
|
|
a: []string{"step-gateway", "https://test.ca.smallstep.com/sign"},
|
|
|
|
|
b: []string{"https://127.0.0.1:0/sign", "https://test.ca.smallstep.com/sign"},
|
|
|
|
|
exp: true,
|
|
|
|
|
},
|
|
|
|
|
"true,portsA": {
|
|
|
|
|
a: []string{"step-gateway", "https://test.ca.smallstep.com:9000/sign"},
|
|
|
|
|
b: []string{"https://127.0.0.1:0/sign", "https://test.ca.smallstep.com/sign"},
|
|
|
|
|
exp: true,
|
|
|
|
|
},
|
|
|
|
|
"true,portsB": {
|
|
|
|
|
a: []string{"step-gateway", "https://test.ca.smallstep.com/sign"},
|
|
|
|
|
b: []string{"https://127.0.0.1:0/sign", "https://test.ca.smallstep.com:9000/sign"},
|
|
|
|
|
exp: true,
|
|
|
|
|
},
|
|
|
|
|
"true,portsAB": {
|
|
|
|
|
a: []string{"step-gateway", "https://test.ca.smallstep.com:9000/sign"},
|
|
|
|
|
b: []string{"https://127.0.0.1:0/sign", "https://test.ca.smallstep.com:8000/sign"},
|
|
|
|
|
exp: true,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for name, tc := range tests {
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
assert.Equals(t, tc.exp, matchesAudience(tc.a, tc.b))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestStripPort(t *testing.T) {
|
|
|
|
|
type args struct {
|
|
|
|
|
rawurl string
|
|
|
|
|
}
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
args args
|
|
|
|
|
want string
|
|
|
|
|
}{
|
|
|
|
|
{"with port", args{"https://ca.smallstep.com:9000/sign"}, "https://ca.smallstep.com/sign"},
|
|
|
|
|
{"with no port", args{"https://ca.smallstep.com/sign/"}, "https://ca.smallstep.com/sign/"},
|
|
|
|
|
{"bad url", args{"https://a bad url:9000"}, "https://a bad url:9000"},
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
if got := stripPort(tt.args.rawurl); got != tt.want {
|
|
|
|
|
t.Errorf("stripPort() = %v, want %v", got, tt.want)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAuthorize(t *testing.T) {
|
|
|
|
|
a := testAuthority(t)
|
|
|
|
|
jwk, err := stepJOSE.ParseKey("testdata/secrets/step_cli_key_priv.jwk",
|
|
|
|
|