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

Side by Side Diff: impl/memory/user_test.go

Issue 1522783002: Add User Testing interface to impl/memory. (Closed) Base URL: https://github.com/luci/gae.git@logging_service
Patch Set: rebase Created 5 years 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 | « impl/memory/user.go ('k') | impl/prod/user.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package memory
6
7 import (
8 "testing"
9
10 userS "github.com/luci/gae/service/user"
11 . "github.com/luci/luci-go/common/testing/assertions"
12 . "github.com/smartystreets/goconvey/convey"
13 "golang.org/x/net/context"
14 )
15
16 func TestUser(t *testing.T) {
17 t.Parallel()
18
19 Convey("user", t, func() {
20 c := Use(context.Background())
21 user := userS.Get(c)
22
23 Convey("default state is anonymous", func() {
24 So(user.Current(), ShouldBeNil)
25
26 usr, err := user.CurrentOAuth("something")
27 So(err, ShouldBeNil)
28 So(usr, ShouldBeNil)
29
30 So(user.IsAdmin(), ShouldBeFalse)
31 })
32
33 Convey("can login (normal)", func() {
34 user.Testable().Login("hello@world.com", "", false)
35 So(user.Current(), ShouldResembleV, &userS.User{
36 Email: "hello@world.com",
37 AuthDomain: "world.com",
38 ID: "14628837901535854097",
39 })
40
41 usr, err := user.CurrentOAuth("scope")
42 So(usr, ShouldBeNil)
43 So(err, ShouldBeNil)
44
45 Convey("and logout", func() {
46 user.Testable().Logout()
47 So(user.Current(), ShouldBeNil)
48
49 usr, err := user.CurrentOAuth("scope")
50 So(usr, ShouldBeNil)
51 So(err, ShouldBeNil)
52 })
53 })
54
55 Convey("can be admin", func() {
56 user.Testable().Login("hello@world.com", "", true)
57 So(user.Current(), ShouldResembleV, &userS.User{
58 Email: "hello@world.com",
59 AuthDomain: "world.com",
60 ID: "14628837901535854097",
61 Admin: true,
62 })
63 So(user.IsAdmin(), ShouldBeTrue)
64 })
65
66 Convey("can login (oauth)", func() {
67 user.Testable().Login("hello@world.com", "clientID", fal se)
68 usr, err := user.CurrentOAuth("scope")
69 So(err, ShouldBeNil)
70 So(usr, ShouldResembleV, &userS.User{
71 Email: "hello@world.com",
72 AuthDomain: "world.com",
73 ID: "14628837901535854097",
74 ClientID: "clientID",
75 })
76
77 So(user.Current(), ShouldBeNil)
78
79 Convey("and logout", func() {
80 user.Testable().Logout()
81 So(user.Current(), ShouldBeNil)
82
83 usr, err := user.CurrentOAuth("scope")
84 So(usr, ShouldBeNil)
85 So(err, ShouldBeNil)
86 })
87 })
88
89 Convey("panics on bad email", func() {
90 So(func() {
91 user.Testable().Login("bademail", "", false)
92 }, ShouldPanicLike, `"bademail" doesn't seem to be a val id email`)
93
94 So(func() {
95 user.Testable().Login("too@many@ats.com", "", fa lse)
96 }, ShouldPanicLike, `"too@many@ats.com" doesn't seem to be a valid email`)
97 })
98
99 Convey("fake URLs", func() {
100 url, err := user.LoginURL("https://funky.example.com")
101 So(err, ShouldBeNil)
102 So(url, ShouldEqual, "https://fakeapp.example.com/_ah/lo gin?redirect=https%3A%2F%2Ffunky.example.com")
103
104 url, err = user.LogoutURL("https://funky.example.com")
105 So(err, ShouldBeNil)
106 So(url, ShouldEqual, "https://fakeapp.example.com/_ah/lo gout?redirect=https%3A%2F%2Ffunky.example.com")
107 })
108
109 Convey("Some stuff is deprecated", func() {
110 url, err := user.LoginURLFederated("https://something", "something")
111 So(err, ShouldErrLike, "LoginURLFederated is deprecated" )
112 So(url, ShouldEqual, "")
113
114 key, err := user.OAuthConsumerKey()
115 So(err, ShouldErrLike, "OAuthConsumerKey is deprecated")
116 So(key, ShouldEqual, "")
117 })
118
119 })
120 }
OLDNEW
« no previous file with comments | « impl/memory/user.go ('k') | impl/prod/user.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698