| OLD | NEW |
| 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 auth | 5 package auth |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "net" | 9 "net" |
| 10 "net/http" | 10 "net/http" |
| 11 "net/http/httptest" | 11 "net/http/httptest" |
| 12 "testing" | 12 "testing" |
| 13 | 13 |
| 14 "golang.org/x/net/context" | 14 "golang.org/x/net/context" |
| 15 | 15 |
| 16 "github.com/luci/luci-go/server/router" | 16 "github.com/luci/luci-go/server/router" |
| 17 | 17 |
| 18 "github.com/luci/luci-go/server/auth/authdb" | 18 "github.com/luci/luci-go/server/auth/authdb" |
| 19 "github.com/luci/luci-go/server/auth/identity" | 19 "github.com/luci/luci-go/server/auth/identity" |
| 20 "github.com/luci/luci-go/server/auth/service/protocol" | 20 "github.com/luci/luci-go/server/auth/service/protocol" |
| 21 "github.com/luci/luci-go/server/auth/signing" | 21 "github.com/luci/luci-go/server/auth/signing" |
| 22 | 22 |
| 23 "github.com/luci/luci-go/common/errors" | 23 "github.com/luci/luci-go/common/errors" |
| 24 "github.com/luci/luci-go/common/retry" |
| 24 . "github.com/luci/luci-go/common/testing/assertions" | 25 . "github.com/luci/luci-go/common/testing/assertions" |
| 25 . "github.com/smartystreets/goconvey/convey" | 26 . "github.com/smartystreets/goconvey/convey" |
| 26 ) | 27 ) |
| 27 | 28 |
| 28 func TestAuthenticate(t *testing.T) { | 29 func TestAuthenticate(t *testing.T) { |
| 29 t.Parallel() | 30 t.Parallel() |
| 30 | 31 |
| 31 Convey("Happy path", t, func() { | 32 Convey("Happy path", t, func() { |
| 32 c := injectTestDB(context.Background(), &fakeDB{ | 33 c := injectTestDB(context.Background(), &fakeDB{ |
| 33 allowedClientID: "some_client_id", | 34 allowedClientID: "some_client_id", |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 Convey("Fatal error", t, func() { | 170 Convey("Fatal error", t, func() { |
| 170 rr := call(&Authenticator{ | 171 rr := call(&Authenticator{ |
| 171 Methods: []Method{fakeAuthMethod{clientID: "another_clie
nt_id"}}, | 172 Methods: []Method{fakeAuthMethod{clientID: "another_clie
nt_id"}}, |
| 172 }) | 173 }) |
| 173 So(rr.Code, ShouldEqual, 401) | 174 So(rr.Code, ShouldEqual, 401) |
| 174 So(rr.Body.String(), ShouldEqual, "Authentication error\n") | 175 So(rr.Body.String(), ShouldEqual, "Authentication error\n") |
| 175 }) | 176 }) |
| 176 | 177 |
| 177 Convey("Transient error", t, func() { | 178 Convey("Transient error", t, func() { |
| 178 rr := call(&Authenticator{ | 179 rr := call(&Authenticator{ |
| 179 » » » Methods: []Method{fakeAuthMethod{err: errors.WrapTransie
nt(errors.New("boo"))}}, | 180 » » » Methods: []Method{fakeAuthMethod{err: errors.New("boo",
retry.Tag)}}, |
| 180 }) | 181 }) |
| 181 So(rr.Code, ShouldEqual, 500) | 182 So(rr.Code, ShouldEqual, 500) |
| 182 So(rr.Body.String(), ShouldEqual, "Transient error during authen
tication\n") | 183 So(rr.Body.String(), ShouldEqual, "Transient error during authen
tication\n") |
| 183 }) | 184 }) |
| 184 } | 185 } |
| 185 | 186 |
| 186 /// | 187 /// |
| 187 | 188 |
| 188 func makeRequest() *http.Request { | 189 func makeRequest() *http.Request { |
| 189 req, _ := http.NewRequest("GET", "http://some-url", nil) | 190 req, _ := http.NewRequest("GET", "http://some-url", nil) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 } | 268 } |
| 268 return db.authServiceURL, nil | 269 return db.authServiceURL, nil |
| 269 } | 270 } |
| 270 | 271 |
| 271 func (db *fakeDB) GetTokenServiceURL(c context.Context) (string, error) { | 272 func (db *fakeDB) GetTokenServiceURL(c context.Context) (string, error) { |
| 272 if db.tokenServiceURL == "" { | 273 if db.tokenServiceURL == "" { |
| 273 return "", errors.New("fakeDB: GetTokenServiceURL is not configu
red") | 274 return "", errors.New("fakeDB: GetTokenServiceURL is not configu
red") |
| 274 } | 275 } |
| 275 return db.tokenServiceURL, nil | 276 return db.tokenServiceURL, nil |
| 276 } | 277 } |
| OLD | NEW |