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

Unified Diff: tokenserver/appengine/impl/serviceaccounts/config_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 side-by-side diff with in-line comments
Download patch
Index: tokenserver/appengine/impl/serviceaccounts/config_test.go
diff --git a/tokenserver/appengine/impl/serviceaccounts/config_test.go b/tokenserver/appengine/impl/serviceaccounts/config_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..22b1c698172cb300318d6861a1f4d8898cab11fc
--- /dev/null
+++ b/tokenserver/appengine/impl/serviceaccounts/config_test.go
@@ -0,0 +1,60 @@
+// Copyright 2017 The LUCI Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package serviceaccounts
+
+import (
+ "testing"
+
+ "github.com/golang/protobuf/proto"
+
+ "github.com/luci/luci-go/tokenserver/api/admin/v1"
+ "github.com/luci/luci-go/tokenserver/appengine/impl/utils/policy"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestRules(t *testing.T) {
+ t.Parallel()
+
+ Convey("Loads", t, func() {
+ cfg, err := loadConfig(`
+ rules {
+ name: "rule 1"
+ owner: "developer@example.com"
+ service_account: "abc@robots.com"
+ allowed_scope: "https://scope"
+ end_user: "user:abc@example.com"
+ end_user: "group:group-name"
+ proxy: "user:proxy@example.com"
+ max_grant_validity_duration: 3600
+ }
+ `)
+ So(err, ShouldBeNil)
+ So(cfg, ShouldNotBeNil)
+ })
+}
+
+func loadConfig(text string) (*Rules, error) {
+ cfg := &admin.ServiceAccountsPermissions{}
+ err := proto.UnmarshalText(text, cfg)
+ if err != nil {
+ return nil, err
+ }
+ rules, err := prepareRules(policy.ConfigBundle{serviceAccountsCfg: cfg}, "fake-revision")
+ if err != nil {
+ return nil, err
+ }
+ return rules.(*Rules), nil
+}

Powered by Google App Engine
This is Rietveld 408576698