| OLD | NEW |
| (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 settings | |
| 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 := Update(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 } | |
| OLD | NEW |