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

Unified Diff: tokenserver/appengine/impl/serviceaccounts/config_test.go

Issue 2997433002: tokenserver: Validate and parse service_accounts.cfg rules. (Closed)
Patch Set: tokenserver: Validate and parse service_accounts.cfg rules. 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
index 22b1c698172cb300318d6861a1f4d8898cab11fc..1f823cb191f96cc0198ff7e7ca2e136a64767510 100644
--- a/tokenserver/appengine/impl/serviceaccounts/config_test.go
+++ b/tokenserver/appengine/impl/serviceaccounts/config_test.go
@@ -15,6 +15,7 @@
package serviceaccounts
import (
+ "sort"
"testing"
"github.com/golang/protobuf/proto"
@@ -34,15 +35,46 @@ func TestRules(t *testing.T) {
name: "rule 1"
owner: "developer@example.com"
service_account: "abc@robots.com"
- allowed_scope: "https://scope"
+ service_account: "def@robots.com"
+ allowed_scope: "https://www.googleapis.com/scope1"
+ allowed_scope: "https://www.googleapis.com/scope2"
end_user: "user:abc@example.com"
- end_user: "group:group-name"
+ end_user: "group:enduser-group"
proxy: "user:proxy@example.com"
- max_grant_validity_duration: 3600
+ proxy: "group:proxy-group"
+ }
+ rules {
+ name: "rule 2"
+ service_account: "xyz@robots.com"
}
`)
So(err, ShouldBeNil)
So(cfg, ShouldNotBeNil)
+
+ rule := cfg.Rule("abc@robots.com")
+ So(rule, ShouldNotBeNil)
+ So(rule.Rule.Name, ShouldEqual, "rule 1")
+
+ scopes := rule.AllowedScopes.ToSlice()
+ sort.Strings(scopes)
+ So(scopes, ShouldResemble, []string{
+ "https://www.googleapis.com/scope1",
+ "https://www.googleapis.com/scope2",
+ })
+
+ So(rule.EndUsers.ToStrings(), ShouldResemble, []string{
+ "group:enduser-group",
+ "user:abc@example.com",
+ })
+ So(rule.Proxies.ToStrings(), ShouldResemble, []string{
+ "group:proxy-group",
+ "user:proxy@example.com",
+ })
+ So(rule.Rule.MaxGrantValidityDuration, ShouldEqual, 24*3600)
+
+ So(cfg.Rule("def@robots.com").Rule.Name, ShouldEqual, "rule 1")
+ So(cfg.Rule("xyz@robots.com").Rule.Name, ShouldEqual, "rule 2")
+ So(cfg.Rule("unknown@robots.com"), ShouldBeNil)
})
}
« no previous file with comments | « tokenserver/appengine/impl/serviceaccounts/config.go ('k') | tokenserver/appengine/impl/serviceaccounts/config_validation.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698