14
14
)
15
15
16
16
func TestDelegationsIterator (t * testing.T ) {
17
+ defaultKeyIDs := []string {"26b878ad73362774b8b69dd4fdeb2cc6a2688e4133ed5ace9e18a06e9d998a6d" }
17
18
var iteratorTests = []struct {
18
19
testName string
19
20
roles map [string ][]data.DelegatedRole
@@ -25,23 +26,23 @@ func TestDelegationsIterator(t *testing.T) {
25
26
testName : "no termination" ,
26
27
roles : map [string ][]data.DelegatedRole {
27
28
"targets" : {
28
- {Name : "b" , Paths : defaultPathPatterns },
29
- {Name : "e" , Paths : defaultPathPatterns },
29
+ {Name : "b" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
30
+ {Name : "e" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
30
31
},
31
32
"b" : {
32
- {Name : "c" , Paths : defaultPathPatterns },
33
+ {Name : "c" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
33
34
},
34
35
"c" : {
35
- {Name : "d" , Paths : defaultPathPatterns },
36
+ {Name : "d" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
36
37
},
37
38
"e" : {
38
- {Name : "f" , Paths : defaultPathPatterns },
39
- {Name : "g" , Paths : defaultPathPatterns },
39
+ {Name : "f" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
40
+ {Name : "g" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
40
41
},
41
42
"g" : {
42
- {Name : "h" , Paths : defaultPathPatterns },
43
- {Name : "i" , Paths : defaultPathPatterns },
44
- {Name : "j" , Paths : defaultPathPatterns },
43
+ {Name : "h" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
44
+ {Name : "i" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
45
+ {Name : "j" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
45
46
},
46
47
},
47
48
file : "" ,
@@ -51,12 +52,12 @@ func TestDelegationsIterator(t *testing.T) {
51
52
testName : "terminated in b" ,
52
53
roles : map [string ][]data.DelegatedRole {
53
54
"targets" : {
54
- {Name : "b" , Paths : defaultPathPatterns , Terminating : true },
55
- {Name : "e" , Paths : defaultPathPatterns },
55
+ {Name : "b" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs , Terminating : true },
56
+ {Name : "e" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
56
57
},
57
58
"b" : {
58
- {Name : "c" , Paths : defaultPathPatterns },
59
- {Name : "d" , Paths : defaultPathPatterns },
59
+ {Name : "c" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
60
+ {Name : "d" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
60
61
},
61
62
},
62
63
file : "" ,
@@ -66,12 +67,12 @@ func TestDelegationsIterator(t *testing.T) {
66
67
testName : "path does not match b" ,
67
68
roles : map [string ][]data.DelegatedRole {
68
69
"targets" : {
69
- {Name : "b" , Paths : noMatchPathPatterns },
70
- {Name : "e" , Paths : defaultPathPatterns },
70
+ {Name : "b" , Paths : noMatchPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
71
+ {Name : "e" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
71
72
},
72
73
"b" : {
73
- {Name : "c" , Paths : defaultPathPatterns },
74
- {Name : "d" , Paths : defaultPathPatterns },
74
+ {Name : "c" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
75
+ {Name : "d" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
75
76
},
76
77
},
77
78
file : "" ,
@@ -81,12 +82,13 @@ func TestDelegationsIterator(t *testing.T) {
81
82
testName : "path does not match b - path prefixes" ,
82
83
roles : map [string ][]data.DelegatedRole {
83
84
"targets" : {
84
- {Name : "b" , PathHashPrefixes : []string {"33472a4909" }},
85
- {Name : "c" , PathHashPrefixes : []string {"34c85d1ee84f61f10d7dc633" }},
85
+ {Name : "b" , PathHashPrefixes : []string {"33472a4909" }, Threshold : 1 , KeyIDs : defaultKeyIDs },
86
+ {Name : "c" , PathHashPrefixes : []string {"34c85d1ee84f61f10d7dc633" }, Threshold : 1 , KeyIDs : defaultKeyIDs },
86
87
},
87
88
"c" : {
88
- {Name : "d" , PathHashPrefixes : []string {"8baf" }},
89
- {Name : "e" , PathHashPrefixes : []string {"34c85d1ee84f61f10d7dc633472a49096ed87f8f764bd597831eac371f40ac39" }},
89
+
90
+ {Name : "d" , PathHashPrefixes : []string {"8baf" }, Threshold : 1 , KeyIDs : defaultKeyIDs },
91
+ {Name : "e" , PathHashPrefixes : []string {"34c85d1ee84f61f10d7dc633472a49096ed87f8f764bd597831eac371f40ac39" }, Threshold : 1 , KeyIDs : defaultKeyIDs },
90
92
},
91
93
},
92
94
file : "/e/f/g.txt" ,
@@ -96,7 +98,7 @@ func TestDelegationsIterator(t *testing.T) {
96
98
testName : "err paths and pathHashPrefixes are set" ,
97
99
roles : map [string ][]data.DelegatedRole {
98
100
"targets" : {
99
- {Name : "b" , Paths : defaultPathPatterns , PathHashPrefixes : defaultPathPatterns },
101
+ {Name : "b" , Paths : defaultPathPatterns , PathHashPrefixes : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
100
102
},
101
103
"b" : {},
102
104
},
@@ -108,48 +110,54 @@ func TestDelegationsIterator(t *testing.T) {
108
110
testName : "cycle avoided 1" ,
109
111
roles : map [string ][]data.DelegatedRole {
110
112
"targets" : {
111
- {Name : "b" , Paths : defaultPathPatterns },
112
- {Name : "e" , Paths : defaultPathPatterns },
113
+ {Name : "a" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
114
+ },
115
+ "a" : {
116
+ {Name : "b" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
117
+ {Name : "e" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
113
118
},
114
119
"b" : {
115
- {Name : "targets " , Paths : defaultPathPatterns },
116
- {Name : "d" , Paths : defaultPathPatterns },
120
+ {Name : "a " , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
121
+ {Name : "d" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
117
122
},
118
123
},
119
124
file : "" ,
120
- resultOrder : []string {"targets" , "b" , "d" , "e" },
125
+ resultOrder : []string {"targets" , "a" , " b" , "d" , "e" },
121
126
},
122
127
{
123
128
testName : "cycle avoided 2" ,
124
129
roles : map [string ][]data.DelegatedRole {
125
130
"targets" : {
126
- {Name : "targets" , Paths : defaultPathPatterns },
127
- {Name : "b" , Paths : defaultPathPatterns },
131
+ {Name : "a" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
132
+ },
133
+ "a" : {
134
+ {Name : "a" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
135
+ {Name : "b" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
128
136
},
129
137
"b" : {
130
- {Name : "targets " , Paths : defaultPathPatterns },
131
- {Name : "b" , Paths : defaultPathPatterns },
132
- {Name : "c" , Paths : defaultPathPatterns },
138
+ {Name : "a " , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
139
+ {Name : "b" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
140
+ {Name : "c" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
133
141
},
134
142
"c" : {
135
- {Name : "c" , Paths : defaultPathPatterns },
143
+ {Name : "c" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
136
144
},
137
145
},
138
146
file : "" ,
139
- resultOrder : []string {"targets" , "b" , "c" },
147
+ resultOrder : []string {"targets" , "a" , " b" , "c" },
140
148
},
141
149
{
142
150
testName : "diamond delegation" ,
143
151
roles : map [string ][]data.DelegatedRole {
144
152
"targets" : {
145
- {Name : "b" , Paths : defaultPathPatterns },
146
- {Name : "c" , Paths : defaultPathPatterns },
153
+ {Name : "b" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
154
+ {Name : "c" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
147
155
},
148
156
"b" : {
149
- {Name : "d" , Paths : defaultPathPatterns },
157
+ {Name : "d" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
150
158
},
151
159
"c" : {
152
- {Name : "d" , Paths : defaultPathPatterns },
160
+ {Name : "d" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
153
161
},
154
162
},
155
163
file : "" ,
@@ -159,10 +167,10 @@ func TestDelegationsIterator(t *testing.T) {
159
167
testName : "simple cycle" ,
160
168
roles : map [string ][]data.DelegatedRole {
161
169
"targets" : {
162
- {Name : "a" , Paths : defaultPathPatterns },
170
+ {Name : "a" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
163
171
},
164
172
"a" : {
165
- {Name : "a" , Paths : defaultPathPatterns },
173
+ {Name : "a" , Paths : defaultPathPatterns , Threshold : 1 , KeyIDs : defaultKeyIDs },
166
174
},
167
175
},
168
176
file : "" ,
@@ -172,7 +180,17 @@ func TestDelegationsIterator(t *testing.T) {
172
180
173
181
for _ , tt := range iteratorTests {
174
182
t .Run (tt .testName , func (t * testing.T ) {
175
- d := NewDelegationsIterator (tt .file )
183
+ flattened := []data.DelegatedRole {}
184
+ for _ , roles := range tt .roles {
185
+ flattened = append (flattened , roles ... )
186
+ }
187
+ db , err := verify .NewDBFromDelegations (& data.Delegations {
188
+ Roles : flattened ,
189
+ })
190
+
191
+ assert .NoError (t , err )
192
+ d := NewDelegationsIterator (tt .file , db )
193
+
176
194
var iterationOrder []string
177
195
for {
178
196
r , ok := d .Next ()
@@ -184,7 +202,13 @@ func TestDelegationsIterator(t *testing.T) {
184
202
if ! ok {
185
203
continue
186
204
}
187
- err := d .Add (delegations , r .Delegatee .Name , verify.DelegationsVerifier {})
205
+
206
+ db , err := verify .NewDBFromDelegations (& data.Delegations {
207
+ Roles : delegations ,
208
+ })
209
+ assert .NoError (t , err )
210
+
211
+ err = d .Add (delegations , r .Delegatee .Name , db )
188
212
assert .Equal (t , tt .err , err )
189
213
}
190
214
assert .Equal (t , tt .resultOrder , iterationOrder )
0 commit comments