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

Side by Side Diff: scheduler/appengine/catalog/catalog_test.go

Issue 2986033003: [scheduler]: ACLs phase 1 - per Job ACL specification and enforcement. (Closed)
Patch Set: Review. Created 3 years, 4 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
« no previous file with comments | « scheduler/appengine/catalog/catalog.go ('k') | scheduler/appengine/engine/engine.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. 1 // Copyright 2015 The LUCI Authors.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 package catalog 15 package catalog
16 16
17 import ( 17 import (
18 "errors" 18 "errors"
19 "testing" 19 "testing"
20 20
21 "github.com/golang/protobuf/proto" 21 "github.com/golang/protobuf/proto"
22 "golang.org/x/net/context" 22 "golang.org/x/net/context"
23 "google.golang.org/api/pubsub/v1" 23 "google.golang.org/api/pubsub/v1"
24 24
25 memcfg "github.com/luci/luci-go/common/config/impl/memory" 25 memcfg "github.com/luci/luci-go/common/config/impl/memory"
26 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig " 26 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig "
27 27
28 "github.com/luci/luci-go/scheduler/appengine/acl"
28 "github.com/luci/luci-go/scheduler/appengine/messages" 29 "github.com/luci/luci-go/scheduler/appengine/messages"
29 "github.com/luci/luci-go/scheduler/appengine/task" 30 "github.com/luci/luci-go/scheduler/appengine/task"
30 31
31 . "github.com/luci/luci-go/common/testing/assertions" 32 . "github.com/luci/luci-go/common/testing/assertions"
32 . "github.com/smartystreets/goconvey/convey" 33 . "github.com/smartystreets/goconvey/convey"
33 ) 34 )
34 35
35 func TestRegisterTaskManagerAndFriends(t *testing.T) { 36 func TestRegisterTaskManagerAndFriends(t *testing.T) {
36 Convey("RegisterTaskManager works", t, func() { 37 Convey("RegisterTaskManager works", t, func() {
37 c := New("scheduler.cfg") 38 c := New("scheduler.cfg")
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 So(err, ShouldBeNil) 200 So(err, ShouldBeNil)
200 So(projects, ShouldResemble, []string{"broken", "project 1", "project2"}) 201 So(projects, ShouldResemble, []string{"broken", "project 1", "project2"})
201 }) 202 })
202 203
203 Convey("GetProjectJobs works", func() { 204 Convey("GetProjectJobs works", func() {
204 defs, err := cat.GetProjectJobs(ctx, "project1") 205 defs, err := cat.GetProjectJobs(ctx, "project1")
205 So(err, ShouldBeNil) 206 So(err, ShouldBeNil)
206 So(defs, ShouldResemble, []Definition{ 207 So(defs, ShouldResemble, []Definition{
207 { 208 {
208 JobID: "project1/noop-job-1", 209 JobID: "project1/noop-job-1",
209 » » » » » Revision: "776a16076543daae60a3c9df9a3ea 2d7a4067045", 210 » » » » » Acls: acl.GrantsByRole{Readers: []st ring{"group:all"}, Owners: []string{"group:some-admins"}},
211 » » » » » Revision: "847cf9c217f7bad214805f3bea7a3 0799383940b",
210 Schedule: "*/10 * * * * * *", 212 Schedule: "*/10 * * * * * *",
211 Task: []uint8{0xa, 0x0}, 213 Task: []uint8{0xa, 0x0},
212 }, 214 },
213 { 215 {
214 JobID: "project1/noop-job-2", 216 JobID: "project1/noop-job-2",
215 » » » » » Revision: "776a16076543daae60a3c9df9a3ea 2d7a4067045", 217 » » » » » Acls: acl.GrantsByRole{Readers: []st ring{"group:all"}, Owners: []string{"group:some-admins"}},
218 » » » » » Revision: "847cf9c217f7bad214805f3bea7a3 0799383940b",
216 Schedule: "*/10 * * * * * *", 219 Schedule: "*/10 * * * * * *",
217 Task: []uint8{0xa, 0x0}, 220 Task: []uint8{0xa, 0x0},
218 }, 221 },
219 { 222 {
220 JobID: "project1/urlfetch-job-1", 223 JobID: "project1/urlfetch-job-1",
221 » » » » » Revision: "776a16076543daae60a3c9df9a3ea 2d7a4067045", 224 » » » » » Acls: acl.GrantsByRole{Readers: []st ring{"group:all"}, Owners: []string{"group:debuggers", "group:some-admins"}},
225 » » » » » Revision: "847cf9c217f7bad214805f3bea7a3 0799383940b",
222 Schedule: "*/10 * * * * * *", 226 Schedule: "*/10 * * * * * *",
223 Task: []uint8{18, 21, 18, 19, 104, 1 16, 116, 112, 115, 58, 47, 47, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 10 9}, 227 Task: []uint8{18, 21, 18, 19, 104, 1 16, 116, 112, 115, 58, 47, 47, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 10 9},
224 }, 228 },
225 { 229 {
226 JobID: "project1/urlfetch-job-2", 230 JobID: "project1/urlfetch-job-2",
227 » » » » » Revision: "776a16076543daae60a3c9df9a3ea 2d7a4067045", 231 » » » » » Acls: acl.GrantsByRole{Readers: []st ring{"group:all"}, Owners: []string{"group:some-admins"}},
232 » » » » » Revision: "847cf9c217f7bad214805f3bea7a3 0799383940b",
228 Schedule: "*/10 * * * * * *", 233 Schedule: "*/10 * * * * * *",
229 Task: []uint8{18, 21, 18, 19, 104, 1 16, 116, 112, 115, 58, 47, 47, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 10 9}, 234 Task: []uint8{18, 21, 18, 19, 104, 1 16, 116, 112, 115, 58, 47, 47, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 10 9},
230 }, 235 },
231 }) 236 })
232 237
233 // Make sure URL fetch jobs are parsed correctly and ide ntically. 238 // Make sure URL fetch jobs are parsed correctly and ide ntically.
234 newStyleDef := defs[2].Task 239 newStyleDef := defs[2].Task
235 oldStyleDef := defs[3].Task 240 oldStyleDef := defs[3].Task
236 So(newStyleDef, ShouldResemble, oldStyleDef) 241 So(newStyleDef, ShouldResemble, oldStyleDef)
237 msg := messages.TaskDefWrapper{} 242 msg := messages.TaskDefWrapper{}
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 fakeTaskManager 328 fakeTaskManager
324 } 329 }
325 330
326 func (b brokenTaskManager) ProtoMessageType() proto.Message { 331 func (b brokenTaskManager) ProtoMessageType() proto.Message {
327 return nil 332 return nil
328 } 333 }
329 334
330 //// 335 ////
331 336
332 const project1Cfg = ` 337 const project1Cfg = `
338
339 acl_sets {
340 name: "public"
341 acls {
342 role: READER
343 granted_to: "group:all"
344 }
345 acls {
346 role: OWNER
347 granted_to: "group:some-admins"
348 }
349 }
350
333 job { 351 job {
334 id: "noop-job-1" 352 id: "noop-job-1"
335 schedule: "*/10 * * * * * *" 353 schedule: "*/10 * * * * * *"
354 acl_sets: "public"
336 355
337 noop: {} 356 noop: {}
338 } 357 }
339 358
340 job { 359 job {
341 id: "noop-job-2" 360 id: "noop-job-2"
342 schedule: "*/10 * * * * * *" 361 schedule: "*/10 * * * * * *"
362 acl_sets: "public"
343 363
344 noop: {} 364 noop: {}
345 } 365 }
346 366
347 job { 367 job {
348 id: "noop-job-3" 368 id: "noop-job-3"
349 schedule: "*/10 * * * * * *" 369 schedule: "*/10 * * * * * *"
350 disabled: true 370 disabled: true
351 371
352 noop: {} 372 noop: {}
353 } 373 }
354 374
355 job { 375 job {
356 id: "urlfetch-job-1" 376 id: "urlfetch-job-1"
357 schedule: "*/10 * * * * * *" 377 schedule: "*/10 * * * * * *"
378 acl_sets: "public"
379 acls {
380 role: OWNER
381 granted_to: "group:debuggers"
382 }
358 383
359 url_fetch: { 384 url_fetch: {
360 url: "https://example.com" 385 url: "https://example.com"
361 } 386 }
362 } 387 }
363 388
364 # Old-style URL fetch job definition. 389 # Old-style URL fetch job definition.
365 job { 390 job {
366 id: "urlfetch-job-2" 391 id: "urlfetch-job-2"
367 schedule: "*/10 * * * * * *" 392 schedule: "*/10 * * * * * *"
393 acl_sets: "public"
368 394
369 task: { 395 task: {
370 url_fetch: { 396 url_fetch: {
371 url: "https://example.com" 397 url: "https://example.com"
372 } 398 }
373 } 399 }
374 } 400 }
375 401
376 # Will be skipped since SwarmingTask Manager is not registered. 402 # Will be skipped since SwarmingTask Manager is not registered.
377 job { 403 job {
(...skipping 16 matching lines...) Expand all
394 "projects/project1": { 420 "projects/project1": {
395 "scheduler.cfg": project1Cfg, 421 "scheduler.cfg": project1Cfg,
396 }, 422 },
397 "projects/project2": { 423 "projects/project2": {
398 "scheduler.cfg": project2Cfg, 424 "scheduler.cfg": project2Cfg,
399 }, 425 },
400 "projects/broken": { 426 "projects/broken": {
401 "scheduler.cfg": "broken!!!!111", 427 "scheduler.cfg": "broken!!!!111",
402 }, 428 },
403 } 429 }
OLDNEW
« no previous file with comments | « scheduler/appengine/catalog/catalog.go ('k') | scheduler/appengine/engine/engine.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698