Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
Fix up, additional tests, add deprecation warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
aeijdenberg committed Oct 4, 2017
1 parent 71af89a commit fee76cb
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 107 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ key. These are public and can be set in your manifest file. Note that your
Browser license key is different than your New Relic License Key (which should
be treated as confidential).

```bash
```yaml
# manifest.yml
env:
NEW_RELIC_ID: 12345
Expand All @@ -125,7 +125,7 @@ env:
If you have a GA site configured, specify your tracking ID as `GA_TRACKING_ID`
in your environment.

```bash
```yaml
# manifest.yml
env:
GA_TRACKING_ID: UA-123456-11
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ services:
"credentials": {
"CONSOLE_CLIENT_ID": "dashboard-local",
"CONSOLE_CLIENT_SECRET": "notarealsecret",
"CSRF_KEY": "notarealcsrfkey",
"SESSION_AUTHENTICATION_KEY": "notarealsessionauthenticationkey",
"CSRF_KEY": "00112233445566778899aabbccddeeff",
"SESSION_AUTHENTICATION_KEY": "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
"SMTP_FROM": "[email protected]",
"SMTP_HOST": "smtp.fake.com",
"SMTP_PASS": "",
Expand Down
6 changes: 6 additions & 0 deletions helpers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ func (s *Settings) InitSettings(envVars *EnvVars, env *cfenv.App) (retErr error)
// Fall back to legacy key variable and format - consider printing deprecation warning
if len(s.CSRFKey) == 0 {
s.CSRFKey = []byte(envVars.String(LegacySessionKeyEnvVar, ""))
if len(s.CSRFKey) != 0 {
log.Println("Warning: Use of deprecated SESSION_KEY. Please switch to CSRF_KEY (note new value is hex-encoded, see docs).")
}
}

// Return error if not found
Expand All @@ -169,6 +172,9 @@ func (s *Settings) InitSettings(envVars *EnvVars, env *cfenv.App) (retErr error)
// Fall back to legacy key variable and format
if len(sessionAuthenticationKey) == 0 {
sessionAuthenticationKey = []byte(envVars.String(LegacySessionKeyEnvVar, ""))
if len(sessionAuthenticationKey) != 0 {
log.Println("Warning: Use of deprecated SESSION_KEY. Please switch to SESSION_AUTHENTICATION_KEY (note new value is hex-encoded, see docs).")
}
}

// Return error if not found
Expand Down
208 changes: 119 additions & 89 deletions helpers/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ type initSettingsTest struct {
var initSettingsTests = []initSettingsTest{
{
testName: "Basic Valid Production CF Settings",
envVars: map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
helpers.SMTPFromEnvVar: "[email protected]",
helpers.SMTPHostEnvVar: "localhost",
helpers.SecureCookiesEnvVar: "1",
helpers.TICSecretEnvVar: "tic",
},
returnValueNull: true,
},
{
testName: "Basic Valid Legacy Session Key CF Settings",
envVars: map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
Expand All @@ -37,129 +56,138 @@ var initSettingsTests = []initSettingsTest{
{
testName: "Basic Valid Local CF Settings",
envVars: map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.LegacySessionKeyEnvVar: "lalala",
helpers.SMTPFromEnvVar: "[email protected]",
helpers.SMTPHostEnvVar: "localhost",
helpers.SecureCookiesEnvVar: "0",
helpers.LocalCFEnvVar: "1",
helpers.TICSecretEnvVar: "tic",
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
helpers.SMTPFromEnvVar: "[email protected]",
helpers.SMTPHostEnvVar: "localhost",
helpers.SecureCookiesEnvVar: "0",
helpers.LocalCFEnvVar: "1",
helpers.TICSecretEnvVar: "tic",
},
returnValueNull: true,
},
{
testName: "Basic Invalid Prod CF Settings",
envVars: map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.LegacySessionKeyEnvVar: "lalala",
helpers.SMTPFromEnvVar: "[email protected]",
helpers.SMTPHostEnvVar: "localhost",
helpers.LocalCFEnvVar: "0",
helpers.TICSecretEnvVar: "tic",
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
helpers.SMTPFromEnvVar: "[email protected]",
helpers.SMTPHostEnvVar: "localhost",
helpers.LocalCFEnvVar: "0",
helpers.TICSecretEnvVar: "tic",
// Let SecureCookies Default to false (similar to what would happen in real life).
},
returnValueNull: false,
},
{
testName: "Missing Client ID check",
envVars: map[string]string{
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.LegacySessionKeyEnvVar: "lalala",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
},
returnValueNull: false,
},
{
testName: "Missing Client Secret check",
envVars: map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.LegacySessionKeyEnvVar: "lalala",
helpers.ClientIDEnvVar: "ID",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
},
returnValueNull: false,
},
{
testName: "Missing Hostname check",
envVars: map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.LegacySessionKeyEnvVar: "lalala",
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
},
returnValueNull: false,
},
{
testName: "Missing Auth URL check",
envVars: map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.LegacySessionKeyEnvVar: "lalala",
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
},
returnValueNull: false,
},
{
testName: "Missing Token URL check",
envVars: map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.LegacySessionKeyEnvVar: "lalala",
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LogURLEnvVar: "logurl",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
},
returnValueNull: false,
},
{
testName: "Missing API URL check",
envVars: map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.LogURLEnvVar: "logurl",
helpers.LegacySessionKeyEnvVar: "lalala",
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.LogURLEnvVar: "logurl",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
},
returnValueNull: false,
},
{
testName: "Missing Log URL check",
envVars: map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LegacySessionKeyEnvVar: "lalala",
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
},
returnValueNull: false,
},
Expand All @@ -178,27 +206,29 @@ var initSettingsTests = []initSettingsTest{
{
testName: "Missing SMTP From",
envVars: map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LegacySessionKeyEnvVar: "blah",
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
},
returnValueNull: false,
},
{
testName: "Missing SMTP Host",
envVars: map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.LegacySessionKeyEnvVar: "blah",
helpers.SMTPFromEnvVar: "[email protected]",
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "hostname",
helpers.LoginURLEnvVar: "loginurl",
helpers.UAAURLEnvVar: "uaaurl",
helpers.APIURLEnvVar: "apiurl",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
helpers.SMTPFromEnvVar: "[email protected]",
},
returnValueNull: false,
},
Expand Down
29 changes: 15 additions & 14 deletions helpers/testhelpers/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,21 @@ type BasicProxyTest struct {
// GetMockCompleteEnvVars is just a commonly used env vars object that contains non-empty values for all the fields of the EnvVars struct.
func GetMockCompleteEnvVars() map[string]string {
return map[string]string{
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "https://hostname",
helpers.LoginURLEnvVar: "https://loginurl",
helpers.UAAURLEnvVar: "https://uaaurl",
helpers.APIURLEnvVar: "https://apiurl",
helpers.LogURLEnvVar: "https://logurl",
helpers.PProfEnabledEnvVar: "true",
helpers.LegacySessionKeyEnvVar: "lalala",
helpers.BasePathEnvVar: os.Getenv(helpers.BasePathEnvVar),
helpers.SMTPFromEnvVar: "[email protected]",
helpers.SMTPHostEnvVar: "localhost",
helpers.SecureCookiesEnvVar: "1",
helpers.TICSecretEnvVar: "tic",
helpers.ClientIDEnvVar: "ID",
helpers.ClientSecretEnvVar: "Secret",
helpers.HostnameEnvVar: "https://hostname",
helpers.LoginURLEnvVar: "https://loginurl",
helpers.UAAURLEnvVar: "https://uaaurl",
helpers.APIURLEnvVar: "https://apiurl",
helpers.LogURLEnvVar: "https://logurl",
helpers.PProfEnabledEnvVar: "true",
helpers.SessionAuthenticationEnvVar: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
helpers.CSRFKeyEnvVar: "00112233445566778899aabbccddeeff",
helpers.BasePathEnvVar: os.Getenv(helpers.BasePathEnvVar),
helpers.SMTPFromEnvVar: "[email protected]",
helpers.SMTPHostEnvVar: "localhost",
helpers.SecureCookiesEnvVar: "1",
helpers.TICSecretEnvVar: "tic",
}
}

Expand Down

0 comments on commit fee76cb

Please sign in to comment.