This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force a default session secret in development environment fixes #1067
- Loading branch information
Showing
2 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package buffalo | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gobuffalo/envy" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOptions_NewOptions(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
env string | ||
secret string | ||
expectErr string | ||
}{ | ||
{name: "Development doesn't fail with no secret", env: "development", secret: "", expectErr: "securecookie: the value is not valid"}, | ||
{name: "Development doesn't fail with secret set", env: "development", secret: "secrets", expectErr: "securecookie: the value is not valid"}, | ||
{name: "Test doesn't fail with secret set", env: "test", secret: "", expectErr: "securecookie: the value is not valid"}, | ||
{name: "Test doesn't fail with secret set", env: "test", secret: "secrets", expectErr: "securecookie: the value is not valid"}, | ||
{name: "Production fails with no secret", env: "production", secret: "", expectErr: "securecookie: hash key is not set"}, | ||
{name: "Production doesn't fail with secret set", env: "production", secret: "secrets", expectErr: "securecookie: the value is not valid"}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
r := require.New(t) | ||
envy.Temp(func() { | ||
envy.Set("GO_ENV", test.env) | ||
envy.Set("SESSION_SECRET", test.secret) | ||
|
||
opts := NewOptions() | ||
|
||
req, _ := http.NewRequest("GET", "/", strings.NewReader("")) | ||
req.AddCookie(&http.Cookie{Name: "_buffalo_session"}) | ||
|
||
_, err := opts.SessionStore.New(req, "_buffalo_session") | ||
|
||
r.Error(err) | ||
r.Equal(test.expectErr, err.Error()) | ||
}) | ||
}) | ||
} | ||
} |