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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « impl/memory/user.go ('k') | impl/prod/user.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/user_test.go
diff --git a/impl/memory/user_test.go b/impl/memory/user_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..a49ab7c9cf7ff1afba49719df88b58e8df215778
--- /dev/null
+++ b/impl/memory/user_test.go
@@ -0,0 +1,120 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package memory
+
+import (
+ "testing"
+
+ userS "github.com/luci/gae/service/user"
+ . "github.com/luci/luci-go/common/testing/assertions"
+ . "github.com/smartystreets/goconvey/convey"
+ "golang.org/x/net/context"
+)
+
+func TestUser(t *testing.T) {
+ t.Parallel()
+
+ Convey("user", t, func() {
+ c := Use(context.Background())
+ user := userS.Get(c)
+
+ Convey("default state is anonymous", func() {
+ So(user.Current(), ShouldBeNil)
+
+ usr, err := user.CurrentOAuth("something")
+ So(err, ShouldBeNil)
+ So(usr, ShouldBeNil)
+
+ So(user.IsAdmin(), ShouldBeFalse)
+ })
+
+ Convey("can login (normal)", func() {
+ user.Testable().Login("hello@world.com", "", false)
+ So(user.Current(), ShouldResembleV, &userS.User{
+ Email: "hello@world.com",
+ AuthDomain: "world.com",
+ ID: "14628837901535854097",
+ })
+
+ usr, err := user.CurrentOAuth("scope")
+ So(usr, ShouldBeNil)
+ So(err, ShouldBeNil)
+
+ Convey("and logout", func() {
+ user.Testable().Logout()
+ So(user.Current(), ShouldBeNil)
+
+ usr, err := user.CurrentOAuth("scope")
+ So(usr, ShouldBeNil)
+ So(err, ShouldBeNil)
+ })
+ })
+
+ Convey("can be admin", func() {
+ user.Testable().Login("hello@world.com", "", true)
+ So(user.Current(), ShouldResembleV, &userS.User{
+ Email: "hello@world.com",
+ AuthDomain: "world.com",
+ ID: "14628837901535854097",
+ Admin: true,
+ })
+ So(user.IsAdmin(), ShouldBeTrue)
+ })
+
+ Convey("can login (oauth)", func() {
+ user.Testable().Login("hello@world.com", "clientID", false)
+ usr, err := user.CurrentOAuth("scope")
+ So(err, ShouldBeNil)
+ So(usr, ShouldResembleV, &userS.User{
+ Email: "hello@world.com",
+ AuthDomain: "world.com",
+ ID: "14628837901535854097",
+ ClientID: "clientID",
+ })
+
+ So(user.Current(), ShouldBeNil)
+
+ Convey("and logout", func() {
+ user.Testable().Logout()
+ So(user.Current(), ShouldBeNil)
+
+ usr, err := user.CurrentOAuth("scope")
+ So(usr, ShouldBeNil)
+ So(err, ShouldBeNil)
+ })
+ })
+
+ Convey("panics on bad email", func() {
+ So(func() {
+ user.Testable().Login("bademail", "", false)
+ }, ShouldPanicLike, `"bademail" doesn't seem to be a valid email`)
+
+ So(func() {
+ user.Testable().Login("too@many@ats.com", "", false)
+ }, ShouldPanicLike, `"too@many@ats.com" doesn't seem to be a valid email`)
+ })
+
+ Convey("fake URLs", func() {
+ url, err := user.LoginURL("https://funky.example.com")
+ So(err, ShouldBeNil)
+ So(url, ShouldEqual, "https://fakeapp.example.com/_ah/login?redirect=https%3A%2F%2Ffunky.example.com")
+
+ url, err = user.LogoutURL("https://funky.example.com")
+ So(err, ShouldBeNil)
+ So(url, ShouldEqual, "https://fakeapp.example.com/_ah/logout?redirect=https%3A%2F%2Ffunky.example.com")
+ })
+
+ Convey("Some stuff is deprecated", func() {
+ url, err := user.LoginURLFederated("https://something", "something")
+ So(err, ShouldErrLike, "LoginURLFederated is deprecated")
+ So(url, ShouldEqual, "")
+
+ key, err := user.OAuthConsumerKey()
+ So(err, ShouldErrLike, "OAuthConsumerKey is deprecated")
+ So(key, ShouldEqual, "")
+ })
+
+ })
+}
« 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