aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2017-02-19 02:20:04 +0000
committerNiall Sheridan <nsheridan@gmail.com>2017-04-10 22:17:01 +0100
commit54cefc8500136ca60f294bbb3360faeccaaf52b1 (patch)
tree41c1ff9476852e4ae109267370ea014c08721c94 /server
parentd919f85c19cb754b1507b45e1609292f495ffff9 (diff)
enable race detection
Diffstat (limited to 'server')
-rw-r--r--server/handlers_test.go23
1 files changed, 8 insertions, 15 deletions
diff --git a/server/handlers_test.go b/server/handlers_test.go
index a08d638..1670f2f 100644
--- a/server/handlers_test.go
+++ b/server/handlers_test.go
@@ -26,23 +26,20 @@ import (
"github.com/stripe/krl"
)
-func newContext(t *testing.T) *appContext {
- f, err := ioutil.TempFile(os.TempDir(), "signing_key_")
- if err != nil {
- t.Error(err)
- }
+var ctx *appContext
+
+func init() {
+ f, _ := ioutil.TempFile(os.TempDir(), "signing_key_")
defer os.Remove(f.Name())
f.Write(testdata.Priv)
f.Close()
- if keysigner, err = signer.New(&config.SSH{
+ keysigner, _ = signer.New(&config.SSH{
SigningKey: f.Name(),
MaxAge: "1h",
- }); err != nil {
- t.Error(err)
- }
+ })
authprovider = testprovider.New()
certstore = store.NewMemoryStore()
- return &appContext{
+ ctx = &appContext{
cookiestore: sessions.NewCookieStore([]byte("secret")),
authsession: &auth.Session{AuthURL: "https://www.example.com/auth"},
}
@@ -51,7 +48,7 @@ func newContext(t *testing.T) *appContext {
func TestLoginHandler(t *testing.T) {
req, _ := http.NewRequest("GET", "/auth/login", nil)
resp := httptest.NewRecorder()
- loginHandler(newContext(t), resp, req)
+ loginHandler(ctx, resp, req)
if resp.Code != http.StatusFound && resp.Header().Get("Location") != "https://www.example.com/auth" {
t.Error("Unexpected response")
}
@@ -61,7 +58,6 @@ func TestCallbackHandler(t *testing.T) {
req, _ := http.NewRequest("GET", "/auth/callback", nil)
req.Form = url.Values{"state": []string{"state"}, "code": []string{"abcdef"}}
resp := httptest.NewRecorder()
- ctx := newContext(t)
ctx.setAuthStateCookie(resp, req, "state")
callbackHandler(ctx, resp, req)
if resp.Code != http.StatusFound && resp.Header().Get("Location") != "/" {
@@ -72,7 +68,6 @@ func TestCallbackHandler(t *testing.T) {
func TestRootHandler(t *testing.T) {
req, _ := http.NewRequest("GET", "/", nil)
resp := httptest.NewRecorder()
- ctx := newContext(t)
tok := &oauth2.Token{
AccessToken: "XXX_TEST_TOKEN_STRING_XXX",
Expiry: time.Now().Add(1 * time.Hour),
@@ -87,7 +82,6 @@ func TestRootHandler(t *testing.T) {
func TestRootHandlerNoSession(t *testing.T) {
req, _ := http.NewRequest("GET", "/", nil)
resp := httptest.NewRecorder()
- ctx := newContext(t)
rootHandler(ctx, resp, req)
if resp.Code != http.StatusSeeOther {
t.Errorf("Unexpected status: %s, wanted %s", http.StatusText(resp.Code), http.StatusText(http.StatusSeeOther))
@@ -101,7 +95,6 @@ func TestSignRevoke(t *testing.T) {
})
req, _ := http.NewRequest("POST", "/sign", bytes.NewReader(s))
resp := httptest.NewRecorder()
- ctx := newContext(t)
req.Header.Set("Authorization", "Bearer abcdef")
signHandler(ctx, resp, req)
if resp.Code != http.StatusOK {