| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package services | 5 package services |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "testing" | 8 "testing" |
| 9 | 9 |
| 10 "github.com/luci/gae/impl/memory" | 10 "github.com/luci/gae/impl/memory" |
| 11 "github.com/luci/luci-go/appengine/logdog/coordinator" |
| 11 ct "github.com/luci/luci-go/appengine/logdog/coordinator/coordinatorTest
" | 12 ct "github.com/luci/luci-go/appengine/logdog/coordinator/coordinatorTest
" |
| 12 "github.com/luci/luci-go/common/clock/testclock" | 13 "github.com/luci/luci-go/common/clock/testclock" |
| 13 "github.com/luci/luci-go/common/proto/logdog/svcconfig" | |
| 14 "github.com/luci/luci-go/server/auth" | 14 "github.com/luci/luci-go/server/auth" |
| 15 "github.com/luci/luci-go/server/auth/authtest" | 15 "github.com/luci/luci-go/server/auth/authtest" |
| 16 "golang.org/x/net/context" | 16 "golang.org/x/net/context" |
| 17 | 17 |
| 18 . "github.com/luci/luci-go/common/testing/assertions" | 18 . "github.com/luci/luci-go/common/testing/assertions" |
| 19 . "github.com/smartystreets/goconvey/convey" | 19 . "github.com/smartystreets/goconvey/convey" |
| 20 ) | 20 ) |
| 21 | 21 |
| 22 func TestServiceAuth(t *testing.T) { | 22 func TestServiceAuth(t *testing.T) { |
| 23 t.Parallel() | 23 t.Parallel() |
| 24 | 24 |
| 25 Convey(`With a testing configuration`, t, func() { | 25 Convey(`With a testing configuration`, t, func() { |
| 26 c, _ := testclock.UseTime(context.Background(), testclock.TestTi
meLocal) | 26 c, _ := testclock.UseTime(context.Background(), testclock.TestTi
meLocal) |
| 27 c = memory.Use(c) | 27 c = memory.Use(c) |
| 28 | 28 |
| 29 svcStub := ct.Services{} |
| 30 |
| 31 be := Server{ |
| 32 ServiceBase: coordinator.ServiceBase{&svcStub}, |
| 33 } |
| 34 svc := be.GetServices() |
| 35 |
| 29 c = auth.SetAuthenticator(c, auth.Authenticator{&authtest.FakeAu
th{}}) | 36 c = auth.SetAuthenticator(c, auth.Authenticator{&authtest.FakeAu
th{}}) |
| 30 Convey(`Will reject all traffic if no configuration is present.`
, func() { | 37 Convey(`Will reject all traffic if no configuration is present.`
, func() { |
| 31 » » » So(Auth(c), ShouldBeRPCInternal) | 38 » » » So(Auth(c, svc), ShouldBeRPCInternal) |
| 32 }) | 39 }) |
| 33 | 40 |
| 34 Convey(`With an application config installed`, func() { | 41 Convey(`With an application config installed`, func() { |
| 35 » » » c := ct.UseConfig(c, &svcconfig.Coordinator{ | 42 » » » svcStub.InitConfig() |
| 36 » » » » ServiceAuthGroup: "test-services", | 43 » » » svcStub.ServiceConfig.Coordinator.ServiceAuthGroup = "te
st-services" |
| 37 » » » }) | |
| 38 | 44 |
| 39 Convey(`Will reject users if there is an authentication
error (no state).`, func() { | 45 Convey(`Will reject users if there is an authentication
error (no state).`, func() { |
| 40 » » » » So(Auth(c), ShouldBeRPCInternal) | 46 » » » » So(Auth(c, svc), ShouldBeRPCInternal) |
| 41 }) | 47 }) |
| 42 | 48 |
| 43 Convey(`With an authentication state`, func() { | 49 Convey(`With an authentication state`, func() { |
| 44 fs := authtest.FakeState{} | 50 fs := authtest.FakeState{} |
| 45 c = auth.WithState(c, &fs) | 51 c = auth.WithState(c, &fs) |
| 46 | 52 |
| 47 Convey(`Will reject users who are not logged in.
`, func() { | 53 Convey(`Will reject users who are not logged in.
`, func() { |
| 48 » » » » » So(Auth(c), ShouldBeRPCPermissionDenied) | 54 » » » » » So(Auth(c, svc), ShouldBeRPCPermissionDe
nied) |
| 49 }) | 55 }) |
| 50 | 56 |
| 51 Convey(`When a user is logged in`, func() { | 57 Convey(`When a user is logged in`, func() { |
| 52 fs.Identity = "user:user@example.com" | 58 fs.Identity = "user:user@example.com" |
| 53 | 59 |
| 54 Convey(`Will reject users who are not me
mbers of the service group.`, func() { | 60 Convey(`Will reject users who are not me
mbers of the service group.`, func() { |
| 55 » » » » » » So(Auth(c), ShouldBeRPCPermissio
nDenied) | 61 » » » » » » So(Auth(c, svc), ShouldBeRPCPerm
issionDenied) |
| 56 }) | 62 }) |
| 57 | 63 |
| 58 Convey(`Will allow users who are members
of the service group.`, func() { | 64 Convey(`Will allow users who are members
of the service group.`, func() { |
| 59 fs.IdentityGroups = []string{"te
st-services"} | 65 fs.IdentityGroups = []string{"te
st-services"} |
| 60 » » » » » » So(Auth(c), ShouldBeNil) | 66 » » » » » » So(Auth(c, svc), ShouldBeNil) |
| 61 }) | 67 }) |
| 62 }) | 68 }) |
| 63 }) | 69 }) |
| 64 }) | 70 }) |
| 65 }) | 71 }) |
| 66 } | 72 } |
| OLD | NEW |