Skip to content

Commit 7c11861

Browse files
author
Matthew Fisher
committed
feat(tests): add cert integration tests
1 parent f376230 commit 7c11861

4 files changed

Lines changed: 130 additions & 79 deletions

File tree

docs/reference/domain-ssl.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ Add your certificate, any intermediate certificates, and private key to the endp
6464
Adding SSL endpoint... done
6565
www.example.com
6666
67+
.. note::
68+
69+
It may take up to one minute for the certificate to be available on the routers.
70+
6771

6872
Attach a Certificate Chain
6973
^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/domain_test.go

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/domains_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// +build integration
2+
3+
package tests
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
"time"
9+
10+
"github.com/deis/deis/tests/utils"
11+
)
12+
13+
var (
14+
certsAddCmd = "certs:add {{.SSLCertificatePath}} {{.SSLKeyPath}}"
15+
certsRemoveCmd = "certs:remove {{.AppDomain}}"
16+
domainsAddCmd = "domains:add {{.AppDomain}} --app {{.AppName}}"
17+
domainsRemoveCmd = "domains:remove {{.AppDomain}} --app {{.AppName}}"
18+
)
19+
20+
func TestDomains(t *testing.T) {
21+
cfg := domainsSetup(t)
22+
domainsTest(t, cfg)
23+
certsTest(t, cfg)
24+
utils.AppsDestroyTest(t, cfg)
25+
}
26+
27+
func domainsSetup(t *testing.T) *utils.DeisTestConfig {
28+
cfg := utils.GetGlobalConfig()
29+
cfg.AppName = "domainsample"
30+
utils.Execute(t, authLoginCmd, cfg, false, "")
31+
utils.Execute(t, gitCloneCmd, cfg, false, "")
32+
if err := utils.Chdir(cfg.ExampleApp); err != nil {
33+
t.Fatal(err)
34+
}
35+
utils.Execute(t, appsCreateCmd, cfg, false, "")
36+
utils.Execute(t, gitPushCmd, cfg, false, "")
37+
utils.CurlApp(t, *cfg)
38+
if err := utils.Chdir(".."); err != nil {
39+
t.Fatal(err)
40+
}
41+
return cfg
42+
}
43+
44+
func domainsTest(t *testing.T, cfg *utils.DeisTestConfig) {
45+
utils.Execute(t, domainsAddCmd, cfg, false, "done")
46+
// ensure both the root domain and the custom domain work
47+
utils.CurlApp(t, *cfg)
48+
utils.Curl(t, fmt.Sprintf("http://%s", cfg.AppDomain))
49+
utils.Execute(t, domainsRemoveCmd, cfg, false, "done")
50+
// only the root domain should work now
51+
utils.CurlApp(t, *cfg)
52+
// TODO (bacongobbler): add test to ensure that the custom domain fails to connect
53+
}
54+
55+
func certsTest(t *testing.T, cfg *utils.DeisTestConfig) {
56+
utils.Execute(t, domainsAddCmd, cfg, false, "done")
57+
utils.Execute(t, certsAddCmd, cfg, false, cfg.AppDomain)
58+
// wait for the certs to be populated in the router; cron takes up to 1 minute
59+
fmt.Println("sleeping for 60 seconds until certs are generated...")
60+
time.Sleep(60 * time.Second)
61+
fmt.Println("ok")
62+
// ensure the custom domain's SSL endpoint works
63+
utils.Curl(t, fmt.Sprintf("https://%s", cfg.AppDomain))
64+
utils.Execute(t, certsRemoveCmd, cfg, false, "done")
65+
// only the root domain should work now
66+
utils.CurlApp(t, *cfg)
67+
// TODO (bacongobbler): add test to ensure that the custom domain fails to connect
68+
}

tests/utils/itutils.go

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import (
44
"bytes"
55
"fmt"
66
"io/ioutil"
7+
"log"
78
"math/rand"
89
"net/http"
910
"os"
1011
"os/exec"
12+
"path/filepath"
1113
"strings"
1214
"testing"
1315
"text/template"
@@ -22,21 +24,23 @@ var Deis = "deis "
2224
// DeisTestConfig allows tests to be repeated against different
2325
// targets, with different example apps, using specific credentials, and so on.
2426
type DeisTestConfig struct {
25-
AuthKey string
26-
Hosts string
27-
Domain string
28-
SSHKey string
29-
ClusterName string
30-
UserName string
31-
Password string
32-
Email string
33-
ExampleApp string
34-
AppDomain string
35-
AppName string
36-
ProcessNum string
37-
ImageID string
38-
Version string
39-
AppUser string
27+
AuthKey string
28+
Hosts string
29+
Domain string
30+
SSHKey string
31+
ClusterName string
32+
UserName string
33+
Password string
34+
Email string
35+
ExampleApp string
36+
AppDomain string
37+
AppName string
38+
ProcessNum string
39+
ImageID string
40+
Version string
41+
AppUser string
42+
SSLCertificatePath string
43+
SSLKeyPath string
4044
}
4145

4246
// randomApp is used for the test run if DEIS_TEST_APP isn't set
@@ -68,22 +72,46 @@ func GetGlobalConfig() *DeisTestConfig {
6872
if appDomain == "" {
6973
appDomain = fmt.Sprintf("test.%s", domain)
7074
}
75+
76+
// generate a self-signed certifcate for the app domain
77+
keyOut, err := filepath.Abs(appDomain + ".key")
78+
if err != nil {
79+
log.Fatal(err)
80+
}
81+
certOut, err := filepath.Abs(appDomain + ".cert")
82+
if err != nil {
83+
log.Fatal(err)
84+
}
85+
cmd := exec.Command("openssl", "req", "-new", "-newkey", "rsa:4096", "-nodes", "-x509",
86+
"-days", "1",
87+
"-subj", fmt.Sprintf("/C=US/ST=Colorado/L=Boulder/CN=%s", appDomain),
88+
"-keyout", keyOut,
89+
"-out", certOut)
90+
if err := cmd.Start(); err != nil {
91+
log.Fatal(err)
92+
}
93+
if err := cmd.Wait(); err != nil {
94+
log.Fatal(err)
95+
}
96+
7197
var envCfg = DeisTestConfig{
72-
AuthKey: authKey,
73-
Hosts: hosts,
74-
Domain: domain,
75-
SSHKey: sshKey,
76-
ClusterName: "dev",
77-
UserName: "test",
78-
Password: "asdf1234",
79-
Email: "test@test.co.nz",
80-
ExampleApp: exampleApp,
81-
AppDomain: appDomain,
82-
AppName: "sample",
83-
ProcessNum: "2",
84-
ImageID: "buildtest",
85-
Version: "2",
86-
AppUser: "test1",
98+
AuthKey: authKey,
99+
Hosts: hosts,
100+
Domain: domain,
101+
SSHKey: sshKey,
102+
ClusterName: "dev",
103+
UserName: "test",
104+
Password: "asdf1234",
105+
Email: "test@test.co.nz",
106+
ExampleApp: exampleApp,
107+
AppDomain: appDomain,
108+
AppName: "sample",
109+
ProcessNum: "2",
110+
ImageID: "buildtest",
111+
Version: "2",
112+
AppUser: "test1",
113+
SSLCertificatePath: certOut,
114+
SSLKeyPath: keyOut,
87115
}
88116
return &envCfg
89117
}

0 commit comments

Comments
 (0)