| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 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 internal | 5 package internal |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "context" | 8 "context" |
| 9 "encoding/json" | 9 "encoding/json" |
| 10 "net" | 10 "net" |
| 11 "net/http" | 11 "net/http" |
| 12 "net/http/httptest" | 12 "net/http/httptest" |
| 13 "testing" | 13 "testing" |
| 14 "time" | 14 "time" |
| 15 | 15 |
| 16 "golang.org/x/oauth2" | 16 "golang.org/x/oauth2" |
| 17 | 17 |
| 18 "github.com/luci/luci-go/common/auth/localauth/rpcs" | 18 "github.com/luci/luci-go/common/auth/localauth/rpcs" |
| 19 » "github.com/luci/luci-go/common/errors" | 19 » "github.com/luci/luci-go/common/retry" |
| 20 "github.com/luci/luci-go/lucictx" | 20 "github.com/luci/luci-go/lucictx" |
| 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 TestLUCIContextProvider(t *testing.T) { | 26 func TestLUCIContextProvider(t *testing.T) { |
| 27 t.Parallel() | 27 t.Parallel() |
| 28 | 28 |
| 29 Convey("Requires local_auth", t, func() { | 29 Convey("Requires local_auth", t, func() { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 Secret: []byte("zekret"), | 101 Secret: []byte("zekret"), |
| 102 AccountID: "acc_id", | 102 AccountID: "acc_id", |
| 103 }) | 103 }) |
| 104 }) | 104 }) |
| 105 | 105 |
| 106 Convey("HTTP 500", func() { | 106 Convey("HTTP 500", func() { |
| 107 responses <- 500 | 107 responses <- 500 |
| 108 tok, err := p.MintToken(ctx, nil) | 108 tok, err := p.MintToken(ctx, nil) |
| 109 So(tok, ShouldBeNil) | 109 So(tok, ShouldBeNil) |
| 110 So(err, ShouldErrLike, `local auth - HTTP 500`) | 110 So(err, ShouldErrLike, `local auth - HTTP 500`) |
| 111 » » » So(errors.IsTransient(err), ShouldBeTrue) | 111 » » » So(retry.Tag.In(err), ShouldBeTrue) |
| 112 }) | 112 }) |
| 113 | 113 |
| 114 Convey("HTTP 403", func() { | 114 Convey("HTTP 403", func() { |
| 115 responses <- 403 | 115 responses <- 403 |
| 116 tok, err := p.MintToken(ctx, nil) | 116 tok, err := p.MintToken(ctx, nil) |
| 117 So(tok, ShouldBeNil) | 117 So(tok, ShouldBeNil) |
| 118 So(err, ShouldErrLike, `local auth - HTTP 403`) | 118 So(err, ShouldErrLike, `local auth - HTTP 403`) |
| 119 » » » So(errors.IsTransient(err), ShouldBeFalse) | 119 » » » So(retry.Tag.In(err), ShouldBeFalse) |
| 120 }) | 120 }) |
| 121 | 121 |
| 122 Convey("RPC level error", func() { | 122 Convey("RPC level error", func() { |
| 123 responses <- rpcs.GetOAuthTokenResponse{ | 123 responses <- rpcs.GetOAuthTokenResponse{ |
| 124 BaseResponse: rpcs.BaseResponse{ | 124 BaseResponse: rpcs.BaseResponse{ |
| 125 ErrorCode: 123, | 125 ErrorCode: 123, |
| 126 ErrorMessage: "omg, error", | 126 ErrorMessage: "omg, error", |
| 127 }, | 127 }, |
| 128 } | 128 } |
| 129 tok, err := p.MintToken(ctx, nil) | 129 tok, err := p.MintToken(ctx, nil) |
| 130 So(tok, ShouldBeNil) | 130 So(tok, ShouldBeNil) |
| 131 So(err, ShouldErrLike, `local auth - RPC code 123: omg,
error`) | 131 So(err, ShouldErrLike, `local auth - RPC code 123: omg,
error`) |
| 132 » » » So(errors.IsTransient(err), ShouldBeFalse) | 132 » » » So(retry.Tag.In(err), ShouldBeFalse) |
| 133 }) | 133 }) |
| 134 }) | 134 }) |
| 135 } | 135 } |
| OLD | NEW |