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

Side by Side Diff: milo/appengine/common/acl_test.go

Issue 2949783002: [milo] appengine/* -> * (Closed)
Patch Set: rebase Created 3 years, 6 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 | « milo/appengine/common/acl.go ('k') | milo/appengine/common/config.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 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package common
6
7 import (
8 "testing"
9
10 "github.com/luci/gae/impl/memory"
11 memcfg "github.com/luci/luci-go/common/config/impl/memory"
12 "github.com/luci/luci-go/common/logging/gologger"
13 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig "
14 "github.com/luci/luci-go/server/auth"
15 "github.com/luci/luci-go/server/auth/authtest"
16 "github.com/luci/luci-go/server/auth/identity"
17 "golang.org/x/net/context"
18
19 . "github.com/smartystreets/goconvey/convey"
20 )
21
22 func TestACL(t *testing.T) {
23 t.Parallel()
24
25 Convey("Test Environment", t, func() {
26 c := memory.UseWithAppID(context.Background(), "dev~luci-milo")
27 c = gologger.StdConfig.Use(c)
28
29 Convey("Set up projects", func() {
30 c = testconfig.WithCommonClient(c, memcfg.New(aclConfgs) )
31 err := UpdateProjectConfigs(c)
32 So(err, ShouldBeNil)
33
34 Convey("Anon wants to...", func() {
35 c = auth.WithState(c, &authtest.FakeState{
36 Identity: identity.AnonymousIdenti ty,
37 IdentityGroups: []string{"all"},
38 })
39 Convey("Read public project", func() {
40 ok, err := IsAllowed(c, "opensource")
41 So(ok, ShouldEqual, true)
42 So(err, ShouldBeNil)
43 })
44 Convey("Read private project", func() {
45 ok, err := IsAllowed(c, "secret")
46 So(ok, ShouldEqual, false)
47 So(err, ShouldBeNil)
48 })
49
50 })
51 Convey("alicebob@google.com wants to...", func() {
52 c = auth.WithState(c, &authtest.FakeState{
53 Identity: "user:alicebob@google.co m",
54 IdentityGroups: []string{"googlers", "al l"},
55 })
56 Convey("Read private project", func() {
57 ok, err := IsAllowed(c, "secret")
58 So(ok, ShouldEqual, true)
59 So(err, ShouldBeNil)
60 })
61 })
62
63 Convey("eve@notgoogle.com wants to...", func() {
64 c = auth.WithState(c, &authtest.FakeState{
65 Identity: "user:eve@notgoogle.com" ,
66 IdentityGroups: []string{"all"},
67 })
68 Convey("Read public project", func() {
69 ok, err := IsAllowed(c, "opensource")
70 So(ok, ShouldEqual, true)
71 So(err, ShouldBeNil)
72 })
73 Convey("Read private project", func() {
74 ok, err := IsAllowed(c, "secret")
75 So(ok, ShouldEqual, false)
76 So(err, ShouldBeNil)
77 })
78 })
79 })
80 })
81 }
82
83 var secretProjectCfg = `
84 name: "secret"
85 access: "group:googlers"
86 `
87
88 var publicProjectCfg = `
89 name: "opensource"
90 access: "group:all"
91 `
92
93 var aclConfgs = map[string]memcfg.ConfigSet{
94 "projects/secret": {
95 "project.cfg": secretProjectCfg,
96 },
97 "projects/opensource": {
98 "project.cfg": publicProjectCfg,
99 },
100 }
OLDNEW
« no previous file with comments | « milo/appengine/common/acl.go ('k') | milo/appengine/common/config.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698