aboutsummaryrefslogtreecommitdiff
path: root/server/config
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2016-04-23 18:06:49 +0100
committerNiall Sheridan <nsheridan@gmail.com>2016-04-23 18:06:49 +0100
commitc6bf0a05763f567079cb464212a17b89b75f1a50 (patch)
treef19d26002e3232f9e54fcff2a3ed48e97fc858c9 /server/config
parent19125034df9d17e0eec70fd8be76d785648232b1 (diff)
Add config file tests
Diffstat (limited to 'server/config')
-rw-r--r--server/config/config_test.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/server/config/config_test.go b/server/config/config_test.go
new file mode 100644
index 0000000..70436d5
--- /dev/null
+++ b/server/config/config_test.go
@@ -0,0 +1,60 @@
+package config
+
+import (
+ "bytes"
+ "testing"
+ "time"
+
+ "github.com/nsheridan/cashier/testdata"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestServerConfig(t *testing.T) {
+ a := assert.New(t)
+ c, err := ReadConfig(bytes.NewBuffer(testdata.ServerConfig))
+ if err != nil {
+ t.Fatal(err)
+ }
+ server := c.Server
+ a.IsType(server, Server{})
+ a.True(server.UseTLS)
+ a.Equal(server.TLSKey, "server.key")
+ a.Equal(server.TLSCert, "server.crt")
+ a.Equal(server.Port, 443)
+ a.Equal(server.CookieSecret, "supersecret")
+}
+
+func TestAuthConfig(t *testing.T) {
+ a := assert.New(t)
+ c, err := ReadConfig(bytes.NewBuffer(testdata.AuthConfig))
+ if err != nil {
+ t.Fatal(err)
+ }
+ auth := c.Auth
+ a.IsType(auth, Auth{})
+ a.Equal(auth.Provider, "google")
+ a.Equal(auth.ProviderOpts, map[string]string{"domain": "example.com"})
+ a.Equal(auth.OauthClientID, "client_id")
+ a.Equal(auth.OauthClientSecret, "secret")
+ a.Equal(auth.OauthCallbackURL, "https://sshca.example.com/auth/callback")
+ a.Equal(auth.JWTSigningKey, "supersecret")
+}
+
+func TestSSHConfig(t *testing.T) {
+ a := assert.New(t)
+ c, err := ReadConfig(bytes.NewBuffer(testdata.SSHConfig))
+ if err != nil {
+ t.Fatal(err)
+ }
+ ssh := c.SSH
+ a.IsType(ssh, SSH{})
+ a.Equal(ssh.SigningKey, "signing_key")
+ a.Equal(ssh.AdditionalPrincipals, []string{"ec2-user", "ubuntu"})
+ a.Equal(ssh.Permissions, []string{"permit-pty", "permit-X11-forwarding", "permit-port-forwarding", "permit-user-rc"})
+ a.Equal(ssh.MaxAge, "720h")
+ d, err := time.ParseDuration(ssh.MaxAge)
+ if err != nil {
+ t.Fatal(err)
+ }
+ a.Equal(d.Hours(), float64(720))
+}