2019-03-06 23:01:51 +00:00
|
|
|
package provisioner
|
2018-10-12 06:03:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/smallstep/assert"
|
|
|
|
jose "gopkg.in/square/go-jose.v2"
|
|
|
|
)
|
|
|
|
|
2018-10-19 05:26:39 +00:00
|
|
|
func TestProvisionerInit(t *testing.T) {
|
2018-10-12 06:03:00 +00:00
|
|
|
type ProvisionerValidateTest struct {
|
2019-03-07 20:15:18 +00:00
|
|
|
p *JWK
|
2018-10-12 06:03:00 +00:00
|
|
|
err error
|
|
|
|
}
|
|
|
|
tests := map[string]func(*testing.T) ProvisionerValidateTest{
|
2018-10-30 22:25:52 +00:00
|
|
|
"fail-empty-name": func(t *testing.T) ProvisionerValidateTest {
|
2018-10-12 06:03:00 +00:00
|
|
|
return ProvisionerValidateTest{
|
2019-03-07 20:15:18 +00:00
|
|
|
p: &JWK{},
|
2018-10-30 22:25:52 +00:00
|
|
|
err: errors.New("provisioner name cannot be empty"),
|
2018-10-12 06:03:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"fail-empty-type": func(t *testing.T) ProvisionerValidateTest {
|
|
|
|
return ProvisionerValidateTest{
|
2019-03-07 20:15:18 +00:00
|
|
|
p: &JWK{Name: "foo"},
|
2018-10-12 06:03:00 +00:00
|
|
|
err: errors.New("provisioner type cannot be empty"),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"fail-empty-key": func(t *testing.T) ProvisionerValidateTest {
|
|
|
|
return ProvisionerValidateTest{
|
2019-03-07 20:15:18 +00:00
|
|
|
p: &JWK{Name: "foo", Type: "bar"},
|
2018-10-12 06:03:00 +00:00
|
|
|
err: errors.New("provisioner key cannot be empty"),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"ok": func(t *testing.T) ProvisionerValidateTest {
|
|
|
|
return ProvisionerValidateTest{
|
2019-03-07 20:15:18 +00:00
|
|
|
p: &JWK{Name: "foo", Type: "bar", Key: &jose.JSONWebKey{}},
|
2018-10-12 06:03:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, get := range tests {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
tc := get(t)
|
2018-10-19 05:26:39 +00:00
|
|
|
err := tc.p.Init(&globalProvisionerClaims)
|
2018-10-12 06:03:00 +00:00
|
|
|
if err != nil {
|
|
|
|
if assert.NotNil(t, tc.err) {
|
|
|
|
assert.Equals(t, tc.err.Error(), err.Error())
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert.Nil(t, tc.err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|