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

Side by Side Diff: server/auth/auth_test.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: more refactor Created 3 years, 5 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 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/transient"
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
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", transient.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
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 }
OLDNEW
« grpc/grpcutil/errors.go ('K') | « server/auth/auth.go ('k') | server/auth/delegation.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698