2017-05-09 00:43:48 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-06-22 19:50:45 +00:00
|
|
|
"github.com/kolide/fleet/server/kolide"
|
2017-05-09 00:43:48 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSSONotPresent(t *testing.T) {
|
|
|
|
invalid := &invalidArgumentError{}
|
|
|
|
var p kolide.AppConfigPayload
|
2017-05-17 15:58:40 +00:00
|
|
|
validateSSOSettings(p, &kolide.AppConfig{}, invalid)
|
2017-05-09 00:43:48 +00:00
|
|
|
assert.False(t, invalid.HasErrors())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNeedFieldsPresent(t *testing.T) {
|
|
|
|
invalid := &invalidArgumentError{}
|
|
|
|
config := kolide.AppConfig{
|
|
|
|
EnableSSO: true,
|
|
|
|
EntityID: "kolide",
|
|
|
|
IssuerURI: "http://issuer.idp.com",
|
|
|
|
MetadataURL: "http://isser.metadata.com",
|
|
|
|
IDPName: "onelogin",
|
|
|
|
}
|
|
|
|
p := appConfigPayloadFromAppConfig(&config)
|
2017-05-17 15:58:40 +00:00
|
|
|
validateSSOSettings(*p, &kolide.AppConfig{}, invalid)
|
2017-05-09 00:43:48 +00:00
|
|
|
assert.False(t, invalid.HasErrors())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMissingMetadata(t *testing.T) {
|
|
|
|
invalid := invalidArgumentError{}
|
|
|
|
config := kolide.AppConfig{
|
|
|
|
EnableSSO: true,
|
|
|
|
EntityID: "kolide",
|
|
|
|
IssuerURI: "http://issuer.idp.com",
|
|
|
|
IDPName: "onelogin",
|
|
|
|
}
|
|
|
|
p := appConfigPayloadFromAppConfig(&config)
|
2017-05-17 15:58:40 +00:00
|
|
|
validateSSOSettings(*p, &kolide.AppConfig{}, &invalid)
|
2017-05-09 00:43:48 +00:00
|
|
|
require.True(t, invalid.HasErrors())
|
|
|
|
require.Len(t, invalid, 1)
|
|
|
|
assert.Equal(t, "metadata", invalid[0].name)
|
|
|
|
assert.Equal(t, "either metadata or metadata_url must be defined", invalid[0].reason)
|
|
|
|
}
|