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

Side by Side 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: Update tests 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package signing 5 package signing
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "net/http"
10 "net/http/httptest" 9 "net/http/httptest"
11 "testing" 10 "testing"
12 11
13 "github.com/julienschmidt/httprouter"
14 "golang.org/x/net/context" 12 "golang.org/x/net/context"
15 13
16 "github.com/luci/luci-go/server/middleware"
17
18 . "github.com/luci/luci-go/common/testing/assertions" 14 . "github.com/luci/luci-go/common/testing/assertions"
15 "github.com/luci/luci-go/server/router"
19 . "github.com/smartystreets/goconvey/convey" 16 . "github.com/smartystreets/goconvey/convey"
20 ) 17 )
21 18
22 func TestContext(t *testing.T) { 19 func TestContext(t *testing.T) {
23 Convey("Works", t, func() { 20 Convey("Works", t, func() {
24 ctx := context.Background() 21 ctx := context.Background()
25 22
26 So(GetSigner(ctx), ShouldBeNil) 23 So(GetSigner(ctx), ShouldBeNil)
27 _, _, err := SignBytes(ctx, nil) 24 _, _, err := SignBytes(ctx, nil)
28 So(err, ShouldErrLike, "no Signer in the context") 25 So(err, ShouldErrLike, "no Signer in the context")
29 26
30 ctx = SetSigner(ctx, phonySigner{}) 27 ctx = SetSigner(ctx, phonySigner{})
31 _, _, err = SignBytes(ctx, nil) 28 _, _, err = SignBytes(ctx, nil)
32 So(err, ShouldBeNil) 29 So(err, ShouldBeNil)
33 }) 30 })
34 } 31 }
35 32
36 func TestHandlers(t *testing.T) { 33 func TestHandlers(t *testing.T) {
37 34
38 call := func(s Signer) (*PublicCertificates, error) { 35 call := func(s Signer) (*PublicCertificates, error) {
39 » » r := httprouter.New() 36 » » r := router.New()
40 » » InstallHandlers(r, func(h middleware.Handler) httprouter.Handle { 37 » » InstallHandlers(r, []router.Handler{
41 » » » return func(w http.ResponseWriter, r *http.Request, p ht tprouter.Params) { 38 » » » func(c *router.Context) { c.Context = SetSigner(context. Background(), s) },
42 » » » » ctx := SetSigner(context.Background(), s)
43 » » » » h(ctx, w, r, p)
44 » » » }
45 }) 39 })
46 ts := httptest.NewServer(r) 40 ts := httptest.NewServer(r)
47 return FetchCertificates(context.Background(), ts.URL+"/auth/api /v1/server/certificates") 41 return FetchCertificates(context.Background(), ts.URL+"/auth/api /v1/server/certificates")
48 } 42 }
49 43
50 Convey("Works", t, func() { 44 Convey("Works", t, func() {
51 certs, err := call(phonySigner{}) 45 certs, err := call(phonySigner{})
52 So(err, ShouldBeNil) 46 So(err, ShouldBeNil)
53 So(len(certs.Certificates), ShouldEqual, 1) 47 So(len(certs.Certificates), ShouldEqual, 1)
54 }) 48 })
(...skipping 25 matching lines...) Expand all
80 } 74 }
81 return &PublicCertificates{ 75 return &PublicCertificates{
82 Certificates: []Certificate{ 76 Certificates: []Certificate{
83 { 77 {
84 KeyName: "phonyKey", 78 KeyName: "phonyKey",
85 X509CertificatePEM: "phonyPEM", 79 X509CertificatePEM: "phonyPEM",
86 }, 80 },
87 }, 81 },
88 }, nil 82 }, nil
89 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698