| 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 "errors" | 8 "errors" |
| 9 "testing" | 9 "testing" |
| 10 "time" | 10 "time" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 // Set our archival delays. The project delay is smaller than th
e service | 34 // Set our archival delays. The project delay is smaller than th
e service |
| 35 // delay, so it should be used. | 35 // delay, so it should be used. |
| 36 env.ModServiceConfig(c, func(cfg *svcconfig.Config) { | 36 env.ModServiceConfig(c, func(cfg *svcconfig.Config) { |
| 37 cfg.Coordinator.ArchiveDelayMax = google.NewDuration(24
* time.Hour) | 37 cfg.Coordinator.ArchiveDelayMax = google.NewDuration(24
* time.Hour) |
| 38 }) | 38 }) |
| 39 env.ModProjectConfig(c, "proj-foo", func(pcfg *svcconfig.Project
Config) { | 39 env.ModProjectConfig(c, "proj-foo", func(pcfg *svcconfig.Project
Config) { |
| 40 pcfg.MaxStreamAge = google.NewDuration(time.Hour) | 40 pcfg.MaxStreamAge = google.NewDuration(time.Hour) |
| 41 }) | 41 }) |
| 42 | 42 |
| 43 // By default, the testing user is a service. |
| 44 env.JoinGroup("services") |
| 45 |
| 43 svr := New() | 46 svr := New() |
| 44 | 47 |
| 45 Convey(`Returns Forbidden error if not a service.`, func() { | 48 Convey(`Returns Forbidden error if not a service.`, func() { |
| 49 env.LeaveAllGroups() |
| 50 |
| 46 _, err := svr.RegisterStream(c, &logdog.RegisterStreamRe
quest{}) | 51 _, err := svr.RegisterStream(c, &logdog.RegisterStreamRe
quest{}) |
| 47 So(err, ShouldBeRPCPermissionDenied) | 52 So(err, ShouldBeRPCPermissionDenied) |
| 48 }) | 53 }) |
| 49 | 54 |
| 50 » » Convey(`When logged in as a service`, func() { | 55 » » Convey(`When registering a testing log sream, "testing/+/foo/bar
"`, func() { |
| 51 » » » env.JoinGroup("services") | |
| 52 | |
| 53 tls := ct.MakeStream(c, "proj-foo", "testing/+/foo/bar") | 56 tls := ct.MakeStream(c, "proj-foo", "testing/+/foo/bar") |
| 54 | 57 |
| 55 » » » Convey(`A stream registration request for "testing/+/foo
/bar"`, func() { | 58 » » » req := logdog.RegisterStreamRequest{ |
| 56 » » » » req := logdog.RegisterStreamRequest{ | 59 » » » » Project: string(tls.Project), |
| 57 » » » » » Project: string(tls.Project), | 60 » » » » Secret: tls.Prefix.Secret, |
| 58 » » » » » Secret: tls.Prefix.Secret, | 61 » » » » ProtoVersion: logpb.Version, |
| 59 » » » » » ProtoVersion: logpb.Version, | 62 » » » » Desc: tls.DescBytes(), |
| 60 » » » » » Desc: tls.DescBytes(), | 63 » » » } |
| 61 » » » » } | 64 |
| 65 » » » Convey(`Returns FailedPrecondition when the Prefix is no
t registered.`, func() { |
| 66 » » » » _, err := svr.RegisterStream(c, &req) |
| 67 » » » » So(err, ShouldBeRPCFailedPrecondition) |
| 68 » » » }) |
| 69 |
| 70 » » » Convey(`When the Prefix is registered`, func() { |
| 71 » » » » tls.WithProjectNamespace(c, func(c context.Conte
xt) { |
| 72 » » » » » if err := ds.Get(c).Put(tls.Prefix); err
!= nil { |
| 73 » » » » » » panic(err) |
| 74 » » » » » } |
| 75 » » » » }) |
| 62 | 76 |
| 63 expResp := &logdog.RegisterStreamResponse{ | 77 expResp := &logdog.RegisterStreamResponse{ |
| 64 Id: string(tls.Stream.ID), | 78 Id: string(tls.Stream.ID), |
| 65 State: &logdog.LogStreamState{ | 79 State: &logdog.LogStreamState{ |
| 66 Secret: tls.Prefix.Secret
, | 80 Secret: tls.Prefix.Secret
, |
| 67 ProtoVersion: logpb.Version, | 81 ProtoVersion: logpb.Version, |
| 68 TerminalIndex: -1, | 82 TerminalIndex: -1, |
| 69 }, | 83 }, |
| 70 } | 84 } |
| 71 | 85 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 env.Clock.Set(created.Ad
d(time.Hour)) // 1 hour after initial registration. | 152 env.Clock.Set(created.Ad
d(time.Hour)) // 1 hour after initial registration. |
| 139 env.DrainTumbleAll(c) | 153 env.DrainTumbleAll(c) |
| 140 | 154 |
| 141 So(env.ArchivalPublisher
.Hashes(), ShouldResemble, []string{string(tls.Stream.ID)}) | 155 So(env.ArchivalPublisher
.Hashes(), ShouldResemble, []string{string(tls.Stream.ID)}) |
| 142 }) | 156 }) |
| 143 }) | 157 }) |
| 144 | 158 |
| 145 Convey(`Will not re-register if secrets
don't match.`, func() { | 159 Convey(`Will not re-register if secrets
don't match.`, func() { |
| 146 req.Secret[0] = 0xAB | 160 req.Secret[0] = 0xAB |
| 147 _, err := svr.RegisterStream(c,
&req) | 161 _, err := svr.RegisterStream(c,
&req) |
| 148 » » » » » » So(err, ShouldBeRPCAlreadyExists
, "Log prefix is already registered") | 162 » » » » » » So(err, ShouldBeRPCInvalidArgume
nt, "invalid secret") |
| 149 }) | 163 }) |
| 150 }) | 164 }) |
| 151 | 165 |
| 152 Convey(`Will schedule the correct archival expir
ation delay`, func() { | 166 Convey(`Will schedule the correct archival expir
ation delay`, func() { |
| 153 Convey(`When there is no project config
delay.`, func() { | 167 Convey(`When there is no project config
delay.`, func() { |
| 154 env.ModProjectConfig(c, "proj-fo
o", func(pcfg *svcconfig.ProjectConfig) { | 168 env.ModProjectConfig(c, "proj-fo
o", func(pcfg *svcconfig.ProjectConfig) { |
| 155 pcfg.MaxStreamAge = nil | 169 pcfg.MaxStreamAge = nil |
| 156 }) | 170 }) |
| 157 | 171 |
| 158 _, err := svr.RegisterStream(c,
&req) | 172 _, err := svr.RegisterStream(c,
&req) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 _, err := svr.RegisterStream(c,
&req) | 225 _, err := svr.RegisterStream(c,
&req) |
| 212 So(err, ShouldBeRPCInvalidArgume
nt, "Unrecognized protobuf version") | 226 So(err, ShouldBeRPCInvalidArgume
nt, "Unrecognized protobuf version") |
| 213 }) | 227 }) |
| 214 | 228 |
| 215 Convey(`Will not register a stream with
an unknown protobuf version.`, func() { | 229 Convey(`Will not register a stream with
an unknown protobuf version.`, func() { |
| 216 req.ProtoVersion = "unknown" | 230 req.ProtoVersion = "unknown" |
| 217 _, err := svr.RegisterStream(c,
&req) | 231 _, err := svr.RegisterStream(c,
&req) |
| 218 So(err, ShouldBeRPCInvalidArgume
nt, "Unrecognized protobuf version") | 232 So(err, ShouldBeRPCInvalidArgume
nt, "Unrecognized protobuf version") |
| 219 }) | 233 }) |
| 220 | 234 |
| 221 Convey(`Will not register a wrong-sized
secret.`, func() { | |
| 222 req.Secret = nil | |
| 223 _, err := svr.RegisterStream(c,
&req) | |
| 224 So(err, ShouldBeRPCInvalidArgume
nt, "Invalid prefix secret") | |
| 225 }) | |
| 226 | |
| 227 Convey(`Will not register with an empty
descriptor.`, func() { | 235 Convey(`Will not register with an empty
descriptor.`, func() { |
| 228 req.Desc = nil | 236 req.Desc = nil |
| 229 | 237 |
| 230 _, err := svr.RegisterStream(c,
&req) | 238 _, err := svr.RegisterStream(c,
&req) |
| 231 So(err, ShouldBeRPCInvalidArgume
nt, "Invalid log stream descriptor") | 239 So(err, ShouldBeRPCInvalidArgume
nt, "Invalid log stream descriptor") |
| 232 }) | 240 }) |
| 233 | 241 |
| 234 Convey(`Will not register if the descrip
tor doesn't validate.`, func() { | 242 Convey(`Will not register if the descrip
tor doesn't validate.`, func() { |
| 235 tls.Desc.ContentType = "" | 243 tls.Desc.ContentType = "" |
| 236 So(tls.Desc.Validate(true), Shou
ldNotBeNil) | 244 So(tls.Desc.Validate(true), Shou
ldNotBeNil) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 260 fb.BreakFeatures(errors.New("tes
t error"), "PutMulti") | 268 fb.BreakFeatures(errors.New("tes
t error"), "PutMulti") |
| 261 | 269 |
| 262 _, err := rsm.RollForward(c) | 270 _, err := rsm.RollForward(c) |
| 263 So(err, ShouldBeRPCInternal) | 271 So(err, ShouldBeRPCInternal) |
| 264 }) | 272 }) |
| 265 }) | 273 }) |
| 266 }) | 274 }) |
| 267 }) | 275 }) |
| 268 }) | 276 }) |
| 269 } | 277 } |
| OLD | NEW |