| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 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 coordinator | 5 package coordinator |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "testing" | 10 "testing" |
| 11 | 11 |
| 12 "github.com/luci/gae/impl/memory" | 12 "github.com/luci/gae/impl/memory" |
| 13 luciConfig "github.com/luci/luci-go/common/config" | 13 luciConfig "github.com/luci/luci-go/common/config" |
| 14 "github.com/luci/luci-go/logdog/api/config/svcconfig" | 14 "github.com/luci/luci-go/logdog/api/config/svcconfig" |
| 15 "github.com/luci/luci-go/logdog/appengine/coordinator/config" | 15 "github.com/luci/luci-go/logdog/appengine/coordinator/config" |
| 16 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 16 "github.com/luci/luci-go/server/auth" | 17 "github.com/luci/luci-go/server/auth" |
| 17 "github.com/luci/luci-go/server/auth/authtest" | 18 "github.com/luci/luci-go/server/auth/authtest" |
| 18 "github.com/luci/luci-go/server/auth/identity" | 19 "github.com/luci/luci-go/server/auth/identity" |
| 19 | 20 |
| 20 "golang.org/x/net/context" | 21 "golang.org/x/net/context" |
| 21 | 22 |
| 22 . "github.com/luci/luci-go/common/testing/assertions" | 23 . "github.com/luci/luci-go/common/testing/assertions" |
| 23 . "github.com/smartystreets/goconvey/convey" | 24 . "github.com/smartystreets/goconvey/convey" |
| 24 ) | 25 ) |
| 25 | 26 |
| 26 type testServices struct { | 27 type testServices struct { |
| 27 Services | 28 Services |
| 28 | 29 |
| 29 configErr error | 30 configErr error |
| 30 » configs map[luciConfig.ProjectName]*svcconfig.ProjectConfig | 31 » configs map[cfgtypes.ProjectName]*svcconfig.ProjectConfig |
| 31 } | 32 } |
| 32 | 33 |
| 33 func (s *testServices) ProjectConfig(c context.Context, project luciConfig.Proje
ctName) (*svcconfig.ProjectConfig, error) { | 34 func (s *testServices) ProjectConfig(c context.Context, project cfgtypes.Project
Name) (*svcconfig.ProjectConfig, error) { |
| 34 if err := s.configErr; err != nil { | 35 if err := s.configErr; err != nil { |
| 35 return nil, err | 36 return nil, err |
| 36 } | 37 } |
| 37 | 38 |
| 38 cfg, ok := s.configs[project] | 39 cfg, ok := s.configs[project] |
| 39 switch { | 40 switch { |
| 40 case !ok: | 41 case !ok: |
| 41 return nil, luciConfig.ErrNoConfig | 42 return nil, luciConfig.ErrNoConfig |
| 42 | 43 |
| 43 case cfg == nil: | 44 case cfg == nil: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 56 c = memory.Use(c) | 57 c = memory.Use(c) |
| 57 | 58 |
| 58 // Fake authentication state. | 59 // Fake authentication state. |
| 59 as := authtest.FakeState{ | 60 as := authtest.FakeState{ |
| 60 IdentityGroups: []string{"all"}, | 61 IdentityGroups: []string{"all"}, |
| 61 } | 62 } |
| 62 c = auth.WithState(c, &as) | 63 c = auth.WithState(c, &as) |
| 63 | 64 |
| 64 // Fake service with fake project configs. | 65 // Fake service with fake project configs. |
| 65 svc := testServices{ | 66 svc := testServices{ |
| 66 » » » configs: map[luciConfig.ProjectName]*svcconfig.ProjectCo
nfig{ | 67 » » » configs: map[cfgtypes.ProjectName]*svcconfig.ProjectConf
ig{ |
| 67 "all-access": { | 68 "all-access": { |
| 68 ReaderAuthGroups: []string{"all"}, | 69 ReaderAuthGroups: []string{"all"}, |
| 69 WriterAuthGroups: []string{"all"}, | 70 WriterAuthGroups: []string{"all"}, |
| 70 }, | 71 }, |
| 71 "exclusive-access": { | 72 "exclusive-access": { |
| 72 ReaderAuthGroups: []string{"auth"}, | 73 ReaderAuthGroups: []string{"auth"}, |
| 73 WriterAuthGroups: []string{"auth"}, | 74 WriterAuthGroups: []string{"auth"}, |
| 74 }, | 75 }, |
| 75 }, | 76 }, |
| 76 } | 77 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 So(WithProjectNamespace(&c, "exclusive-a
ccess", tc.access), ShouldBeRPCUnauthenticated) | 154 So(WithProjectNamespace(&c, "exclusive-a
ccess", tc.access), ShouldBeRPCUnauthenticated) |
| 154 }) | 155 }) |
| 155 | 156 |
| 156 Convey(`Will fail to access non-existent project
with Unauthenticated.`, func() { | 157 Convey(`Will fail to access non-existent project
with Unauthenticated.`, func() { |
| 157 So(WithProjectNamespace(&c, "does-not-ex
ist", tc.access), ShouldBeRPCUnauthenticated) | 158 So(WithProjectNamespace(&c, "does-not-ex
ist", tc.access), ShouldBeRPCUnauthenticated) |
| 158 }) | 159 }) |
| 159 | 160 |
| 160 Convey(`When config service returns an unexpecte
d error`, func() { | 161 Convey(`When config service returns an unexpecte
d error`, func() { |
| 161 svc.configErr = errors.New("misc") | 162 svc.configErr = errors.New("misc") |
| 162 | 163 |
| 163 » » » » » for _, proj := range []luciConfig.Projec
tName{"all-access", "exclusive-access", "does-not-exist"} { | 164 » » » » » for _, proj := range []cfgtypes.ProjectN
ame{"all-access", "exclusive-access", "does-not-exist"} { |
| 164 Convey(fmt.Sprintf(`Will fail to
access %q with Internal.`, proj), func() { | 165 Convey(fmt.Sprintf(`Will fail to
access %q with Internal.`, proj), func() { |
| 165 So(WithProjectNamespace(
&c, "all-access", tc.access), ShouldBeRPCInternal) | 166 So(WithProjectNamespace(
&c, "all-access", tc.access), ShouldBeRPCInternal) |
| 166 }) | 167 }) |
| 167 } | 168 } |
| 168 }) | 169 }) |
| 169 }) | 170 }) |
| 170 } | 171 } |
| 171 }) | 172 }) |
| 172 } | 173 } |
| OLD | NEW |