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

Side by Side Diff: tokenserver/appengine/impl/serviceaccounts/config_validation_test.go

Issue 2993023002: tokenserver: Boilerplate for loading and serving service_accounts.cfg. (Closed)
Patch Set: add test 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
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package serviceaccounts
16
17 import (
18 "testing"
19
20 "github.com/golang/protobuf/proto"
21
22 "github.com/luci/luci-go/tokenserver/api/admin/v1"
23 "github.com/luci/luci-go/tokenserver/appengine/impl/utils/policy"
24
25 "github.com/luci/luci-go/common/config/validation"
26 . "github.com/luci/luci-go/common/testing/assertions"
27 . "github.com/smartystreets/goconvey/convey"
28 )
29
30 func TestValidation(t *testing.T) {
31 t.Parallel()
32
33 cases := []struct {
34 Cfg string
35 Errors []string
36 }{
37 {
38 Cfg: `
39 rules {
40 name: "rule 1"
41 owner: "developer@example.com"
42 service_account: "abc@robots.com"
43 allowed_scope: "https://scope"
44 end_user: "user:abc@example.com"
45 end_user: "group:group-name"
46 proxy: "user:proxy@example.com"
47 max_grant_validity_duration: 3600
48 }
49
50 rules {
51 name: "rule 2"
52 owner: "developer@example.com"
53 service_account: "def@robots.com"
54 allowed_scope: "https://scope"
55 end_user: "user:abc@example.com"
56 end_user: "group:group-name"
57 proxy: "user:proxy@example.com"
58 max_grant_validity_duration: 3600
59 }
60 `,
61 },
62
63 // TODO(vadimsh): Add more cases.
64 }
65
66 Convey("Validation works", t, func(c C) {
67 for idx, cs := range cases {
68 c.Printf("Case #%d\n", idx)
69
70 cfg := &admin.ServiceAccountsPermissions{}
71 err := proto.UnmarshalText(cs.Cfg, cfg)
72 So(err, ShouldBeNil)
73
74 ctx := validation.Context{}
75 validateConfigs(policy.ConfigBundle{serviceAccountsCfg: cfg}, &ctx)
76 verr := ctx.Finalize()
77
78 if len(cs.Errors) == 0 { // no errors expected
79 So(verr, ShouldBeNil)
80 } else {
81 verr := verr.(*validation.Error)
82 So(len(verr.Errors), ShouldEqual, len(cs.Errors) )
83 for i, err := range verr.Errors {
84 So(err, ShouldErrLike, cs.Errors[i])
85 }
86 }
87 }
88 })
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698