2018-10-19 05:26:39 +00:00
|
|
|
package authority
|
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 {
|
|
|
|
p *Provisioner
|
|
|
|
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{
|
|
|
|
p: &Provisioner{},
|
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{
|
2018-10-30 01:00:30 +00:00
|
|
|
p: &Provisioner{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{
|
2018-10-30 01:00:30 +00:00
|
|
|
p: &Provisioner{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{
|
2018-10-30 01:00:30 +00:00
|
|
|
p: &Provisioner{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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|