Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(913)

Unified Diff: server/auth/signing/context_test.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: gaemiddleware: add middleware func for WithProd Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « server/auth/signing/context.go ('k') | server/auth/xsrf/xsrf.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/auth/signing/context_test.go
diff --git a/server/auth/signing/context_test.go b/server/auth/signing/context_test.go
index 4a49d16f4d3a738df2cefd762c018b04bb6f72b6..667520014d04995fc54ac572ce8437f76238af1d 100644
--- a/server/auth/signing/context_test.go
+++ b/server/auth/signing/context_test.go
@@ -1,54 +1,51 @@
// Copyright 2015 The LUCI Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package signing
import (
"errors"
- "net/http"
"net/http/httptest"
"testing"
- "github.com/julienschmidt/httprouter"
"golang.org/x/net/context"
- "github.com/luci/luci-go/server/middleware"
+ "github.com/luci/luci-go/server/router"
. "github.com/luci/luci-go/common/testing/assertions"
. "github.com/smartystreets/goconvey/convey"
)
func TestContext(t *testing.T) {
Convey("Works", t, func() {
ctx := context.Background()
So(GetSigner(ctx), ShouldBeNil)
_, _, err := SignBytes(ctx, nil)
So(err, ShouldErrLike, "no Signer in the context")
ctx = SetSigner(ctx, phonySigner{})
_, _, err = SignBytes(ctx, nil)
So(err, ShouldBeNil)
})
}
func TestHandlers(t *testing.T) {
-
call := func(s Signer) (*PublicCertificates, error) {
- r := httprouter.New()
- InstallHandlers(r, func(h middleware.Handler) httprouter.Handle {
- return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
- ctx := SetSigner(context.Background(), s)
- h(ctx, w, r, p)
- }
+ r := router.New()
+ InstallHandlers(r, router.MiddlewareChain{
+ func(c *router.Context, next router.Handler) {
+ c.Context = SetSigner(context.Background(), s)
+ next(c)
+ },
})
ts := httptest.NewServer(r)
return FetchCertificates(context.Background(), ts.URL+"/auth/api/v1/server/certificates")
}
Convey("Works", t, func() {
certs, err := call(phonySigner{})
So(err, ShouldBeNil)
So(len(certs.Certificates), ShouldEqual, 1)
})
« no previous file with comments | « server/auth/signing/context.go ('k') | server/auth/xsrf/xsrf.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698