-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathtest_types.py
835 lines (540 loc) · 20.4 KB
/
test_types.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
import re
from ipaddress import IPv4Network, IPv6Network
import pytest
from sigma.exceptions import (
SigmaPlaceholderError,
SigmaTypeError,
SigmaValueError,
SigmaRegularExpressionError,
)
from sigma.types import (
CompareOperators,
SigmaBool,
SigmaCasedString,
SigmaCompareExpression,
SigmaFieldReference,
SigmaRegularExpressionFlag,
SigmaString,
Placeholder,
SpecialChars,
SigmaNumber,
SigmaNull,
SigmaRegularExpression,
SigmaQueryExpression,
sigma_type,
SigmaCIDRExpression,
)
@pytest.fixture
def sigma_string():
return SigmaString("*Test*Str\\*ing*")
@pytest.fixture
def empty_sigma_string():
return SigmaString("")
def test_strings_empty():
assert SigmaString().s == tuple()
def test_strings_plain():
assert SigmaString("plain").s == ("plain",)
def test_strings_merge():
s = SigmaString()
s.s = (SpecialChars.WILDCARD_MULTI, "te", "st", SpecialChars.WILDCARD_MULTI)
assert s._merge_strs().s == (
SpecialChars.WILDCARD_MULTI,
"test",
SpecialChars.WILDCARD_MULTI,
)
def test_strings_merge_end():
s = SigmaString()
s.s = (
SpecialChars.WILDCARD_MULTI,
"test",
SpecialChars.WILDCARD_MULTI,
"te",
"st",
"test",
)
assert s._merge_strs().s == (
SpecialChars.WILDCARD_MULTI,
"test",
SpecialChars.WILDCARD_MULTI,
"testtest",
)
def test_strings_merge_start():
s = SigmaString()
s.s = (
"te",
"st",
"test",
SpecialChars.WILDCARD_MULTI,
"test",
SpecialChars.WILDCARD_MULTI,
)
assert s._merge_strs().s == (
"testtest",
SpecialChars.WILDCARD_MULTI,
"test",
SpecialChars.WILDCARD_MULTI,
)
def test_strings_wildcards():
assert SigmaString("wild*cards?contained").s == (
"wild",
SpecialChars.WILDCARD_MULTI,
"cards",
SpecialChars.WILDCARD_SINGLE,
"contained",
)
def test_strings_escaping():
assert SigmaString("escaped\\*\\?\\\\*?").s == (
"escaped*?\\",
SpecialChars.WILDCARD_MULTI,
SpecialChars.WILDCARD_SINGLE,
)
def test_strings_escaping_nonspecial():
assert SigmaString("escaped\\nonspecial").s == ("escaped\\nonspecial",)
def test_strings_escaping_end():
assert SigmaString("finalescape\\").s == ("finalescape\\",)
def test_strings_from_str():
assert SigmaString.from_str("test*string\\\\") == SigmaString("test\\*string\\\\\\\\")
def test_string_placeholders_single():
assert SigmaString("test1%var%test2").insert_placeholders().s == (
"test1",
Placeholder("var"),
"test2",
)
def test_string_placeholders_multi():
assert SigmaString("%start%te*st1%middle%te?st2%end%").insert_placeholders().s == (
Placeholder("start"),
"te",
SpecialChars.WILDCARD_MULTI,
"st1",
Placeholder("middle"),
"te",
SpecialChars.WILDCARD_SINGLE,
"st2",
Placeholder("end"),
)
def test_string_replace_with_placeholder():
assert SigmaString("testx1xfoox1xtest*x2x*bar*x3x").replace_with_placeholder(
re.compile("x\\dx"), "test"
).s == (
"test",
Placeholder("test"),
"foo",
Placeholder("test"),
"test",
SpecialChars.WILDCARD_MULTI,
Placeholder("test"),
SpecialChars.WILDCARD_MULTI,
"bar",
SpecialChars.WILDCARD_MULTI,
Placeholder("test"),
)
def test_string_placeholders_replace():
def callback(p):
yield from ["A", SpecialChars.WILDCARD_MULTI]
assert SigmaString("test%var1%something%var2%end").insert_placeholders().replace_placeholders(
callback
) == [
SigmaString("testAsomethingAend"),
SigmaString("testAsomething*end"),
SigmaString("test*somethingAend"),
SigmaString("test*something*end"),
]
def test_string_placeholders_escape():
assert SigmaString("\\%test1\\%test2\\%%var%\\%test3\\%").insert_placeholders().s == (
"%test1%test2%",
Placeholder("var"),
"%test3%",
)
def test_string_contains_placeholders():
assert SigmaString("test1%var%test2").insert_placeholders().contains_placeholder()
def test_string_contains_placeholders_none():
assert SigmaString("test1test2").insert_placeholders().contains_placeholder() == False
def test_string_contains_placeholders_included():
assert (
SigmaString("test1%var%test2%test%")
.insert_placeholders()
.contains_placeholder(include=["var"])
)
def test_string_contains_placeholders_no_included():
assert (
SigmaString("test1%var%test2%test%")
.insert_placeholders()
.contains_placeholder(include=["other"])
== False
)
def test_string_contains_placeholders_one_excluded():
assert (
SigmaString("test1%var%test2%test%")
.insert_placeholders()
.contains_placeholder(exclude=["var"])
)
def test_string_contains_placeholders_all_excluded():
assert (
SigmaString("test1%var%test2%test%")
.insert_placeholders()
.contains_placeholder(exclude=["var", "test"])
== False
)
def test_strings_equal():
assert SigmaString("test*string") == SigmaString("test*string")
def test_strings_not_equal():
assert SigmaString("test\\*string") != SigmaString("test*string")
def test_strings_equal_str():
assert SigmaString("test*string") == "test*string"
def test_strings_not_equal_str():
assert SigmaString("test\\*string") != "test*string"
def test_strings_equal_invalid_type():
with pytest.raises(NotImplementedError):
SigmaString("123") == 123
def test_strings_startswith_str():
assert SigmaString("foobar").startswith("foo")
def test_strings_startswith_empty():
assert not SigmaString("").startswith("abc")
def test_strings_startswith_special():
assert SigmaString("*foobar").startswith(SpecialChars.WILDCARD_MULTI)
def test_strings_startswith_difftypes():
assert not SigmaString("*foobar").startswith("foo")
def test_strings_endswith_str():
assert SigmaString("foobar").endswith("bar")
def test_strings_endswith_empty():
assert not SigmaString("").endswith("abc")
def test_strings_endswith_special():
assert SigmaString("foobar*").endswith(SpecialChars.WILDCARD_MULTI)
def test_strings_endswith_difftypes():
assert not SigmaString("foobar*").endswith("bar")
def test_strings_contains_special():
assert SigmaString("foo*bar").contains_special()
def test_strings_not_contains_special():
assert not SigmaString("foobar").contains_special()
def test_strings_add_sigmastring():
assert SigmaString("*foo?") + SigmaString("bar*") == SigmaString("*foo?bar*")
def test_strings_add_lstr():
assert "*foo?" + SigmaString("?bar*") == SigmaString("\\*foo\\??bar*")
def test_strings_add_rstr():
assert SigmaString("*foo?") + "?bar*" == SigmaString("*foo?\\?bar\\*")
def test_strings_add_linvalid():
with pytest.raises(TypeError):
123 + SigmaString("foo")
def test_strings_add_rinvalid():
with pytest.raises(TypeError):
SigmaString("foo") + 123
def test_strings_add_lspecial():
assert SpecialChars.WILDCARD_MULTI + SigmaString("foo*") == SigmaString("*foo*")
def test_strings_add_rspecial():
assert SigmaString("*foo") + SpecialChars.WILDCARD_MULTI == SigmaString("*foo*")
def test_strings_to_string():
assert str(SigmaString("test*?")) == "test*?"
def test_strings_with_plain_wildcards_to_string():
plain_s = r"value\*with\?plain*wild?cards"
s = SigmaString(plain_s)
assert s.s == (
"value*with?plain",
SpecialChars.WILDCARD_MULTI,
"wild",
SpecialChars.WILDCARD_SINGLE,
"cards",
)
assert str(s) == plain_s
assert SigmaString(str(s)) == s
def test_strings_with_placeholder_to_string():
assert str(SigmaString("te%var%st").insert_placeholders()) == "te%var%st"
def test_strings_to_plain():
assert SigmaString("test*?").to_plain() == "test*?"
def test_strings_to_bytes():
assert bytes(SigmaString("test*?")) == b"test*?"
def test_strings_len(sigma_string):
assert len(sigma_string) == 14
def test_strings_iter():
assert list(SigmaString("foo*bar")) == [
"f",
"o",
"o",
SpecialChars.WILDCARD_MULTI,
"b",
"a",
"r",
]
def test_strings_convert():
assert SigmaString("foo?\\*bar*").convert(add_escaped="f", filter_chars="o") == "\\f?\\*bar*"
def test_strings_convert_no_multiwildcard():
with pytest.raises(SigmaValueError, match="Multi-character wildcard"):
SigmaString("foo*bar").convert(wildcard_multi=None)
def test_strings_convert_no_singlewildcard():
with pytest.raises(SigmaValueError, match="Single-character wildcard"):
SigmaString("foo?bar").convert(wildcard_single=None)
def test_strings_convert_placeholder():
with pytest.raises(SigmaPlaceholderError, match="unhandled placeholder 'var'"):
SigmaString("foo%var%bar").insert_placeholders().convert()
def test_strings_convert_invalid_part():
s = SigmaString("test")
s.s = ("test", 1)
with pytest.raises(SigmaValueError, match="part of type 'int'"):
s.convert()
def test_strings_to_regex():
s = SigmaString("Test*Special?(Plain)/[\\*\\?]")
assert s.s == (
"Test",
SpecialChars.WILDCARD_MULTI,
"Special",
SpecialChars.WILDCARD_SINGLE,
"(Plain)/[*?]",
)
r = s.to_regex()
assert r.regexp == "Test.*Special.\\(Plain\\)/\\[\\*\\?\\]"
def test_strings_to_regex_with_additional_escape_chars():
s = SigmaString("Test*Special?(Plain)/[\\*\\?]")
r = s.to_regex("/")
assert r.regexp == "Test.*Special.\\(Plain\\)\\/\\[\\*\\?\\]"
def test_string_index(sigma_string):
assert sigma_string[3] == SigmaString("s")
def test_string_index_negative(sigma_string):
assert sigma_string[-1] == SigmaString("*")
def test_string_index_open_start(sigma_string):
assert sigma_string[:3] == SigmaString("*Te")
def test_string_index_slice_without_escaped(sigma_string):
assert sigma_string[3:9] == SigmaString("st*Str")
def test_string_index_slice_with_escaped(sigma_string):
assert sigma_string[3:10] == SigmaString("st*Str\\*")
def test_string_index_slice_start_and_end_in_same_string_part(sigma_string):
assert sigma_string[2:4] == SigmaString("es")
def test_string_index_slice_negative_end(sigma_string):
assert sigma_string[3:-1] == SigmaString("st*Str\\*ing")
def test_string_index_slice_cut_first_and_last(sigma_string):
assert sigma_string[1:-1] == SigmaString("Test*Str\\*ing")
def test_empty_string_index_slice_cut_first_and_last(empty_sigma_string):
assert empty_sigma_string[1:-1] == SigmaString("")
def test_string_index_slice_negative_start_and_end(sigma_string):
assert sigma_string[-3:-1] == SigmaString("ng")
def test_string_index_slice_open_end_with_escaped(sigma_string):
assert sigma_string[9:] == SigmaString("\\*ing*")
def test_string_index_slice_open_end_without_escaped(sigma_string):
assert sigma_string[10:] == SigmaString("ing*")
def test_string_index_slice_empty_result(sigma_string):
assert sigma_string[4:2] == SigmaString("")
def test_string_index_slice_start_after_end(sigma_string):
assert sigma_string[100:] == SigmaString("")
def test_string_index_slice_open_start_negative_end(sigma_string):
assert sigma_string[:-1] == SigmaString("*Test*Str\\*ing")
def test_string_index_invalid_type(sigma_string):
with pytest.raises(TypeError, match="indices must be"):
sigma_string["invalid"]
def test_string_index_slice_with_step(sigma_string):
with pytest.raises(IndexError, match="slice index with step"):
sigma_string[2:8:2]
def test_string_iter_parts(sigma_string):
assert list(sigma_string.iter_parts()) == [
SpecialChars.WILDCARD_MULTI,
"Test",
SpecialChars.WILDCARD_MULTI,
"Str*ing",
SpecialChars.WILDCARD_MULTI,
]
def test_string_map_parts(sigma_string):
assert sigma_string.map_parts(lambda x: x.upper(), lambda x: isinstance(x, str)).s == (
SpecialChars.WILDCARD_MULTI,
"TEST",
SpecialChars.WILDCARD_MULTI,
"STR*ING",
SpecialChars.WILDCARD_MULTI,
)
def test_string_map_parts_interpret_special(sigma_string):
assert sigma_string.map_parts(lambda x: x.upper(), lambda x: isinstance(x, str), True).s == (
SpecialChars.WILDCARD_MULTI,
"TEST",
SpecialChars.WILDCARD_MULTI,
"STR",
SpecialChars.WILDCARD_MULTI,
"ING",
SpecialChars.WILDCARD_MULTI,
)
def test_cased_string(sigma_string):
assert SigmaCasedString.from_sigma_string(sigma_string) == SigmaCasedString("*Test*Str\\*ing*")
def test_number_int():
assert SigmaNumber(123).number == 123
def test_number_float():
assert SigmaNumber(12.34).number == 12.34
def test_number_to_plain():
assert SigmaNumber(123).to_plain() == 123
def test_number_equal():
assert SigmaNumber(123) == SigmaNumber(123)
def test_number_not_equal():
assert SigmaNumber(123) != SigmaNumber(456)
def test_number_equal_plain():
assert SigmaNumber(123) == 123
def test_number_not_equal_plain():
assert SigmaNumber(123) != 456
def test_number_equal_wrong_type():
with pytest.raises(NotImplementedError, match="SigmaNumber can only be compared"):
SigmaNumber(123) == "123"
def test_number_invalid():
with pytest.raises(SigmaValueError):
SigmaNumber("test")
def test_field_reference():
assert SigmaFieldReference("field").field == "field"
def test_re():
assert SigmaRegularExpression("test.*")
def test_re_flags():
r = SigmaRegularExpression("test.*", {flag for flag in SigmaRegularExpressionFlag})
assert len(r.flags) == len(SigmaRegularExpressionFlag)
def test_re_add_flags():
r = SigmaRegularExpression("test.*")
r.add_flag(SigmaRegularExpressionFlag.IGNORECASE)
assert r.flags == {SigmaRegularExpressionFlag.IGNORECASE}
def test_re_to_plain():
assert SigmaRegularExpression("test.*").to_plain() == "test.*"
def test_re_to_plain_trailing_backslash():
assert SigmaRegularExpression("test\\\\").to_plain() == "test\\\\"
def test_re_invalid():
with pytest.raises(SigmaRegularExpressionError):
SigmaRegularExpression("(test.*")
def test_re_escape():
assert (
SigmaRegularExpression("foo\\d+bar-test").escape(("foo", "-", "t"), "\\")
== "\\foo\\\\d+bar\\-\\tes\\t"
)
def test_re_escape_without_escape():
assert (
SigmaRegularExpression("foo\\d+bar-test").escape(("foo", "-", "t"), "\\", False)
== "\\foo\\d+bar\\-\\tes\\t"
)
def test_re_escape_with_escape_escape_char_param():
# See issue #153 https://github.com/SigmaHQ/pySigma/issues/153
assert (
SigmaRegularExpression("bitsadmin\\.exe").escape(escape_escape_char=True)
== "bitsadmin\\\\.exe"
)
assert (
SigmaRegularExpression("bitsadmin\\.exe").escape(escape_escape_char=False)
== "bitsadmin\\.exe"
)
def test_bool():
assert SigmaBool(True).boolean == True
def test_bool_true_cond():
b = SigmaBool(True)
if b:
assert True
else:
assert False
def test_bool_false_cond():
b = SigmaBool(False)
if b:
assert False
else:
assert True
def test_bool_str():
assert str(SigmaBool(True)) == "True"
def test_bool_to_plain():
assert SigmaBool(True).to_plain() == True
def test_bool_invalid():
with pytest.raises(SigmaTypeError, match="must be a boolean"):
SigmaBool(123)
def test_bool_equal():
assert SigmaBool(True) == SigmaBool(True)
def test_bool_not_equal():
assert SigmaBool(True) != SigmaBool(False)
def test_bool_equal_plain():
assert SigmaBool(True) == True
def test_bool_not_equal_plain():
assert SigmaBool(True) != False
def test_bool_equal_wrong_type():
with pytest.raises(NotImplementedError, match="SigmaBool can only be compared"):
SigmaBool(True) == "True"
def test_null_to_plain():
assert SigmaNull().to_plain() == None
def test_null_equality():
assert SigmaNull() == SigmaNull("foo")
def test_null_inequality():
assert SigmaNull() != SigmaString("foo")
def test_conversion_str():
assert sigma_type("Test") == SigmaString("Test")
def test_conversion_int():
assert sigma_type(123) == SigmaNumber(123)
def test_conversion_float():
assert sigma_type(12.34) == SigmaNumber(12.34)
def test_conversion_bool():
assert sigma_type(True) == SigmaBool(True)
def test_conversion_none():
assert sigma_type(None) == SigmaNull()
def test_query_expression():
assert str(SigmaQueryExpression("test\\test*test?test[]", "id")) == "test\\test*test?test[]"
def test_query_expression_finalize():
assert SigmaQueryExpression("{field} in list({id})", "id").finalize("xxx") == "xxx in list(id)"
def test_query_expression_finalize_nofield_error():
with pytest.raises(SigmaValueError, match="no field was given"):
SigmaQueryExpression("{field} in list({id})", "id").finalize()
def test_query_expression_to_plain():
with pytest.raises(SigmaValueError, match="can't be converted into a plain representation"):
SigmaQueryExpression("test", "id").to_plain()
def test_query_expression_wrong_expr_type():
with pytest.raises(SigmaTypeError, match="must be a string"):
SigmaQueryExpression(123, "id")
def test_query_expression_wrong_id_type():
with pytest.raises(SigmaTypeError, match="must be a string"):
SigmaQueryExpression("123", 123)
def test_cidr_ipv4():
cidr_spec = "192.168.1.0/24"
assert SigmaCIDRExpression(cidr_spec).network == IPv4Network(cidr_spec)
def test_cidr_ipv6():
cidr_spec = "::1/128"
assert SigmaCIDRExpression(cidr_spec).network == IPv6Network(cidr_spec)
def test_cidr_to_plain():
with pytest.raises(SigmaValueError, match="can't be converted into a plain representation"):
SigmaCIDRExpression("192.168.1.0/24").to_plain()
def test_cidr_to_str():
assert str(SigmaCIDRExpression("192.168.1.0/24")) == "192.168.1.0/24"
def test_cidr_invalid():
with pytest.raises(SigmaTypeError, match="Invalid CIDR expression"):
SigmaCIDRExpression("1/132")
def test_cidr_expand_ipv4_0():
assert SigmaCIDRExpression("0.0.0.0/0").expand() == ["*"]
def test_cidr_expand_ipv4_7():
assert SigmaCIDRExpression("10.0.0.0/7").expand() == ["10.*", "11.*"]
def test_cidr_expand_ipv4_8():
assert SigmaCIDRExpression("192.0.0.0/8").expand() == ["192.*"]
def test_cidr_expand_ipv4_14():
assert SigmaCIDRExpression("192.168.0.0/14").expand() == [
"192.168.*",
"192.169.*",
"192.170.*",
"192.171.*",
]
def test_cidr_expand_ipv4_23():
assert SigmaCIDRExpression("192.168.0.0/23").expand() == [
"192.168.0.*",
"192.168.1.*",
]
def test_cidr_expand_ipv4_24():
assert SigmaCIDRExpression("192.168.1.0/24").expand() == ["192.168.1.*"]
def test_cidr_expand_ipv4_31():
assert SigmaCIDRExpression("192.168.1.0/31").expand() == [
"192.168.1.0",
"192.168.1.1",
]
def test_cidr_expand_ipv4_32():
assert SigmaCIDRExpression("192.168.1.1/32").expand() == ["192.168.1.1"]
def test_cidr_expand_ipv6_0():
assert SigmaCIDRExpression("::/0").expand() == ["*"]
def test_cidr_expand_ipv6_56():
assert SigmaCIDRExpression("1234:5678:0:ab00::/56").expand() == ["1234:5678:0:ab*"]
def test_cidr_expand_ipv6_58():
assert SigmaCIDRExpression("1234:5678:0:ab00::/58").expand() == [
"1234:5678:0:ab0*",
"1234:5678:0:ab1*",
"1234:5678:0:ab2*",
"1234:5678:0:ab3*",
]
def test_cidr_expand_ipv6_60():
assert SigmaCIDRExpression("1234:5678:0:ab00::/60").expand() == ["1234:5678:0:ab0*"]
def test_cidr_expand_ipv6_64():
assert SigmaCIDRExpression("1234:5678:0:ab00::/64").expand() == ["1234:5678:0:ab00:*"]
def test_cidr_expand_ipv6_128():
assert SigmaCIDRExpression("::1/128").expand() == ["::1/128"]
def test_cidr_invalid():
with pytest.raises(SigmaTypeError, match="Invalid CIDR expression"):
SigmaCIDRExpression("192.168.1.2/24")
def test_compare_to_plain():
with pytest.raises(SigmaValueError, match="can't be converted into a plain representation"):
SigmaCompareExpression(SigmaNumber(123), CompareOperators.LTE).to_plain()
def test_compare_string():
with pytest.raises(SigmaTypeError, match="expects number"):
SigmaCompareExpression(SigmaString("123"), CompareOperators.LTE).to_plain()