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

Side by Side Diff: tokenserver/appengine/utils/identityset/identityset_test.go

Issue 2413683004: token-server: Delegation config import, validation and evaluation. (Closed)
Patch Set: also check validity_duration Created 4 years, 1 month 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 | « tokenserver/appengine/utils/identityset/identityset.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 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 identityset 5 package identityset
6 6
7 import ( 7 import (
8 "testing" 8 "testing"
9 9
10 "golang.org/x/net/context" 10 "golang.org/x/net/context"
11 11
12 "github.com/luci/luci-go/server/auth" 12 "github.com/luci/luci-go/server/auth"
13 "github.com/luci/luci-go/server/auth/authtest" 13 "github.com/luci/luci-go/server/auth/authtest"
14 "github.com/luci/luci-go/server/auth/identity" 14 "github.com/luci/luci-go/server/auth/identity"
15 15
16 . "github.com/luci/luci-go/common/testing/assertions" 16 . "github.com/luci/luci-go/common/testing/assertions"
17 . "github.com/smartystreets/goconvey/convey" 17 . "github.com/smartystreets/goconvey/convey"
18 ) 18 )
19 19
20 func TestFromStrings(t *testing.T) { 20 func TestFromStrings(t *testing.T) {
21 Convey("Empty", t, func() { 21 Convey("Empty", t, func() {
22 s, err := FromStrings(nil, nil) 22 s, err := FromStrings(nil, nil)
23 So(err, ShouldBeNil) 23 So(err, ShouldBeNil)
24 So(s, ShouldResemble, &Set{}) 24 So(s, ShouldResemble, &Set{})
25 So(s.IsEmpty(), ShouldBeTrue) 25 So(s.IsEmpty(), ShouldBeTrue)
26 So(s.ToStrings(), ShouldResemble, []string{})
26 }) 27 })
27 28
28 Convey("Universal", t, func() { 29 Convey("Universal", t, func() {
29 s, err := FromStrings([]string{"*", "user:abc@example.com"}, nil ) 30 s, err := FromStrings([]string{"*", "user:abc@example.com"}, nil )
30 So(err, ShouldBeNil) 31 So(err, ShouldBeNil)
31 So(s, ShouldResemble, &Set{All: true}) 32 So(s, ShouldResemble, &Set{All: true})
32 So(s.IsEmpty(), ShouldBeFalse) 33 So(s.IsEmpty(), ShouldBeFalse)
34 So(s.ToStrings(), ShouldResemble, []string{"*"})
33 }) 35 })
34 36
35 Convey("Normal", t, func() { 37 Convey("Normal", t, func() {
36 s, err := FromStrings([]string{ 38 s, err := FromStrings([]string{
37 "user:abc@example.com", 39 "user:abc@example.com",
38 "user:def@example.com", 40 "user:def@example.com",
39 "user:abc@example.com", 41 "user:abc@example.com",
40 "skipped", 42 "skipped",
41 "group:abc", 43 "group:abc",
42 "group:def", 44 "group:def",
43 "group:abc", 45 "group:abc",
44 }, func(s string) bool { return s == "skipped" }) 46 }, func(s string) bool { return s == "skipped" })
45 So(err, ShouldBeNil) 47 So(err, ShouldBeNil)
46 So(s, ShouldResemble, &Set{ 48 So(s, ShouldResemble, &Set{
47 IDs: identSet{ 49 IDs: identSet{
48 "user:abc@example.com": struct{}{}, 50 "user:abc@example.com": struct{}{},
49 "user:def@example.com": struct{}{}, 51 "user:def@example.com": struct{}{},
50 }, 52 },
51 Groups: groupSet{ 53 Groups: groupSet{
52 "abc": struct{}{}, 54 "abc": struct{}{},
53 "def": struct{}{}, 55 "def": struct{}{},
54 }, 56 },
55 }) 57 })
56 So(s.IsEmpty(), ShouldBeFalse) 58 So(s.IsEmpty(), ShouldBeFalse)
59 So(s.ToStrings(), ShouldResemble, []string{
60 "group:abc",
61 "group:def",
62 "user:abc@example.com",
63 "user:def@example.com",
64 })
57 }) 65 })
58 66
59 Convey("Bad group entry", t, func() { 67 Convey("Bad group entry", t, func() {
60 s, err := FromStrings([]string{"group:"}, nil) 68 s, err := FromStrings([]string{"group:"}, nil)
61 So(err, ShouldErrLike, "invalid entry") 69 So(err, ShouldErrLike, "invalid entry")
62 So(s, ShouldEqual, nil) 70 So(s, ShouldEqual, nil)
63 }) 71 })
64 72
65 Convey("Bad ID entry", t, func() { 73 Convey("Bad ID entry", t, func() {
66 s, err := FromStrings([]string{"shrug"}, nil) 74 s, err := FromStrings([]string{"shrug"}, nil)
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 }, nil) 257 }, nil)
250 So(Extend(set, "user:abc@example.com"), ShouldResemble, &Set{ 258 So(Extend(set, "user:abc@example.com"), ShouldResemble, &Set{
251 IDs: identSet{ 259 IDs: identSet{
252 "user:abc@example.com": struct{}{}, 260 "user:abc@example.com": struct{}{},
253 "user:def@example.com": struct{}{}, 261 "user:def@example.com": struct{}{},
254 }, 262 },
255 Groups: groupSet{"abc": struct{}{}}, 263 Groups: groupSet{"abc": struct{}{}},
256 }) 264 })
257 }) 265 })
258 } 266 }
OLDNEW
« no previous file with comments | « tokenserver/appengine/utils/identityset/identityset.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698