Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: appengine/logdog/coordinator/endpoints/services/registerStream_test.go

Issue 1910923002: LogDog: Add project namespace to service endpoint. (Closed) Base URL: https://github.com/luci/luci-go@logdog-project-coordinator-backend
Patch Set: Updates, works. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 15 matching lines...) Expand all
26 ) 26 )
27 27
28 func TestRegisterStream(t *testing.T) { 28 func TestRegisterStream(t *testing.T) {
29 t.Parallel() 29 t.Parallel()
30 30
31 Convey(`With a testing configuration`, t, func() { 31 Convey(`With a testing configuration`, t, func() {
32 tt := tumble.NewTesting() 32 tt := tumble.NewTesting()
33 c := tt.Context() 33 c := tt.Context()
34 ds.Get(c).Testable().Consistent(true) 34 ds.Get(c).Testable().Consistent(true)
35 35
36 fs := authtest.FakeState{}
37 c = auth.WithState(c, &fs)
38
36 svcStub := ct.Services{} 39 svcStub := ct.Services{}
37 svcStub.InitConfig() 40 svcStub.InitConfig()
38 svcStub.ServiceConfig.Coordinator.ServiceAuthGroup = "test-servi ces" 41 svcStub.ServiceConfig.Coordinator.ServiceAuthGroup = "test-servi ces"
39 c = coordinator.WithServices(c, &svcStub) 42 c = coordinator.WithServices(c, &svcStub)
40 43
41 svr := New() 44 svr := New()
42 45
43 fs := authtest.FakeState{}
44 c = auth.WithState(c, &fs)
45
46 Convey(`Returns Forbidden error if not a service.`, func() { 46 Convey(`Returns Forbidden error if not a service.`, func() {
47 _, err := svr.RegisterStream(c, &logdog.RegisterStreamRe quest{}) 47 _, err := svr.RegisterStream(c, &logdog.RegisterStreamRe quest{})
48 So(err, ShouldBeRPCPermissionDenied) 48 So(err, ShouldBeRPCPermissionDenied)
49 }) 49 })
50 50
51 Convey(`When logged in as a service`, func() { 51 Convey(`When logged in as a service`, func() {
52 fs.IdentityGroups = []string{"test-services"} 52 fs.IdentityGroups = []string{"test-services"}
53 53
54 desc := ct.TestLogStreamDescriptor(c, "foo/bar") 54 desc := ct.TestLogStreamDescriptor(c, "foo/bar")
55 » » » secret := bytes.Repeat([]byte{0xAA}, types.StreamSecretL ength) 55 » » » secret := bytes.Repeat([]byte{0xAA}, types.PrefixSecretL ength)
56 56
57 Convey(`A stream registration request for "testing/+/foo /bar"`, func() { 57 Convey(`A stream registration request for "testing/+/foo /bar"`, func() {
58 req := logdog.RegisterStreamRequest{ 58 req := logdog.RegisterStreamRequest{
59 Path: "testing/+/foo/bar", 59 Path: "testing/+/foo/bar",
60 Secret: secret, 60 Secret: secret,
61 ProtoVersion: logpb.Version, 61 ProtoVersion: logpb.Version,
62 Desc: desc, 62 Desc: desc,
63 } 63 }
64 64
65 expResp := &logdog.RegisterStreamResponse{ 65 expResp := &logdog.RegisterStreamResponse{
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 Convey(`Will not register a stream with an unknown protobuf version.`, func() { 151 Convey(`Will not register a stream with an unknown protobuf version.`, func() {
152 req.ProtoVersion = "unknown" 152 req.ProtoVersion = "unknown"
153 _, err := svr.RegisterStream(c, &req) 153 _, err := svr.RegisterStream(c, &req)
154 So(err, ShouldBeRPCInvalidArgume nt, "Unrecognized protobuf version.") 154 So(err, ShouldBeRPCInvalidArgume nt, "Unrecognized protobuf version.")
155 }) 155 })
156 156
157 Convey(`Will not register a wrong-sized secret.`, func() { 157 Convey(`Will not register a wrong-sized secret.`, func() {
158 req.Secret = nil 158 req.Secret = nil
159 _, err := svr.RegisterStream(c, &req) 159 _, err := svr.RegisterStream(c, &req)
160 » » » » » » So(err, ShouldBeRPCInvalidArgume nt, "Invalid secret length") 160 » » » » » » So(err, ShouldBeRPCInvalidArgume nt, "Invalid prefix secret")
161 }) 161 })
162 162
163 Convey(`Will not register with an empty descriptor.`, func() { 163 Convey(`Will not register with an empty descriptor.`, func() {
164 req.Desc = nil 164 req.Desc = nil
165 _, err := svr.RegisterStream(c, &req) 165 _, err := svr.RegisterStream(c, &req)
166 So(err, ShouldBeRPCInvalidArgume nt, "Missing log stream descriptor.") 166 So(err, ShouldBeRPCInvalidArgume nt, "Missing log stream descriptor.")
167 }) 167 })
168 168
169 Convey(`Will not register if the descrip tor's Prefix doesn't match.`, func() { 169 Convey(`Will not register if the descrip tor's Prefix doesn't match.`, func() {
170 req.Desc.Prefix = "different" 170 req.Desc.Prefix = "different"
(...skipping 12 matching lines...) Expand all
183 So(req.Desc.Validate(true), Shou ldNotBeNil) 183 So(req.Desc.Validate(true), Shou ldNotBeNil)
184 184
185 _, err := svr.RegisterStream(c, &req) 185 _, err := svr.RegisterStream(c, &req)
186 So(err, ShouldBeRPCInvalidArgume nt, "Invalid log stream descriptor") 186 So(err, ShouldBeRPCInvalidArgume nt, "Invalid log stream descriptor")
187 }) 187 })
188 }) 188 })
189 }) 189 })
190 }) 190 })
191 }) 191 })
192 } 192 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698