| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 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 auth | 5 package auth |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "net/http" | 9 "net/http" |
| 10 "net/http/httptest" | 10 "net/http/httptest" |
| 11 "testing" | 11 "testing" |
| 12 | 12 |
| 13 "golang.org/x/net/context" | 13 "golang.org/x/net/context" |
| 14 | 14 |
| 15 "github.com/luci/luci-go/server/auth/signing" | 15 "github.com/luci/luci-go/server/auth/signing" |
| 16 "github.com/luci/luci-go/server/router" | 16 "github.com/luci/luci-go/server/router" |
| 17 | 17 |
| 18 . "github.com/luci/luci-go/common/testing/assertions" | 18 . "github.com/luci/luci-go/common/testing/assertions" |
| 19 . "github.com/smartystreets/goconvey/convey" | 19 . "github.com/smartystreets/goconvey/convey" |
| 20 ) | 20 ) |
| 21 | 21 |
| 22 func TestCertificatesHandler(t *testing.T) { | 22 func TestCertificatesHandler(t *testing.T) { |
| 23 t.Parallel() |
| 24 |
| 23 call := func(s signing.Signer) (*signing.PublicCertificates, error) { | 25 call := func(s signing.Signer) (*signing.PublicCertificates, error) { |
| 24 r := router.New() | 26 r := router.New() |
| 25 InstallHandlers(r, router.NewMiddlewareChain( | 27 InstallHandlers(r, router.NewMiddlewareChain( |
| 26 func(c *router.Context, next router.Handler) { | 28 func(c *router.Context, next router.Handler) { |
| 27 c.Context = SetConfig(context.Background(), Conf
ig{Signer: s}) | 29 c.Context = SetConfig(context.Background(), Conf
ig{Signer: s}) |
| 28 next(c) | 30 next(c) |
| 29 }, | 31 }, |
| 30 )) | 32 )) |
| 31 ts := httptest.NewServer(r) | 33 ts := httptest.NewServer(r) |
| 32 ctx := SetConfig(context.Background(), Config{ | 34 ctx := SetConfig(context.Background(), Config{ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 48 So(err, ShouldErrLike, "HTTP code (404)") | 50 So(err, ShouldErrLike, "HTTP code (404)") |
| 49 }) | 51 }) |
| 50 | 52 |
| 51 Convey("Error getting certs", t, func() { | 53 Convey("Error getting certs", t, func() { |
| 52 _, err := call(&phonySigner{errors.New("fail")}) | 54 _, err := call(&phonySigner{errors.New("fail")}) |
| 53 So(err, ShouldErrLike, "HTTP code (500)") | 55 So(err, ShouldErrLike, "HTTP code (500)") |
| 54 }) | 56 }) |
| 55 } | 57 } |
| 56 | 58 |
| 57 func TestServiceInfoHandler(t *testing.T) { | 59 func TestServiceInfoHandler(t *testing.T) { |
| 60 t.Parallel() |
| 61 |
| 58 Convey("Works", t, func() { | 62 Convey("Works", t, func() { |
| 59 r := router.New() | 63 r := router.New() |
| 60 signer := &phonySigner{} | 64 signer := &phonySigner{} |
| 61 | 65 |
| 62 InstallHandlers(r, router.NewMiddlewareChain( | 66 InstallHandlers(r, router.NewMiddlewareChain( |
| 63 func(ctx *router.Context, next router.Handler) { | 67 func(ctx *router.Context, next router.Handler) { |
| 64 ctx.Context = SetConfig(context.Background(), Co
nfig{Signer: signer}) | 68 ctx.Context = SetConfig(context.Background(), Co
nfig{Signer: signer}) |
| 65 next(ctx) | 69 next(ctx) |
| 66 }, | 70 }, |
| 67 )) | 71 )) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 return nil, s.err | 122 return nil, s.err |
| 119 } | 123 } |
| 120 return &signing.ServiceInfo{ | 124 return &signing.ServiceInfo{ |
| 121 AppID: "phony-app", | 125 AppID: "phony-app", |
| 122 AppRuntime: "go", | 126 AppRuntime: "go", |
| 123 AppRuntimeVersion: "go1.5.1", | 127 AppRuntimeVersion: "go1.5.1", |
| 124 AppVersion: "1234-abcdef", | 128 AppVersion: "1234-abcdef", |
| 125 ServiceAccountName: "phony-app-account@example.com", | 129 ServiceAccountName: "phony-app-account@example.com", |
| 126 }, nil | 130 }, nil |
| 127 } | 131 } |
| OLD | NEW |