mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-12 08:37:38 +02:00
config: generate cookie secret if not set in all-in-one mode (#3742)
* config: generate cookie secret if not set in all-in-one mode * fix tests * config: add warning about cookie_secret * breakup lines
This commit is contained in:
parent
2c9087f5e7
commit
9413123c0f
8 changed files with 111 additions and 17 deletions
|
@ -53,11 +53,6 @@ func Test_Validate(t *testing.T) {
|
|||
badSignoutRedirectURL := testOptions()
|
||||
badSignoutRedirectURL.SignOutRedirectURLString = "--"
|
||||
|
||||
missingSharedSecretWithPersistence := testOptions()
|
||||
missingSharedSecretWithPersistence.SharedKey = ""
|
||||
missingSharedSecretWithPersistence.DataBrokerStorageType = StorageRedisName
|
||||
missingSharedSecretWithPersistence.DataBrokerStorageConnectionString = "redis://somehost:6379"
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
testOpts *Options
|
||||
|
@ -71,7 +66,6 @@ func Test_Validate(t *testing.T) {
|
|||
{"invalid databroker storage type", invalidStorageType, true},
|
||||
{"missing databroker storage dsn", missingStorageDSN, true},
|
||||
{"invalid signout redirect url", badSignoutRedirectURL, true},
|
||||
{"no shared key with databroker persistence", missingSharedSecretWithPersistence, true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
@ -776,6 +770,36 @@ func TestOptions_GetSetResponseHeaders(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestOptions_GetSharedKey(t *testing.T) {
|
||||
t.Run("default", func(t *testing.T) {
|
||||
o := NewDefaultOptions()
|
||||
bs, err := o.GetSharedKey()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, randomSharedKey, base64.StdEncoding.EncodeToString(bs))
|
||||
})
|
||||
t.Run("missing", func(t *testing.T) {
|
||||
o := NewDefaultOptions()
|
||||
o.Services = ServiceProxy
|
||||
_, err := o.GetSharedKey()
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestOptions_GetCookieSecret(t *testing.T) {
|
||||
t.Run("default", func(t *testing.T) {
|
||||
o := NewDefaultOptions()
|
||||
bs, err := o.GetCookieSecret()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, randomSharedKey, base64.StdEncoding.EncodeToString(bs))
|
||||
})
|
||||
t.Run("missing", func(t *testing.T) {
|
||||
o := NewDefaultOptions()
|
||||
o.Services = ServiceProxy
|
||||
_, err := o.GetCookieSecret()
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func encodeCert(cert *tls.Certificate) []byte {
|
||||
return pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Certificate[0]})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue