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 memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "testing" | 8 "testing" |
9 | 9 |
10 » userS "github.com/luci/gae/service/user" | 10 » "github.com/luci/gae/service/user" |
| 11 |
| 12 » "golang.org/x/net/context" |
| 13 |
11 . "github.com/luci/luci-go/common/testing/assertions" | 14 . "github.com/luci/luci-go/common/testing/assertions" |
12 . "github.com/smartystreets/goconvey/convey" | 15 . "github.com/smartystreets/goconvey/convey" |
13 "golang.org/x/net/context" | |
14 ) | 16 ) |
15 | 17 |
16 func TestUser(t *testing.T) { | 18 func TestUser(t *testing.T) { |
17 t.Parallel() | 19 t.Parallel() |
18 | 20 |
19 Convey("user", t, func() { | 21 Convey("user", t, func() { |
20 c := Use(context.Background()) | 22 c := Use(context.Background()) |
21 user := userS.Get(c) | |
22 | 23 |
23 Convey("default state is anonymous", func() { | 24 Convey("default state is anonymous", func() { |
24 » » » So(user.Current(), ShouldBeNil) | 25 » » » So(user.Current(c), ShouldBeNil) |
25 | 26 |
26 » » » usr, err := user.CurrentOAuth("something") | 27 » » » usr, err := user.CurrentOAuth(c, "something") |
27 So(err, ShouldBeNil) | 28 So(err, ShouldBeNil) |
28 So(usr, ShouldBeNil) | 29 So(usr, ShouldBeNil) |
29 | 30 |
30 » » » So(user.IsAdmin(), ShouldBeFalse) | 31 » » » So(user.IsAdmin(c), ShouldBeFalse) |
31 }) | 32 }) |
32 | 33 |
33 Convey("can login (normal)", func() { | 34 Convey("can login (normal)", func() { |
34 » » » user.Testable().Login("hello@world.com", "", false) | 35 » » » user.GetTestable(c).Login("hello@world.com", "", false) |
35 » » » So(user.Current(), ShouldResemble, &userS.User{ | 36 » » » So(user.Current(c), ShouldResemble, &user.User{ |
36 Email: "hello@world.com", | 37 Email: "hello@world.com", |
37 AuthDomain: "world.com", | 38 AuthDomain: "world.com", |
38 ID: "14628837901535854097", | 39 ID: "14628837901535854097", |
39 }) | 40 }) |
40 | 41 |
41 » » » usr, err := user.CurrentOAuth("scope") | 42 » » » usr, err := user.CurrentOAuth(c, "scope") |
42 So(usr, ShouldBeNil) | 43 So(usr, ShouldBeNil) |
43 So(err, ShouldBeNil) | 44 So(err, ShouldBeNil) |
44 | 45 |
45 Convey("and logout", func() { | 46 Convey("and logout", func() { |
46 » » » » user.Testable().Logout() | 47 » » » » user.GetTestable(c).Logout() |
47 » » » » So(user.Current(), ShouldBeNil) | 48 » » » » So(user.Current(c), ShouldBeNil) |
48 | 49 |
49 » » » » usr, err := user.CurrentOAuth("scope") | 50 » » » » usr, err := user.CurrentOAuth(c, "scope") |
50 So(usr, ShouldBeNil) | 51 So(usr, ShouldBeNil) |
51 So(err, ShouldBeNil) | 52 So(err, ShouldBeNil) |
52 }) | 53 }) |
53 }) | 54 }) |
54 | 55 |
55 Convey("can be admin", func() { | 56 Convey("can be admin", func() { |
56 » » » user.Testable().Login("hello@world.com", "", true) | 57 » » » user.GetTestable(c).Login("hello@world.com", "", true) |
57 » » » So(user.Current(), ShouldResemble, &userS.User{ | 58 » » » So(user.Current(c), ShouldResemble, &user.User{ |
58 Email: "hello@world.com", | 59 Email: "hello@world.com", |
59 AuthDomain: "world.com", | 60 AuthDomain: "world.com", |
60 ID: "14628837901535854097", | 61 ID: "14628837901535854097", |
61 Admin: true, | 62 Admin: true, |
62 }) | 63 }) |
63 » » » So(user.IsAdmin(), ShouldBeTrue) | 64 » » » So(user.IsAdmin(c), ShouldBeTrue) |
64 }) | 65 }) |
65 | 66 |
66 Convey("can login (oauth)", func() { | 67 Convey("can login (oauth)", func() { |
67 » » » user.Testable().Login("hello@world.com", "clientID", fal
se) | 68 » » » user.GetTestable(c).Login("hello@world.com", "clientID",
false) |
68 » » » usr, err := user.CurrentOAuth("scope") | 69 » » » usr, err := user.CurrentOAuth(c, "scope") |
69 So(err, ShouldBeNil) | 70 So(err, ShouldBeNil) |
70 » » » So(usr, ShouldResemble, &userS.User{ | 71 » » » So(usr, ShouldResemble, &user.User{ |
71 Email: "hello@world.com", | 72 Email: "hello@world.com", |
72 AuthDomain: "world.com", | 73 AuthDomain: "world.com", |
73 ID: "14628837901535854097", | 74 ID: "14628837901535854097", |
74 ClientID: "clientID", | 75 ClientID: "clientID", |
75 }) | 76 }) |
76 | 77 |
77 » » » So(user.Current(), ShouldBeNil) | 78 » » » So(user.Current(c), ShouldBeNil) |
78 | 79 |
79 Convey("and logout", func() { | 80 Convey("and logout", func() { |
80 » » » » user.Testable().Logout() | 81 » » » » user.GetTestable(c).Logout() |
81 » » » » So(user.Current(), ShouldBeNil) | 82 » » » » So(user.Current(c), ShouldBeNil) |
82 | 83 |
83 » » » » usr, err := user.CurrentOAuth("scope") | 84 » » » » usr, err := user.CurrentOAuth(c, "scope") |
84 So(usr, ShouldBeNil) | 85 So(usr, ShouldBeNil) |
85 So(err, ShouldBeNil) | 86 So(err, ShouldBeNil) |
86 }) | 87 }) |
87 }) | 88 }) |
88 | 89 |
89 Convey("panics on bad email", func() { | 90 Convey("panics on bad email", func() { |
90 So(func() { | 91 So(func() { |
91 » » » » user.Testable().Login("bademail", "", false) | 92 » » » » user.GetTestable(c).Login("bademail", "", false) |
92 }, ShouldPanicLike, `mail: missing phrase`) | 93 }, ShouldPanicLike, `mail: missing phrase`) |
93 }) | 94 }) |
94 | 95 |
95 Convey("fake URLs", func() { | 96 Convey("fake URLs", func() { |
96 » » » url, err := user.LoginURL("https://funky.example.com") | 97 » » » url, err := user.LoginURL(c, "https://funky.example.com"
) |
97 So(err, ShouldBeNil) | 98 So(err, ShouldBeNil) |
98 So(url, ShouldEqual, "https://fakeapp.example.com/_ah/lo
gin?redirect=https%3A%2F%2Ffunky.example.com") | 99 So(url, ShouldEqual, "https://fakeapp.example.com/_ah/lo
gin?redirect=https%3A%2F%2Ffunky.example.com") |
99 | 100 |
100 » » » url, err = user.LogoutURL("https://funky.example.com") | 101 » » » url, err = user.LogoutURL(c, "https://funky.example.com"
) |
101 So(err, ShouldBeNil) | 102 So(err, ShouldBeNil) |
102 So(url, ShouldEqual, "https://fakeapp.example.com/_ah/lo
gout?redirect=https%3A%2F%2Ffunky.example.com") | 103 So(url, ShouldEqual, "https://fakeapp.example.com/_ah/lo
gout?redirect=https%3A%2F%2Ffunky.example.com") |
103 }) | 104 }) |
104 | 105 |
105 Convey("Some stuff is deprecated", func() { | 106 Convey("Some stuff is deprecated", func() { |
106 » » » url, err := user.LoginURLFederated("https://something",
"something") | 107 » » » url, err := user.LoginURLFederated(c, "https://something
", "something") |
107 So(err, ShouldErrLike, "LoginURLFederated is deprecated"
) | 108 So(err, ShouldErrLike, "LoginURLFederated is deprecated"
) |
108 So(url, ShouldEqual, "") | 109 So(url, ShouldEqual, "") |
109 | 110 |
110 » » » key, err := user.OAuthConsumerKey() | 111 » » » key, err := user.OAuthConsumerKey(c) |
111 So(err, ShouldErrLike, "OAuthConsumerKey is deprecated") | 112 So(err, ShouldErrLike, "OAuthConsumerKey is deprecated") |
112 So(key, ShouldEqual, "") | 113 So(key, ShouldEqual, "") |
113 }) | 114 }) |
114 | 115 |
115 }) | 116 }) |
116 } | 117 } |
OLD | NEW |