2020-07-14 15:50:14 +00:00
|
|
|
/*
|
|
|
|
Copyright 2020 VMware, Inc.
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
"github.com/suzerain-io/pinniped/pkg/config/api"
|
2020-07-14 15:50:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFromPath(t *testing.T) {
|
2020-08-03 14:17:11 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
path string
|
|
|
|
wantConfig *api.Config
|
2020-08-20 19:17:18 +00:00
|
|
|
wantError string
|
2020-08-03 14:17:11 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Happy",
|
|
|
|
path: "testdata/happy.yaml",
|
|
|
|
wantConfig: &api.Config{
|
2020-08-20 17:54:15 +00:00
|
|
|
DiscoveryInfo: api.DiscoveryInfoSpec{
|
2020-08-03 14:17:11 +00:00
|
|
|
URL: stringPtr("https://some.discovery/url"),
|
|
|
|
},
|
|
|
|
WebhookConfig: api.WebhookConfigSpec{
|
|
|
|
URL: "https://tuna.com/fish?marlin",
|
|
|
|
CABundle: []byte("-----BEGIN CERTIFICATE-----..."),
|
|
|
|
},
|
2020-08-20 19:17:18 +00:00
|
|
|
APIConfig: api.APIConfigSpec{
|
|
|
|
ServingCertificateConfig: api.ServingCertificateConfigSpec{
|
|
|
|
DurationSeconds: int64Ptr(3600),
|
|
|
|
RenewBeforeSeconds: int64Ptr(2400),
|
|
|
|
},
|
|
|
|
},
|
2020-08-03 14:17:11 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-08-20 19:17:18 +00:00
|
|
|
name: "Default",
|
|
|
|
path: "testdata/default.yaml",
|
2020-08-03 14:17:11 +00:00
|
|
|
wantConfig: &api.Config{
|
2020-08-20 17:54:15 +00:00
|
|
|
DiscoveryInfo: api.DiscoveryInfoSpec{
|
2020-08-03 14:17:11 +00:00
|
|
|
URL: nil,
|
|
|
|
},
|
|
|
|
WebhookConfig: api.WebhookConfigSpec{
|
|
|
|
URL: "https://tuna.com/fish?marlin",
|
|
|
|
CABundle: []byte("-----BEGIN CERTIFICATE-----..."),
|
|
|
|
},
|
2020-08-20 19:17:18 +00:00
|
|
|
APIConfig: api.APIConfigSpec{
|
|
|
|
ServingCertificateConfig: api.ServingCertificateConfigSpec{
|
|
|
|
DurationSeconds: int64Ptr(60 * 60 * 24 * 365), // about a year
|
|
|
|
RenewBeforeSeconds: int64Ptr(60 * 60 * 24 * 30 * 9), // about 9 months
|
|
|
|
},
|
|
|
|
},
|
2020-08-03 14:17:11 +00:00
|
|
|
},
|
2020-07-14 15:50:14 +00:00
|
|
|
},
|
2020-08-20 19:17:18 +00:00
|
|
|
{
|
|
|
|
name: "InvalidDurationRenewBefore",
|
|
|
|
path: "testdata/invalid-duration-renew-before.yaml",
|
|
|
|
wantError: "validate api: durationSeconds cannot be smaller than renewBeforeSeconds",
|
|
|
|
},
|
2020-08-03 14:17:11 +00:00
|
|
|
}
|
|
|
|
for _, test := range tests {
|
|
|
|
test := test
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
config, err := FromPath(test.path)
|
2020-08-20 19:17:18 +00:00
|
|
|
if test.wantError != "" {
|
|
|
|
require.EqualError(t, err, test.wantError)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, test.wantConfig, config)
|
|
|
|
}
|
2020-08-03 14:17:11 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func stringPtr(s string) *string {
|
2020-08-20 19:17:18 +00:00
|
|
|
return &s
|
2020-07-14 15:50:14 +00:00
|
|
|
}
|