7
7
class TestImpactTest (unittest .TestCase ):
8
8
9
9
10
+ @classmethod
11
+ def setUpClass (cls ):
12
+ cls .__repo_analyzer = impact .RepoAnalyzer (detect_cherrypicks = False )
13
+
14
+
15
+
16
+ ######## 1rst : tests with only "introduced" and "fixed"
10
17
def test_introduced_fixed_linear (self ):
11
18
12
- repo_analyzer = impact .RepoAnalyzer (detect_cherrypicks = False )
13
- repo = TestRepository ('test_introduced_fixed_linear' )
19
+ repo = TestRepository ('test_introduced_fixed_linear' ,debug = False )
14
20
15
21
16
22
first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
17
23
second = repo .add_empty_commit (parents = [first ])
18
24
third = repo .add_empty_commit (parents = [second ], vulnerability = TestRepository .VulnerabilityType .FIXED )
19
25
(all_introduced , all_fixed , all_last_affected ,all_limit ) = repo .get_ranges ()
20
26
21
- result = repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
27
+
28
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
22
29
all_limit , all_last_affected )
23
30
24
31
expected = set ([first .hex , second .hex ])
25
32
repo .remove ()
26
- self .assertEqual (result .commits , expected )
33
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % ( expected , result . commits ) )
27
34
28
35
def test_introduced_fixed_branch_propagation (self ):
29
36
30
- repo_analyzer = impact .RepoAnalyzer (detect_cherrypicks = False )
31
- repo = TestRepository ('test_introduced_fixed_branch_propagation' )
37
+ repo = TestRepository ('test_introduced_fixed_branch_propagation' ,debug = False )
32
38
33
39
34
40
first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
@@ -37,16 +43,15 @@ def test_introduced_fixed_branch_propagation(self):
37
43
fourth = repo .add_empty_commit (parents = [second ])
38
44
(all_introduced , all_fixed , all_last_affected ,all_limit ) = repo .get_ranges ()
39
45
40
- result = repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
46
+ result = self . __repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
41
47
all_limit , all_last_affected )
42
48
43
49
expected = set ([first .hex ,second .hex ,fourth .hex ])
44
50
repo .remove ()
45
- self .assertEqual (result .commits , expected )
51
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % ( expected , result . commits ) )
46
52
47
53
def test_introduced_fixed_merge (self ):
48
54
49
- repo_analyzer = impact .RepoAnalyzer (detect_cherrypicks = False )
50
55
repo = TestRepository ('test_introduced_fixed_merge' )
51
56
52
57
@@ -56,10 +61,268 @@ def test_introduced_fixed_merge(self):
56
61
fourth = repo .add_empty_commit (parents = [third ], vulnerability = TestRepository .VulnerabilityType .FIXED )
57
62
(all_introduced , all_fixed , all_last_affected ,all_limit ) = repo .get_ranges ()
58
63
59
- result = repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
64
+ result = self . __repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
60
65
all_limit , all_last_affected )
61
66
62
67
expected = set ([first .hex ,third .hex ])
63
68
repo .remove ()
64
69
self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
65
-
70
+
71
+ def test_introduced_fixed_two_linear (self ):
72
+
73
+ repo = TestRepository ('test_introduced_fixed_two_linear' )
74
+
75
+
76
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
77
+ second = repo .add_empty_commit (parents = [first ], vulnerability = TestRepository .VulnerabilityType .FIXED )
78
+ third = repo .add_empty_commit (parents = [second ], vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
79
+ fourth = repo .add_empty_commit (parents = [third ], vulnerability = TestRepository .VulnerabilityType .FIXED )
80
+ (all_introduced , all_fixed , all_last_affected ,all_limit ) = repo .get_ranges ()
81
+
82
+
83
+
84
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
85
+ all_limit , all_last_affected )
86
+
87
+ expected = set ([first .hex ,third .hex ])
88
+ repo .remove ()
89
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
90
+
91
+ def test_introduced_fixed_merge_propagation (self ):
92
+ repo = TestRepository ('test_introduced_fixed_merge_propagation' )
93
+
94
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
95
+ second = repo .add_empty_commit (parents = [first ], vulnerability = TestRepository .VulnerabilityType .FIXED )
96
+ third = repo .add_empty_commit ( vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
97
+ fourth = repo .add_empty_commit (parents = [second ,third ])
98
+ fifth = repo .add_empty_commit (parents = [fourth ], vulnerability = TestRepository .VulnerabilityType .FIXED )
99
+ (all_introduced , all_fixed , all_last_affected ,all_limit ) = repo .get_ranges ()
100
+
101
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
102
+ all_limit , all_last_affected )
103
+
104
+ expected = set ([first .hex ,third .hex ,fourth .hex ])
105
+ repo .remove ()
106
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
107
+
108
+ def test_introduced_fixed_fix_propagation (self ):
109
+ repo = TestRepository ('test_introduced_fixed_fix_propagation' )
110
+
111
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
112
+ second = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .FIXED )
113
+ third = repo .add_empty_commit (parents = [first ,second ])
114
+ fourth = repo .add_empty_commit (parents = [third ],vulnerability = TestRepository .VulnerabilityType .FIXED )
115
+ (all_introduced , all_fixed , all_last_affected ,all_limit ) = repo .get_ranges ()
116
+
117
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
118
+ all_limit , all_last_affected )
119
+
120
+ expected = set ([first .hex ])
121
+ repo .remove ()
122
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
123
+
124
+ ######## 2nd : tests with "introduced" and "limit"
125
+
126
+ def test_introduced_limit_linear (self ):
127
+
128
+ repo = TestRepository ('test_intoduced_limit_linear' )
129
+
130
+
131
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
132
+ second = repo .add_empty_commit (parents = [first ])
133
+ third = repo .add_empty_commit (parents = [second ], vulnerability = TestRepository .VulnerabilityType .LIMIT )
134
+ (all_introduced , all_fixed , all_last_affected ,all_limit ) = repo .get_ranges ()
135
+
136
+
137
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
138
+ all_limit , all_last_affected )
139
+
140
+ expected = set ([first .hex , second .hex ])
141
+ repo .remove ()
142
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
143
+
144
+ def test_introduced_limit_branch (self ):
145
+
146
+ repo = TestRepository ('test_intoduced_limit_branch' )
147
+
148
+
149
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
150
+ second = repo .add_empty_commit (parents = [first ])
151
+ third = repo .add_empty_commit (parents = [second ], vulnerability = TestRepository .VulnerabilityType .LIMIT )
152
+ fourth = repo .add_empty_commit (parents = [second ])
153
+ (all_introduced , all_fixed , all_last_affected ,all_limit ) = repo .get_ranges ()
154
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
155
+ all_limit , all_last_affected )
156
+
157
+ expected = set ([first .hex , second .hex ,])
158
+ repo .remove ()
159
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
160
+
161
+ def test_introduced_limit_merge (self ):
162
+
163
+ repo = TestRepository ('test_intoduced_limit_merge' )
164
+
165
+
166
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
167
+ second = repo .add_empty_commit ()
168
+ third = repo .add_empty_commit (parents = [first ,second ])
169
+ fourth = repo .add_empty_commit (parents = [third ], vulnerability = TestRepository .VulnerabilityType .LIMIT )
170
+ (all_introduced , all_fixed , all_last_affected ,all_limit ) = repo .get_ranges ()
171
+
172
+
173
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
174
+ all_limit , all_last_affected )
175
+
176
+ expected = set ([first .hex ,third .hex ])
177
+ repo .remove ()
178
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
179
+
180
+ def test_introduced_limit_two_linear (self ):
181
+
182
+ repo = TestRepository ('test_introduced_limit_two_linear' )
183
+
184
+
185
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
186
+ second = repo .add_empty_commit (parents = [first ], vulnerability = TestRepository .VulnerabilityType .LIMIT )
187
+ third = repo .add_empty_commit (parents = [second ], vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
188
+ fourth = repo .add_empty_commit (parents = [third ], vulnerability = TestRepository .VulnerabilityType .LIMIT )
189
+ (all_introduced , all_fixed , all_last_affected ,all_limit ) = repo .get_ranges ()
190
+
191
+
192
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
193
+ all_limit , all_last_affected )
194
+
195
+ expected = set ([first .hex ,third .hex ])
196
+ repo .remove ()
197
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
198
+
199
+
200
+ ######## 2nd : tests with "introduced" and "last-affected"
201
+
202
+ def test_introduced_last_affected_linear (self ):
203
+
204
+ repo = TestRepository ('test_introduced_last_affected_linear' )
205
+
206
+
207
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
208
+ second = repo .add_empty_commit (parents = [first ])
209
+ third = repo .add_empty_commit (parents = [second ], vulnerability = TestRepository .VulnerabilityType .LAST_AFFECTED )
210
+ (all_introduced , all_fixed , all_last_affected ,all_limit ) = repo .get_ranges ()
211
+
212
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
213
+ all_limit , all_last_affected )
214
+
215
+ expected = set ([first .hex ,second .hex ,third .hex ])
216
+ repo .remove ()
217
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
218
+
219
+ def test_introduced_last_affected_branch_propagation (self ):
220
+
221
+ repo = TestRepository ('test_introduced_last_affected_branch_propagation' )
222
+
223
+
224
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
225
+ second = repo .add_empty_commit (parents = [first ])
226
+ third = repo .add_empty_commit (parents = [second ], vulnerability = TestRepository .VulnerabilityType .LAST_AFFECTED )
227
+ fourth = repo .add_empty_commit (parents = [second ])
228
+ (all_introduced , all_fixed , all_last_affected ,all_limit ) = repo .get_ranges ()
229
+
230
+
231
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
232
+ all_limit , all_last_affected )
233
+
234
+ expected = set ([first .hex ,second .hex ,third .hex ,fourth .hex ])
235
+ repo .remove ()
236
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
237
+
238
+
239
+ def test_introduced_last_affected_merge (self ):
240
+
241
+ repo = TestRepository ('test_introduced_last_affected_merge' )
242
+
243
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
244
+ second = repo .add_empty_commit ()
245
+ third = repo .add_empty_commit (parents = [first ,second ])
246
+ fourth = repo .add_empty_commit (parents = [third ], vulnerability = TestRepository .VulnerabilityType .LAST_AFFECTED )
247
+ (all_introduced , all_fixed , all_last_affected , all_limit ) = repo .get_ranges ()
248
+
249
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
250
+ all_limit , all_last_affected )
251
+
252
+ expected = set ([first .hex ,third .hex ,fourth .hex ])
253
+ repo .remove ()
254
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
255
+
256
+ def test_introduced_last_affected_two_linear (self ):
257
+
258
+ repo = TestRepository ('test_introduced_last_affected_two_linear' )
259
+
260
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
261
+ second = repo .add_empty_commit (parents = [first ], vulnerability = TestRepository .VulnerabilityType .LAST_AFFECTED )
262
+ third = repo .add_empty_commit (parents = [second ], vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
263
+ fourth = repo .add_empty_commit (parents = [third ], vulnerability = TestRepository .VulnerabilityType .LAST_AFFECTED )
264
+
265
+ (all_introduced , all_fixed , all_last_affected , all_limit ) = repo .get_ranges ()
266
+
267
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
268
+ all_limit , all_last_affected )
269
+
270
+ expected = set ([first .hex ,second .hex ,third .hex ,fourth .hex ])
271
+ repo .remove ()
272
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
273
+
274
+
275
+ ######## 3nd : tests with "introduced", "limit", and "fixed"
276
+
277
+ def test_introduced_limit_fixed_linear_lf (self ):
278
+
279
+ repo = TestRepository ('test_introduced_limit_fixed_linear_lf' )
280
+
281
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
282
+ second = repo .add_empty_commit (parents = [first ], vulnerability = TestRepository .VulnerabilityType .LIMIT )
283
+ third = repo .add_empty_commit (parents = [second ], vulnerability = TestRepository .VulnerabilityType .FIXED )
284
+
285
+ (all_introduced , all_fixed , all_last_affected , all_limit ) = repo .get_ranges ()
286
+
287
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
288
+ all_limit , all_last_affected )
289
+
290
+ expected = set ([first .hex ])
291
+ repo .remove ()
292
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
293
+
294
+ def test_introduced_limit_fixed_linear_fl (self ):
295
+
296
+ repo = TestRepository ('test_introduced_limit_fixed_linear_lf' )
297
+
298
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
299
+ second = repo .add_empty_commit (parents = [first ], vulnerability = TestRepository .VulnerabilityType .FIXED )
300
+ third = repo .add_empty_commit (parents = [second ], vulnerability = TestRepository .VulnerabilityType .LIMIT )
301
+
302
+ (all_introduced , all_fixed , all_last_affected , all_limit ) = repo .get_ranges ()
303
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
304
+ all_limit , all_last_affected )
305
+
306
+ expected = set ([first .hex ])
307
+ repo .remove ()
308
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
309
+
310
+ def test_introduced_limit_branch_limit (self ):
311
+
312
+ repo = TestRepository ('test_introduced_limit_fixed_linear_lf' ,debug = True )
313
+
314
+ first = repo .add_empty_commit (vulnerability = TestRepository .VulnerabilityType .INTRODUCED )
315
+ second = repo .add_empty_commit (parents = [first ], vulnerability = TestRepository .VulnerabilityType .LIMIT )
316
+ third = repo .add_empty_commit (parents = [first ])
317
+ fourth = repo .add_empty_commit (parents = [second ], vulnerability = TestRepository .VulnerabilityType .FIXED )
318
+
319
+ (all_introduced , all_fixed , all_last_affected , all_limit ) = repo .get_ranges ()
320
+ print ("all_introduced" ,all_introduced )
321
+ print ("all_last_affected" ,all_last_affected )
322
+ result = self .__repo_analyzer .get_affected (repo .repo , all_introduced , all_fixed ,
323
+ all_limit , all_last_affected )
324
+
325
+ expected = set ([first .hex ])
326
+ repo .remove ()
327
+ self .assertEqual (result .commits , expected , "Expected: %s, got: %s" % (expected , result .commits ))
328
+
0 commit comments