@@ -50,6 +50,15 @@ def test_validate_checksum_str_sha256_nok(self):
50
50
with self .assertRaises (HashStrNotValidException ):
51
51
validate_checksum_str (invalid_sha256 , "sha256" )
52
52
53
+ def test_validate_checksum_str_sha512_ok (self ):
54
+ valid_sha512 = "d80f94038e28749518984f0a7827530fc272117f952db85d54baa05ea89b6fc6fc9a4059be18c9b8762139404bd43c59e7ad5814ddc0eb73bdc6a6355b16b718"
55
+ self .assertTrue (validate_checksum_str (valid_sha512 , "sha512" ))
56
+
57
+ def test_validate_checksum_str_sha512_nok (self ):
58
+ invalid_sha512 = "d80f94038e28749518984f0a78275x0fc272117f952db85d54baa05ea89b6fc6fc9a4059be18c9b8762139404bd43c59e7ad5814ddc0eb73bdc6a6355b16b718"
59
+ with self .assertRaises (HashStrNotValidException ):
60
+ validate_checksum_str (invalid_sha512 , "sha512" )
61
+
53
62
54
63
class TestGetFileFromStr (TestCase ):
55
64
def test_get_file_path_from_str_ok (self ):
@@ -66,7 +75,7 @@ def test_get_file_path_from_str_nok_not_found(self):
66
75
67
76
68
77
class TestGetFileChecksum (TestCase ):
69
- def test_get_file_checksum_text (self ):
78
+ def test_get_file_checksum_text_md5_true (self ):
70
79
obj = IntegrityValidator (
71
80
str_path = "tests/data/test_file.txt" ,
72
81
checksum_str = "bbe4f28b27120e0a9611d90d242bc656" ,
@@ -76,7 +85,7 @@ def test_get_file_checksum_text(self):
76
85
"bbe4f28b27120e0a9611d90d242bc656" ,
77
86
)
78
87
79
- def test_get_file_checksum_bin (self ):
88
+ def test_get_file_checksum_bin_md5_true (self ):
80
89
obj = IntegrityValidator (
81
90
str_path = "tests/data/test_file.dat" ,
82
91
checksum_str = "0cb988d042a7f28dd5fe2b55b3f5ac7a" ,
@@ -86,6 +95,56 @@ def test_get_file_checksum_bin(self):
86
95
"0cb988d042a7f28dd5fe2b55b3f5ac7a" ,
87
96
)
88
97
98
+ def test_get_file_checksum_text_md5_false (self ):
99
+ obj = IntegrityValidator (
100
+ str_path = "tests/data/test_file.txt" ,
101
+ checksum_str = "bbe4f28b27120e0a9611d90d242bc657" ,
102
+ )
103
+ self .assertNotEqual (
104
+ obj .get_file_checksum ("md5" ),
105
+ "bbe4f28b27120e0a9611d90d242bc657" ,
106
+ )
107
+
108
+ def test_get_file_checksum_bin_sha256_true (self ):
109
+ obj = IntegrityValidator (
110
+ str_path = "tests/data/test_file.dat" ,
111
+ checksum_str = "a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222" ,
112
+ )
113
+ self .assertEqual (
114
+ obj .get_file_checksum ("sha256" ),
115
+ "a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222" ,
116
+ )
117
+
118
+ def test_get_file_checksum_text_sha256_false (self ):
119
+ obj = IntegrityValidator (
120
+ str_path = "tests/data/test_file.txt" ,
121
+ checksum_str = "a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63223" ,
122
+ )
123
+ self .assertNotEqual (
124
+ obj .get_file_checksum ("sha256" ),
125
+ "a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63223" ,
126
+ )
127
+
128
+ def test_get_file_checksum_bin_sha512_true (self ):
129
+ obj = IntegrityValidator (
130
+ str_path = "tests/data/test_file.dat" ,
131
+ checksum_str = "bdd81ab233bceb6ad233cd1871509320a18d0335a891cf98730990e8923e1dda04f3358e9c7e1c3d16b16f408cfafb6af53254ef3023ed2436533808b6ca9933" ,
132
+ )
133
+ self .assertEqual (
134
+ obj .get_file_checksum ("sha512" ),
135
+ "bdd81ab233bceb6ad233cd1871509320a18d0335a891cf98730990e8923e1dda04f3358e9c7e1c3d16b16f408cfafb6af53254ef3023ed2436533808b6ca9933" ,
136
+ )
137
+
138
+ def test_get_file_checksum_text_sha512_false (self ):
139
+ obj = IntegrityValidator (
140
+ str_path = "tests/data/test_file.txt" ,
141
+ checksum_str = "add81ab233bceb6ad233cd1871509320a18d0335a891cf98730990e8923e1dda04f3358e9c7e1c3d16b16f408cfafb6af53254ef3023ed2436533808b6ca9933" ,
142
+ )
143
+ self .assertNotEqual (
144
+ obj .get_file_checksum ("sha512" ),
145
+ "add81ab233bceb6ad233cd1871509320a18d0335a891cf98730990e8923e1dda04f3358e9c7e1c3d16b16f408cfafb6af53254ef3023ed2436533808b6ca9933" ,
146
+ )
147
+
89
148
90
149
class TestValidateFileIntegrity (TestCase ):
91
150
def test_validate_file_integrity_true (self ):
0 commit comments