Skip to content

Commit ea0ac47

Browse files
committed
dashboard/app: fix admin checks for dev_appserver
Admin checks broke at some point for local app runs (the auth domain is overriden only in tests). Restore proper checking for dev_appserver. Fix TestUserAccessLevel to use production AuthDomain. It does not run in the context of the dev_appserver, so it can now test the actual production logic.
1 parent 1be6895 commit ea0ac47

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

dashboard/app/access.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"strings"
1212

13+
"google.golang.org/appengine/v2"
1314
db "google.golang.org/appengine/v2/datastore"
1415
"google.golang.org/appengine/v2/log"
1516
"google.golang.org/appengine/v2/user"
@@ -79,14 +80,13 @@ func accessLevel(c context.Context, r *http.Request) AccessLevel {
7980
return al
8081
}
8182

82-
// trustedAuthDomain for the test environment is "".
83-
var trustedAuthDomain = "gmail.com"
84-
8583
// userAccessLevel returns authorization flag and AccessLevel.
8684
// (True, AccessAdmin) means authorized, Admin access.
8785
// Note - authorize higher levels first.
8886
func userAccessLevel(u *user.User, wantAccess string, config *GlobalConfig) (bool, AccessLevel) {
89-
if u == nil || u.AuthDomain != trustedAuthDomain {
87+
// dev_appserver.py sets u.AuthDomain="".
88+
// Note: dev_appserver.py is used not only in tests, but also when the app is run locally.
89+
if u == nil || u.AuthDomain != "gmail.com" && !appengine.IsDevAppServer() {
9090
return false, AccessPublic
9191
}
9292
if u.Admin {

dashboard/app/access_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ const (
457457
)
458458

459459
func makeUser(a UserAuthorizationLevel) *user.User {
460-
u := &user.User{}
460+
u := &user.User{
461+
AuthDomain: "gmail.com",
462+
}
461463
switch a {
462464
case BadAuthDomain:
463465
u.AuthDomain = "public.com"

dashboard/app/app_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func init() {
3131
os.Setenv("GAE_MODULE_VERSION", "1")
3232
os.Setenv("GAE_MINOR_VERSION", "1")
3333

34-
trustedAuthDomain = "" // Devappserver environment value is "", prod value is "gmail.com".
3534
obsoleteWhatWontBeFixBisected = true
3635
notifyAboutUnsuccessfulBisections = true
3736
ensureConfigImmutability = true

0 commit comments

Comments
 (0)