@@ -10,29 +10,55 @@ import (
10
10
)
11
11
12
12
func TestGetThreshholdForScan (t * testing.T ) {
13
- t .Run ("returns zero threshold for scans without matching labels " , func (t * testing.T ) {
13
+ t .Run ("returns zero threshold for scans without deduplication annotation " , func (t * testing.T ) {
14
14
scan := executionv1.Scan {
15
15
ObjectMeta : metav1.ObjectMeta {
16
- Labels : map [string ]string {
17
- "foo " : "bar " ,
16
+ Annotations : map [string ]string {
17
+ "irrelevant annotation " : "... " ,
18
18
},
19
19
},
20
20
}
21
- threshold := GetThreshholdForScan (scan )
21
+ threshold , err := GetThreshholdForScan (scan )
22
+ assert .Nil (t , err )
22
23
assert .Equal (t , 0 * time .Second , threshold )
23
24
})
24
25
25
- t .Run ("returns matchign thresholds for scnas with matching rules threshold for scans without matching labels " , func (t * testing.T ) {
26
+ t .Run ("returns parsed threshold for scans with matching annotation " , func (t * testing.T ) {
26
27
scan := executionv1.Scan {
27
28
ObjectMeta : metav1.ObjectMeta {
28
- Labels : map [string ]string {
29
- "securecodebox.io/hook" : "cascading-scans" ,
30
- "cascading.securecodebox.io/cascading-rule" : "nmap-portscan" ,
31
- "foo" : "bar" ,
29
+ Annotations : map [string ]string {
30
+ "scan-deduplicator.securecodebox.io/min-time-interval" : "24h" ,
32
31
},
33
32
},
34
33
}
35
- threshold := GetThreshholdForScan (scan )
36
- assert .Equal (t , 4 * time .Hour , threshold )
34
+ threshold , err := GetThreshholdForScan (scan )
35
+ assert .Nil (t , err )
36
+ assert .Equal (t , 24 * time .Hour , threshold )
37
+ })
38
+
39
+ t .Run ("returns an error if the threshold is wrongly formatted" , func (t * testing.T ) {
40
+ scan := executionv1.Scan {
41
+ ObjectMeta : metav1.ObjectMeta {
42
+ Annotations : map [string ]string {
43
+ "scan-deduplicator.securecodebox.io/min-time-interval" : "invalid-time-format" ,
44
+ },
45
+ },
46
+ }
47
+ threshold , err := GetThreshholdForScan (scan )
48
+ assert .EqualError (t , err , "error parsing duration: time: invalid duration \" invalid-time-format\" " )
49
+ assert .Equal (t , 0 * time .Second , threshold )
50
+ })
51
+
52
+ t .Run ("returns an error if the threshold is negative" , func (t * testing.T ) {
53
+ scan := executionv1.Scan {
54
+ ObjectMeta : metav1.ObjectMeta {
55
+ Annotations : map [string ]string {
56
+ "scan-deduplicator.securecodebox.io/min-time-interval" : "-24h" ,
57
+ },
58
+ },
59
+ }
60
+ threshold , err := GetThreshholdForScan (scan )
61
+ assert .EqualError (t , err , "threshold must be a positive duration" )
62
+ assert .Equal (t , 0 * time .Second , threshold )
37
63
})
38
64
}
0 commit comments