| 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 "errors" | 8 "errors" |
| 9 "net" | 9 "net" |
| 10 "net/http" | 10 "net/http" |
| 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/secrets" | 15 "github.com/luci/luci-go/server/secrets" |
| 16 | 16 |
| 17 "github.com/luci/luci-go/server/auth/authdb" | 17 "github.com/luci/luci-go/server/auth/authdb" |
| 18 "github.com/luci/luci-go/server/auth/identity" | 18 "github.com/luci/luci-go/server/auth/identity" |
| 19 "github.com/luci/luci-go/server/auth/service/protocol" | 19 "github.com/luci/luci-go/server/auth/service/protocol" |
| 20 "github.com/luci/luci-go/server/auth/signing" | 20 "github.com/luci/luci-go/server/auth/signing" |
| 21 | 21 |
| 22 . "github.com/luci/luci-go/common/testing/assertions" | 22 . "github.com/luci/luci-go/common/testing/assertions" |
| 23 . "github.com/smartystreets/goconvey/convey" | 23 . "github.com/smartystreets/goconvey/convey" |
| 24 ) | 24 ) |
| 25 | 25 |
| 26 func TestAuthenticate(t *testing.T) { | 26 func TestAuthenticate(t *testing.T) { |
| 27 t.Parallel() |
| 28 |
| 27 Convey("IsAllowedOAuthClientID on default DB", t, func() { | 29 Convey("IsAllowedOAuthClientID on default DB", t, func() { |
| 28 c := context.Background() | 30 c := context.Background() |
| 29 auth := Authenticator{fakeOAuthMethod{clientID: "some_client_id"
}} | 31 auth := Authenticator{fakeOAuthMethod{clientID: "some_client_id"
}} |
| 30 _, err := auth.Authenticate(c, makeRequest()) | 32 _, err := auth.Authenticate(c, makeRequest()) |
| 31 So(err, ShouldErrLike, "the library is not properly configured") | 33 So(err, ShouldErrLike, "the library is not properly configured") |
| 32 }) | 34 }) |
| 33 | 35 |
| 34 Convey("IsAllowedOAuthClientID with valid client_id", t, func() { | 36 Convey("IsAllowedOAuthClientID with valid client_id", t, func() { |
| 35 c := injectTestDB(context.Background(), &fakeDB{ | 37 c := injectTestDB(context.Background(), &fakeDB{ |
| 36 allowedClientID: "some_client_id", | 38 allowedClientID: "some_client_id", |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 176 } |
| 175 return db.authServiceURL, nil | 177 return db.authServiceURL, nil |
| 176 } | 178 } |
| 177 | 179 |
| 178 func (db *fakeDB) GetTokenServiceURL(c context.Context) (string, error) { | 180 func (db *fakeDB) GetTokenServiceURL(c context.Context) (string, error) { |
| 179 if db.authServiceURL == "" { | 181 if db.authServiceURL == "" { |
| 180 return "", errors.New("fakeDB: GetTokenServiceURL is not configu
red") | 182 return "", errors.New("fakeDB: GetTokenServiceURL is not configu
red") |
| 181 } | 183 } |
| 182 return db.tokenServiceURL, nil | 184 return db.tokenServiceURL, nil |
| 183 } | 185 } |
| OLD | NEW |