@@ -23,16 +23,15 @@ var (
2323
2424func TestDelegationsIterator (t * testing.T ) {
2525 var iteratorTests = []struct {
26- testName string
27- roles map [string ][]data.DelegatedRole
28- rootDelegation data.DelegatedRole
29- file string
30- resultOrder []string
26+ testName string
27+ roles map [string ][]data.DelegatedRole
28+ file string
29+ resultOrder []string
3130 }{
3231 {
3332 testName : "no termination" ,
3433 roles : map [string ][]data.DelegatedRole {
35- "a " : {
34+ "targets " : {
3635 {Name : "b" , Paths : defaultPathPatterns },
3736 {Name : "e" , Paths : defaultPathPatterns },
3837 },
@@ -52,14 +51,13 @@ func TestDelegationsIterator(t *testing.T) {
5251 {Name : "j" , Paths : defaultPathPatterns },
5352 },
5453 },
55- rootDelegation : data.DelegatedRole {Name : "a" , Paths : defaultPathPatterns },
56- file : "" ,
57- resultOrder : []string {"a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" },
54+ file : "" ,
55+ resultOrder : []string {"targets" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" },
5856 },
5957 {
6058 testName : "terminated in b" ,
6159 roles : map [string ][]data.DelegatedRole {
62- "a " : {
60+ "targets " : {
6361 {Name : "b" , Paths : defaultPathPatterns , Terminating : true },
6462 {Name : "e" , Paths : defaultPathPatterns },
6563 },
@@ -68,14 +66,13 @@ func TestDelegationsIterator(t *testing.T) {
6866 {Name : "d" , Paths : defaultPathPatterns },
6967 },
7068 },
71- rootDelegation : data.DelegatedRole {Name : "a" , Paths : defaultPathPatterns },
72- file : "" ,
73- resultOrder : []string {"a" , "b" , "c" , "d" },
69+ file : "" ,
70+ resultOrder : []string {"targets" , "b" , "c" , "d" },
7471 },
7572 {
7673 testName : "path does not match b" ,
7774 roles : map [string ][]data.DelegatedRole {
78- "a " : {
75+ "targets " : {
7976 {Name : "b" , Paths : noMatchPathPatterns },
8077 {Name : "e" , Paths : defaultPathPatterns },
8178 },
@@ -84,50 +81,47 @@ func TestDelegationsIterator(t *testing.T) {
8481 {Name : "d" , Paths : defaultPathPatterns },
8582 },
8683 },
87- rootDelegation : data.DelegatedRole {Name : "a" , Paths : defaultPathPatterns },
88- file : "" ,
89- resultOrder : []string {"a" , "e" },
84+ file : "" ,
85+ resultOrder : []string {"targets" , "e" },
9086 },
9187 {
9288 testName : "cycle avoided 1" ,
9389 roles : map [string ][]data.DelegatedRole {
94- "a " : {
90+ "targets " : {
9591 {Name : "b" , Paths : defaultPathPatterns },
9692 {Name : "e" , Paths : defaultPathPatterns },
9793 },
9894 "b" : {
99- {Name : "a " , Paths : defaultPathPatterns },
95+ {Name : "targets " , Paths : defaultPathPatterns },
10096 {Name : "d" , Paths : defaultPathPatterns },
10197 },
10298 },
103- rootDelegation : data.DelegatedRole {Name : "a" , Paths : defaultPathPatterns },
104- file : "" ,
105- resultOrder : []string {"a" , "b" , "a" , "e" , "d" },
99+ file : "" ,
100+ resultOrder : []string {"targets" , "b" , "targets" , "e" , "d" },
106101 },
107102 {
108103 testName : "cycle avoided 2" ,
109104 roles : map [string ][]data.DelegatedRole {
110- "a " : {
111- {Name : "a " , Paths : defaultPathPatterns },
105+ "targets " : {
106+ {Name : "targets " , Paths : defaultPathPatterns },
112107 {Name : "b" , Paths : defaultPathPatterns },
113108 },
114109 "b" : {
115- {Name : "a " , Paths : defaultPathPatterns },
110+ {Name : "targets " , Paths : defaultPathPatterns },
116111 {Name : "b" , Paths : defaultPathPatterns },
117112 {Name : "c" , Paths : defaultPathPatterns },
118113 },
119114 "c" : {
120115 {Name : "c" , Paths : defaultPathPatterns },
121116 },
122117 },
123- rootDelegation : data.DelegatedRole {Name : "a" , Paths : defaultPathPatterns },
124- file : "" ,
125- resultOrder : []string {"a" , "a" , "b" , "a" , "b" , "c" , "c" },
118+ file : "" ,
119+ resultOrder : []string {"targets" , "targets" , "b" , "targets" , "b" , "c" , "c" },
126120 },
127121 {
128122 testName : "diamond delegation" ,
129123 roles : map [string ][]data.DelegatedRole {
130- "a " : {
124+ "targets " : {
131125 {Name : "b" , Paths : defaultPathPatterns },
132126 {Name : "c" , Paths : defaultPathPatterns },
133127 },
@@ -138,15 +132,14 @@ func TestDelegationsIterator(t *testing.T) {
138132 {Name : "d" , Paths : defaultPathPatterns },
139133 },
140134 },
141- rootDelegation : data.DelegatedRole {Name : "a" , Paths : defaultPathPatterns },
142- file : "" ,
143- resultOrder : []string {"a" , "b" , "d" , "c" , "d" },
135+ file : "" ,
136+ resultOrder : []string {"targets" , "b" , "d" , "c" , "d" },
144137 },
145138 }
146139
147140 for _ , tt := range iteratorTests {
148141 t .Run (tt .testName , func (t * testing.T ) {
149- d := newDelegationsIterator (tt .rootDelegation , "root" , tt . file )
142+ d := newDelegationsIterator (tt .file )
150143 var iterationOrder []string
151144 for {
152145 r , ok := d .next ()
@@ -234,20 +227,6 @@ func TestTargetsNotFound(t *testing.T) {
234227 assert .Equal (t , ErrMissingRemoteMetadata {Name : "c.json" }, err )
235228}
236229
237- func TestRootDelegationMatchesAll (t * testing.T ) {
238- c := & Client {db : verify .NewDB ()}
239- c .db .AddRole ("targets" , & data.Role {Threshold : 1 })
240- d := c .rootTargetDelegation ()
241-
242- matchesPath , err := d .MatchesPath ("a.txt" )
243- assert .NoError (t , err )
244- assert .True (t , matchesPath )
245-
246- matchesPath , err = d .MatchesPath ("var/b//g" )
247- assert .NoError (t , err )
248- assert .True (t , matchesPath )
249- }
250-
251230func TestUnverifiedTargets (t * testing.T ) {
252231 verify .IsExpired = func (t time.Time ) bool { return false }
253232 c , closer := initTestDelegationClient (t , "testdata/php-tuf-fixtures/TUFTestFixture3LevelDelegation" )
0 commit comments