OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package deps | 5 package deps |
6 | 6 |
7 import ( | 7 import ( |
8 "testing" | 8 "testing" |
9 | 9 |
10 » "github.com/luci/gae/service/datastore" | 10 » "github.com/luci/luci-go/appengine/cmd/dm/distributor/fake" |
11 » "github.com/luci/luci-go/appengine/tumble" | |
12 dm "github.com/luci/luci-go/common/api/dm/service/v1" | 11 dm "github.com/luci/luci-go/common/api/dm/service/v1" |
13 . "github.com/luci/luci-go/common/testing/assertions" | 12 . "github.com/luci/luci-go/common/testing/assertions" |
14 . "github.com/smartystreets/goconvey/convey" | 13 . "github.com/smartystreets/goconvey/convey" |
15 ) | 14 ) |
16 | 15 |
17 func TestActivateExecution(t *testing.T) { | 16 func TestActivateExecution(t *testing.T) { |
18 t.Parallel() | 17 t.Parallel() |
19 | 18 |
20 Convey("Test ActivateExecution", t, func() { | 19 Convey("Test ActivateExecution", t, func() { |
21 » » ttest := &tumble.Testing{} | 20 » » ttest, c, dist, s := testSetup() |
22 » » c := ttest.Context() | |
23 » » ds := datastore.Get(c) | |
24 » » _ = ds | |
25 » » s := newDecoratedDeps() | |
26 | 21 |
27 » » qid := ensureQuest(c, "foo", 1) | 22 » » qid := s.ensureQuest(c, "foo", 1) |
28 ttest.Drain(c) | 23 ttest.Drain(c) |
29 realAuth := execute(c, dm.NewAttemptID(qid, 1)) | |
30 | 24 |
31 eid := dm.NewExecutionID(qid, 1, 1) | 25 eid := dm.NewExecutionID(qid, 1, 1) |
| 26 dist.RunTask(c, eid, func(tsk *fake.Task) error { |
| 27 req := &dm.ActivateExecutionReq{ |
| 28 Auth: &dm.Execution_Auth{Id: eid}, |
| 29 ExecutionToken: []byte("sufficiently long new 'r
andom' token"), |
| 30 } |
32 | 31 |
33 » » req := &dm.ActivateExecutionReq{ | 32 » » » Convey("bad", func() { |
34 » » » Auth: &dm.Execution_Auth{Id: eid}, | 33 » » » » Convey("wrong token", func() { |
35 » » » ExecutionToken: []byte("newtok"), | 34 » » » » » _, err := s.ActivateExecution(c, req) |
36 » » } | 35 » » » » » So(err, ShouldBeRPCUnauthenticated, "fai
led to activate") |
| 36 » » » » }) |
37 | 37 |
38 » » Convey("bad", func() { | 38 » » » » Convey("wrong token (already activated)", func()
{ |
39 » » » Convey("wrong token", func() { | 39 » » » » » req.Auth.Token = tsk.Auth.Token |
40 » » » » _, err := s.ActivateExecution(c, req) | 40 » » » » » _, err := s.ActivateExecution(c, req) |
41 » » » » So(err, ShouldBeRPCUnauthenticated, "failed to a
ctivate") | 41 » » » » » So(err, ShouldBeNil) |
| 42 |
| 43 » » » » » req.Auth.Token = []byte("bad sekret") |
| 44 » » » » » req.ExecutionToken = []byte("random othe
r super duper long token") |
| 45 » » » » » _, err = s.ActivateExecution(c, req) |
| 46 » » » » » So(err, ShouldBeRPCUnauthenticated, "fai
led to activate") |
| 47 » » » » }) |
| 48 |
| 49 » » » » Convey("concurrent activation", func() { |
| 50 » » » » » req.Auth.Token = tsk.Auth.Token |
| 51 » » » » » _, err := s.ActivateExecution(c, req) |
| 52 » » » » » So(err, ShouldBeNil) |
| 53 |
| 54 » » » » » req.ExecutionToken = append(req.Executio
nToken, []byte(" (but incorrect)")...) |
| 55 » » » » » _, err = s.ActivateExecution(c, req) |
| 56 » » » » » So(err, ShouldBeRPCUnauthenticated, "fai
led to activate") |
| 57 » » » » }) |
42 }) | 58 }) |
43 | 59 |
44 » » » Convey("wrong token (already activated)", func() { | 60 » » » Convey("good", func() { |
45 » » » » req.Auth.Token = realAuth.Token | 61 » » » » req.Auth.Token = tsk.Auth.Token |
46 » » » » _, err := s.ActivateExecution(c, req) | |
47 » » » » So(err, ShouldBeNil) | |
48 | 62 |
49 » » » » req.Auth.Token = []byte("bad sekret") | 63 » » » » Convey("normal activation", func() { |
50 » » » » req.ExecutionToken = []byte("random other tok") | 64 » » » » » _, err := s.ActivateExecution(c, req) |
51 » » » » _, err = s.ActivateExecution(c, req) | 65 » » » » » So(err, ShouldBeNil) |
52 » » » » So(err, ShouldBeRPCUnauthenticated, "failed to a
ctivate") | 66 » » » » }) |
| 67 |
| 68 » » » » Convey("repeated activation", func() { |
| 69 » » » » » _, err := s.ActivateExecution(c, req) |
| 70 » » » » » So(err, ShouldBeNil) |
| 71 » » » » » _, err = s.ActivateExecution(c, req) |
| 72 » » » » » So(err, ShouldBeNil) |
| 73 » » » » }) |
53 }) | 74 }) |
54 | 75 » » » return nil |
55 » » » Convey("concurrent activation", func() { | |
56 » » » » req.Auth.Token = realAuth.Token | |
57 » » » » _, err := s.ActivateExecution(c, req) | |
58 » » » » So(err, ShouldBeNil) | |
59 | |
60 » » » » req.ExecutionToken = []byte("other newtok") | |
61 » » » » _, err = s.ActivateExecution(c, req) | |
62 » » » » So(err, ShouldBeRPCUnauthenticated, "failed to a
ctivate") | |
63 » » » }) | |
64 » » }) | |
65 | |
66 » » Convey("good", func() { | |
67 » » » req.Auth.Token = realAuth.Token | |
68 | |
69 » » » Convey("normal activation", func() { | |
70 » » » » _, err := s.ActivateExecution(c, req) | |
71 » » » » So(err, ShouldBeNil) | |
72 » » » }) | |
73 | |
74 » » » Convey("repeated activation", func() { | |
75 » » » » _, err := s.ActivateExecution(c, req) | |
76 » » » » So(err, ShouldBeNil) | |
77 » » » » _, err = s.ActivateExecution(c, req) | |
78 » » » » So(err, ShouldBeNil) | |
79 » » » }) | |
80 }) | 76 }) |
81 }) | 77 }) |
82 } | 78 } |
OLD | NEW |