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

Side by Side Diff: common/auth/localauth/ctx_test.go

Issue 2988263002: Fix mocked time in 'common/auth/localauth' tests. (Closed)
Patch Set: doh Created 3 years, 4 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
« no previous file with comments | « no previous file | common/auth/localauth/server_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The LUCI Authors. 1 // Copyright 2017 The LUCI Authors.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 14 matching lines...) Expand all
25 "github.com/luci/luci-go/common/clock/testclock" 25 "github.com/luci/luci-go/common/clock/testclock"
26 "github.com/luci/luci-go/lucictx" 26 "github.com/luci/luci-go/lucictx"
27 27
28 . "github.com/smartystreets/goconvey/convey" 28 . "github.com/smartystreets/goconvey/convey"
29 ) 29 )
30 30
31 func TestWithLocalAuth(t *testing.T) { 31 func TestWithLocalAuth(t *testing.T) {
32 t.Parallel() 32 t.Parallel()
33 33
34 ctx := context.Background() 34 ctx := context.Background()
35 » ctx, _ = testclock.UseTime(ctx, testclock.TestRecentTimeLocal) 35 » ctx, _ = testclock.UseTime(ctx, testclock.TestRecentTimeUTC)
36 36
37 gen := func(ctx context.Context, scopes []string, lifetime time.Duration ) (*oauth2.Token, error) { 37 gen := func(ctx context.Context, scopes []string, lifetime time.Duration ) (*oauth2.Token, error) {
38 return &oauth2.Token{ 38 return &oauth2.Token{
39 AccessToken: "tok", 39 AccessToken: "tok",
40 Expiry: clock.Now(ctx).Add(30 * time.Minute), 40 Expiry: clock.Now(ctx).Add(30 * time.Minute),
41 }, nil 41 }, nil
42 } 42 }
43 43
44 srv := Server{ 44 srv := Server{
45 TokenGenerators: map[string]TokenGenerator{"acc_id": gen}, 45 TokenGenerators: map[string]TokenGenerator{"acc_id": gen},
46 } 46 }
47 47
48 Convey("Works", t, func() { 48 Convey("Works", t, func() {
49 WithLocalAuth(ctx, &srv, func(ctx context.Context) error { 49 WithLocalAuth(ctx, &srv, func(ctx context.Context) error {
50 p := lucictx.GetLocalAuth(ctx) 50 p := lucictx.GetLocalAuth(ctx)
51 So(p, ShouldNotBeNil) 51 So(p, ShouldNotBeNil)
52 req := prepReq(p, "/rpc/LuciLocalAuthService.GetOAuthTok en", map[string]interface{}{ 52 req := prepReq(p, "/rpc/LuciLocalAuthService.GetOAuthTok en", map[string]interface{}{
53 "scopes": []string{"B", "A"}, 53 "scopes": []string{"B", "A"},
54 "secret": p.Secret, 54 "secret": p.Secret,
55 "account_id": "acc_id", 55 "account_id": "acc_id",
56 }) 56 })
57 » » » So(call(req), ShouldEqual, `HTTP 200 (json): {"access_to ken":"tok","expiry":1454502906}`) 57 » » » So(call(req), ShouldEqual, `HTTP 200 (json): {"access_to ken":"tok","expiry":1454474106}`)
58 return nil 58 return nil
59 }) 59 })
60 }) 60 })
61 } 61 }
OLDNEW
« no previous file with comments | « no previous file | common/auth/localauth/server_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698