| 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 "fmt" | 8 "fmt" |
| 9 "math/rand" | 9 "math/rand" |
| 10 "net/http" | 10 "net/http" |
| 11 "testing" | 11 "testing" |
| 12 "time" | 12 "time" |
| 13 | 13 |
| 14 "golang.org/x/net/context" | 14 "golang.org/x/net/context" |
| 15 | 15 |
| 16 "github.com/luci/luci-go/common/clock" | 16 "github.com/luci/luci-go/common/clock" |
| 17 "github.com/luci/luci-go/common/clock/testclock" | 17 "github.com/luci/luci-go/common/clock/testclock" |
| 18 "github.com/luci/luci-go/common/data/rand/mathrand" | 18 "github.com/luci/luci-go/common/data/rand/mathrand" |
| 19 "github.com/luci/luci-go/server/auth/delegation" | 19 "github.com/luci/luci-go/server/auth/delegation" |
| 20 "github.com/luci/luci-go/server/auth/signing" | 20 "github.com/luci/luci-go/server/auth/signing" |
| 21 "github.com/luci/luci-go/server/auth/signing/signingtest" | 21 "github.com/luci/luci-go/server/auth/signing/signingtest" |
| 22 . "github.com/smartystreets/goconvey/convey" | 22 . "github.com/smartystreets/goconvey/convey" |
| 23 ) | 23 ) |
| 24 | 24 |
| 25 func TestMintDelegationToken(t *testing.T) { | 25 func TestMintDelegationToken(t *testing.T) { |
| 26 t.Parallel() |
| 27 |
| 26 Convey("MintDelegationToken works", t, func() { | 28 Convey("MintDelegationToken works", t, func() { |
| 27 ctx := context.Background() | 29 ctx := context.Background() |
| 28 ctx, _ = testclock.UseTime(ctx, testclock.TestRecentTimeUTC) | 30 ctx, _ = testclock.UseTime(ctx, testclock.TestRecentTimeUTC) |
| 29 ctx = mathrand.Set(ctx, rand.New(rand.NewSource(12345))) | 31 ctx = mathrand.Set(ctx, rand.New(rand.NewSource(12345))) |
| 30 | 32 |
| 31 tokenCache := &mockedCache{} | 33 tokenCache := &mockedCache{} |
| 32 | 34 |
| 33 subtokenID := "123" | 35 subtokenID := "123" |
| 34 mintingReq := "" | 36 mintingReq := "" |
| 35 transport := &clientRPCTransportMock{ | 37 transport := &clientRPCTransportMock{ |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 `"impersonate":"user:abc@example.com","i
ntent":"intent"}`) | 127 `"impersonate":"user:abc@example.com","i
ntent":"intent"}`) |
| 126 | 128 |
| 127 // Cached now. | 129 // Cached now. |
| 128 So(len(tokenCache.data), ShouldEqual, 1) | 130 So(len(tokenCache.data), ShouldEqual, 1) |
| 129 for k := range tokenCache.data { | 131 for k := range tokenCache.data { |
| 130 So(k, ShouldEqual, "delegation/2/tjYIGNrwFvKa0FT
5juu7ThjpxBo") | 132 So(k, ShouldEqual, "delegation/2/tjYIGNrwFvKa0FT
5juu7ThjpxBo") |
| 131 } | 133 } |
| 132 }) | 134 }) |
| 133 }) | 135 }) |
| 134 } | 136 } |
| OLD | NEW |