| 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 "bytes" | 8 "bytes" |
| 9 "errors" | 9 "errors" |
| 10 "testing" | 10 "testing" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 Convey(`With a testing configuration`, t, func() { | 35 Convey(`With a testing configuration`, t, func() { |
| 36 tt := &tumble.Testing{} | 36 tt := &tumble.Testing{} |
| 37 c := tt.Context() | 37 c := tt.Context() |
| 38 tc := clock.Get(c).(testclock.TestClock) | 38 tc := clock.Get(c).(testclock.TestClock) |
| 39 | 39 |
| 40 // Add Tumble delayed mutation index. | 40 // Add Tumble delayed mutation index. |
| 41 tt.EnableDelayedMutations(c) | 41 tt.EnableDelayedMutations(c) |
| 42 ds.Get(c).Testable().Consistent(true) | 42 ds.Get(c).Testable().Consistent(true) |
| 43 | 43 |
| 44 fs := authtest.FakeState{} |
| 45 c = auth.WithState(c, &fs) |
| 46 |
| 44 var tap ct.ArchivalPublisher | 47 var tap ct.ArchivalPublisher |
| 45 svcStub := ct.Services{ | 48 svcStub := ct.Services{ |
| 46 AP: func() (coordinator.ArchivalPublisher, error) { | 49 AP: func() (coordinator.ArchivalPublisher, error) { |
| 47 return &tap, nil | 50 return &tap, nil |
| 48 }, | 51 }, |
| 49 } | 52 } |
| 50 svcStub.InitConfig() | 53 svcStub.InitConfig() |
| 51 svcStub.ServiceConfig.Coordinator.ServiceAuthGroup = "test-servi
ces" | 54 svcStub.ServiceConfig.Coordinator.ServiceAuthGroup = "test-servi
ces" |
| 52 svcStub.ServiceConfig.Coordinator.ArchiveDelayMax = google.NewDu
ration(time.Hour) | 55 svcStub.ServiceConfig.Coordinator.ArchiveDelayMax = google.NewDu
ration(time.Hour) |
| 53 c = coordinator.WithServices(c, &svcStub) | 56 c = coordinator.WithServices(c, &svcStub) |
| 54 | 57 |
| 55 svr := New() | 58 svr := New() |
| 56 | 59 |
| 57 fs := authtest.FakeState{} | |
| 58 c = auth.WithState(c, &fs) | |
| 59 | |
| 60 Convey(`Returns Forbidden error if not a service.`, func() { | 60 Convey(`Returns Forbidden error if not a service.`, func() { |
| 61 _, err := svr.RegisterStream(c, &logdog.RegisterStreamRe
quest{}) | 61 _, err := svr.RegisterStream(c, &logdog.RegisterStreamRe
quest{}) |
| 62 So(err, ShouldBeRPCPermissionDenied) | 62 So(err, ShouldBeRPCPermissionDenied) |
| 63 }) | 63 }) |
| 64 | 64 |
| 65 Convey(`When logged in as a service`, func() { | 65 Convey(`When logged in as a service`, func() { |
| 66 fs.IdentityGroups = []string{"test-services"} | 66 fs.IdentityGroups = []string{"test-services"} |
| 67 | 67 |
| 68 desc := ct.TestLogStreamDescriptor(c, "foo/bar") | 68 desc := ct.TestLogStreamDescriptor(c, "foo/bar") |
| 69 » » » secret := bytes.Repeat([]byte{0xAA}, types.StreamSecretL
ength) | 69 » » » secret := bytes.Repeat([]byte{0xAA}, types.PrefixSecretL
ength) |
| 70 | 70 |
| 71 Convey(`A stream registration request for "testing/+/foo
/bar"`, func() { | 71 Convey(`A stream registration request for "testing/+/foo
/bar"`, func() { |
| 72 req := logdog.RegisterStreamRequest{ | 72 req := logdog.RegisterStreamRequest{ |
| 73 Path: "testing/+/foo/bar", | 73 Path: "testing/+/foo/bar", |
| 74 Secret: secret, | 74 Secret: secret, |
| 75 ProtoVersion: logpb.Version, | 75 ProtoVersion: logpb.Version, |
| 76 Desc: desc, | 76 Desc: desc, |
| 77 } | 77 } |
| 78 | 78 |
| 79 expResp := &logdog.RegisterStreamResponse{ | 79 expResp := &logdog.RegisterStreamResponse{ |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 Convey(`Will not register a stream with
an unknown protobuf version.`, func() { | 190 Convey(`Will not register a stream with
an unknown protobuf version.`, func() { |
| 191 req.ProtoVersion = "unknown" | 191 req.ProtoVersion = "unknown" |
| 192 _, err := svr.RegisterStream(c,
&req) | 192 _, err := svr.RegisterStream(c,
&req) |
| 193 So(err, ShouldBeRPCInvalidArgume
nt, "Unrecognized protobuf version.") | 193 So(err, ShouldBeRPCInvalidArgume
nt, "Unrecognized protobuf version.") |
| 194 }) | 194 }) |
| 195 | 195 |
| 196 Convey(`Will not register a wrong-sized
secret.`, func() { | 196 Convey(`Will not register a wrong-sized
secret.`, func() { |
| 197 req.Secret = nil | 197 req.Secret = nil |
| 198 _, err := svr.RegisterStream(c,
&req) | 198 _, err := svr.RegisterStream(c,
&req) |
| 199 » » » » » » So(err, ShouldBeRPCInvalidArgume
nt, "Invalid secret length") | 199 » » » » » » So(err, ShouldBeRPCInvalidArgume
nt, "Invalid prefix secret") |
| 200 }) | 200 }) |
| 201 | 201 |
| 202 Convey(`Will not register with an empty
descriptor.`, func() { | 202 Convey(`Will not register with an empty
descriptor.`, func() { |
| 203 req.Desc = nil | 203 req.Desc = nil |
| 204 _, err := svr.RegisterStream(c,
&req) | 204 _, err := svr.RegisterStream(c,
&req) |
| 205 So(err, ShouldBeRPCInvalidArgume
nt, "Missing log stream descriptor.") | 205 So(err, ShouldBeRPCInvalidArgume
nt, "Missing log stream descriptor.") |
| 206 }) | 206 }) |
| 207 | 207 |
| 208 Convey(`Will not register if the descrip
tor's Prefix doesn't match.`, func() { | 208 Convey(`Will not register if the descrip
tor's Prefix doesn't match.`, func() { |
| 209 req.Desc.Prefix = "different" | 209 req.Desc.Prefix = "different" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 222 So(req.Desc.Validate(true), Shou
ldNotBeNil) | 222 So(req.Desc.Validate(true), Shou
ldNotBeNil) |
| 223 | 223 |
| 224 _, err := svr.RegisterStream(c,
&req) | 224 _, err := svr.RegisterStream(c,
&req) |
| 225 So(err, ShouldBeRPCInvalidArgume
nt, "Invalid log stream descriptor") | 225 So(err, ShouldBeRPCInvalidArgume
nt, "Invalid log stream descriptor") |
| 226 }) | 226 }) |
| 227 }) | 227 }) |
| 228 }) | 228 }) |
| 229 }) | 229 }) |
| 230 }) | 230 }) |
| 231 } | 231 } |
| OLD | NEW |