-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroupmapper_test.go
More file actions
74 lines (66 loc) · 1.51 KB
/
Copy pathgroupmapper_test.go
File metadata and controls
74 lines (66 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package sso_test
import (
"testing"
sso "github.com/foomo/gosso"
"github.com/stretchr/testify/assert"
)
type role string
const (
roleAdmin role = "admin"
roleUser role = "user"
)
func TestGroupMapper(t *testing.T) {
t.Parallel()
cases := map[string]struct {
mapper sso.GroupMapper[role]
input []string
want []role
}{
"empty mapper": {
mapper: sso.GroupMapper[role]{},
input: []string{"a", "b"},
want: nil,
},
"empty input": {
mapper: sso.GroupMapper[role]{"a": roleAdmin},
input: nil,
want: nil,
},
"translates known groups": {
mapper: sso.GroupMapper[role]{
"ad-admins": roleAdmin,
"ad-users": roleUser,
},
input: []string{"ad-admins", "ad-users"},
want: []role{roleAdmin, roleUser},
},
"skips unknown groups": {
mapper: sso.GroupMapper[role]{"ad-admins": roleAdmin},
input: []string{"noise", "ad-admins", "other"},
want: []role{roleAdmin},
},
"deduplicates when multiple groups map to same role": {
mapper: sso.GroupMapper[role]{
"ad-admins-eu": roleAdmin,
"ad-admins-us": roleAdmin,
},
input: []string{"ad-admins-eu", "ad-admins-us"},
want: []role{roleAdmin},
},
"preserves first-seen order": {
mapper: sso.GroupMapper[role]{
"g1": roleUser,
"g2": roleAdmin,
},
input: []string{"g2", "g1"},
want: []role{roleAdmin, roleUser},
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
t.Parallel()
got := tc.mapper.Map(tc.input)
assert.Equal(t, tc.want, got)
})
}
}