Skip to content

Commit

Permalink
test(test/lib.rs)!: Add more crossplatform tests
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Last commit changed the argument types of the SE API
  • Loading branch information
kanav99 committed Apr 7, 2021
1 parent 02a131b commit 42f4f2a
Showing 1 changed file with 321 additions and 1 deletion.
322 changes: 321 additions & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
use rand::{self, seq::SliceRandom, Rng};
use self_encryption::{
test_helpers::{new_test_rng, random_bytes, SimpleStorage},
DataMap, SelfEncryptionError, SelfEncryptor, MAX_CHUNK_SIZE,
ChunkDetails, DataMap, SelfEncryptionError, SelfEncryptor, MAX_CHUNK_SIZE,
};

const DATA_SIZE: usize = 20 * 1024 * 1024;
Expand Down Expand Up @@ -410,3 +410,323 @@ async fn cross_platform_check() {
assert_eq!(&EXPECTED_HASHES[i][..], &chunks[i].hash[..]);
}
}

#[tokio::test]
async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
let storage = SimpleStorage::new();
let se = SelfEncryptor::new(storage, DataMap::None)?;
let content_size: usize = 20 * 1024 * 1024 + 100;
let mut content = vec![0u8; content_size];
for (i, c) in content.iter_mut().enumerate().take(content_size) {
*c = (i % 17) as u8;
}
se.write(&content, 0).await?;
let (dm, _) = se.close().await?;
// update data map when algorithm changes
let ref_datamap = vec![
ChunkDetails {
pre_hash: [
219, 177, 84, 234, 189, 172, 82, 64, 169, 100, 5, 56, 3, 43, 142, 126, 51, 235,
194, 243, 30, 130, 132, 197, 137, 36, 170, 62, 46, 44, 176, 201,
]
.to_vec(),
hash: [
248, 130, 126, 24, 65, 196, 21, 116, 150, 177, 242, 95, 221, 83, 149, 182, 190,
205, 67, 23, 123, 71, 198, 217, 210, 26, 108, 104, 226, 20, 218, 64,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
65, 81, 63, 82, 119, 126, 216, 9, 44, 18, 160, 174, 225, 8, 202, 32, 245, 140, 14,
169, 252, 209, 97, 96, 134, 165, 102, 106, 250, 196, 27, 70,
]
.to_vec(),
hash: [
18, 159, 244, 105, 187, 191, 246, 249, 87, 141, 67, 211, 58, 66, 134, 255, 150,
208, 180, 171, 192, 111, 29, 186, 91, 148, 231, 45, 113, 105, 136, 202,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
80, 237, 26, 5, 69, 59, 53, 210, 44, 236, 191, 69, 92, 39, 113, 124, 206, 169, 5,
126, 189, 2, 146, 80, 68, 186, 142, 219, 37, 170, 135, 61,
]
.to_vec(),
hash: [
122, 136, 131, 108, 167, 36, 157, 132, 244, 145, 104, 32, 217, 12, 238, 220, 110,
27, 50, 152, 172, 17, 66, 223, 251, 25, 212, 94, 142, 110, 132, 203,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
168, 223, 46, 4, 138, 115, 226, 112, 179, 67, 36, 186, 170, 199, 21, 195, 41, 17,
99, 227, 30, 226, 46, 42, 78, 210, 189, 107, 185, 167, 32, 74,
]
.to_vec(),
hash: [
95, 101, 4, 248, 190, 107, 61, 100, 154, 28, 217, 156, 80, 177, 100, 62, 205, 98,
84, 234, 177, 29, 202, 153, 165, 201, 220, 48, 137, 69, 114, 30,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
41, 137, 66, 160, 103, 223, 72, 133, 180, 83, 8, 139, 180, 108, 20, 196, 106, 59,
73, 6, 160, 187, 8, 16, 93, 157, 142, 155, 85, 118, 239, 192,
]
.to_vec(),
hash: [
229, 205, 229, 159, 248, 80, 166, 205, 17, 198, 25, 160, 92, 222, 124, 245, 174,
115, 130, 228, 117, 211, 61, 253, 82, 36, 197, 67, 106, 60, 33, 210,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
48, 226, 1, 203, 69, 49, 140, 152, 90, 232, 209, 42, 178, 241, 60, 11, 24, 2, 196,
26, 14, 229, 127, 68, 119, 116, 135, 195, 248, 217, 227, 78,
]
.to_vec(),
hash: [
72, 114, 190, 123, 137, 144, 19, 58, 46, 98, 42, 42, 32, 22, 250, 239, 40, 191, 85,
193, 248, 243, 119, 35, 205, 131, 97, 106, 141, 241, 149, 245,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
92, 201, 208, 153, 241, 202, 111, 28, 118, 47, 47, 32, 121, 48, 203, 48, 230, 107,
102, 195, 184, 106, 245, 173, 157, 171, 139, 50, 28, 56, 80, 225,
]
.to_vec(),
hash: [
57, 85, 13, 143, 39, 227, 226, 221, 59, 104, 169, 74, 10, 232, 242, 131, 220, 126,
4, 85, 84, 43, 81, 102, 148, 97, 165, 37, 118, 56, 189, 192,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
50, 8, 67, 204, 158, 4, 255, 227, 50, 18, 176, 150, 249, 233, 188, 72, 86, 217, 61,
100, 161, 131, 124, 26, 245, 166, 44, 16, 125, 230, 153, 190,
]
.to_vec(),
hash: [
93, 249, 109, 233, 188, 240, 18, 231, 63, 202, 255, 90, 160, 31, 54, 191, 36, 85,
75, 29, 84, 141, 204, 112, 254, 11, 116, 129, 63, 15, 2, 66,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
132, 6, 224, 90, 168, 59, 66, 114, 199, 67, 140, 171, 226, 213, 141, 21, 32, 143,
4, 192, 143, 64, 253, 216, 200, 76, 162, 121, 130, 169, 89, 229,
]
.to_vec(),
hash: [
56, 110, 198, 24, 230, 120, 195, 219, 227, 31, 129, 221, 182, 202, 3, 146, 2, 223,
67, 21, 114, 84, 65, 108, 18, 235, 239, 62, 175, 220, 138, 201,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
238, 37, 229, 233, 96, 228, 150, 41, 89, 130, 145, 198, 50, 165, 207, 108, 15, 167,
122, 116, 209, 223, 68, 203, 24, 169, 74, 93, 44, 170, 24, 233,
]
.to_vec(),
hash: [
176, 75, 146, 134, 244, 24, 27, 63, 160, 231, 223, 50, 124, 237, 115, 200, 213, 88,
148, 205, 98, 22, 69, 146, 11, 228, 82, 29, 170, 82, 110, 45,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
70, 131, 32, 243, 131, 152, 215, 108, 51, 231, 184, 113, 117, 8, 164, 174, 151,
152, 232, 29, 11, 58, 104, 46, 55, 81, 249, 207, 213, 77, 151, 237,
]
.to_vec(),
hash: [
184, 133, 215, 104, 56, 111, 160, 119, 201, 247, 23, 236, 92, 28, 171, 221, 79,
232, 237, 159, 27, 19, 177, 176, 15, 23, 161, 163, 66, 159, 242, 210,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
50, 175, 184, 213, 76, 189, 138, 227, 190, 200, 141, 26, 235, 78, 173, 171, 137,
95, 43, 119, 8, 145, 253, 102, 189, 117, 247, 89, 246, 214, 129, 182,
]
.to_vec(),
hash: [
49, 232, 225, 31, 240, 54, 141, 164, 15, 217, 164, 149, 222, 144, 11, 59, 134, 214,
126, 179, 105, 30, 190, 131, 89, 27, 240, 190, 124, 226, 198, 150,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
160, 175, 104, 136, 24, 18, 192, 185, 147, 31, 227, 81, 212, 143, 214, 63, 52, 62,
218, 48, 35, 220, 0, 184, 62, 137, 152, 35, 144, 149, 229, 86,
]
.to_vec(),
hash: [
17, 219, 169, 42, 190, 205, 249, 126, 131, 68, 38, 223, 73, 115, 93, 112, 62, 36,
183, 193, 140, 224, 55, 194, 89, 227, 69, 129, 251, 109, 214, 53,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
158, 201, 252, 234, 200, 107, 72, 126, 69, 234, 165, 203, 122, 90, 36, 46, 82, 183,
61, 84, 128, 62, 118, 112, 222, 74, 164, 198, 20, 217, 96, 143,
]
.to_vec(),
hash: [
165, 173, 226, 206, 228, 178, 246, 235, 26, 163, 155, 125, 0, 205, 205, 36, 64, 86,
234, 222, 69, 114, 119, 7, 12, 196, 25, 126, 193, 205, 60, 114,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
208, 35, 197, 158, 225, 12, 21, 130, 132, 59, 227, 65, 238, 178, 232, 169, 186, 48,
27, 106, 153, 46, 168, 196, 199, 70, 105, 236, 161, 167, 109, 43,
]
.to_vec(),
hash: [
1, 63, 38, 182, 193, 210, 99, 152, 89, 107, 90, 17, 230, 73, 159, 81, 102, 57, 247,
106, 68, 225, 33, 192, 209, 0, 196, 53, 242, 35, 108, 96,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
191, 47, 52, 224, 196, 196, 113, 118, 243, 7, 35, 213, 174, 114, 228, 229, 165,
182, 217, 102, 55, 16, 174, 159, 197, 166, 75, 192, 182, 186, 173, 1,
]
.to_vec(),
hash: [
23, 162, 40, 30, 19, 91, 183, 249, 44, 142, 229, 130, 88, 59, 48, 115, 117, 210,
223, 201, 112, 61, 114, 209, 96, 133, 128, 150, 33, 234, 92, 67,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
116, 242, 114, 183, 140, 120, 52, 135, 104, 100, 112, 208, 10, 8, 99, 108, 78, 75,
84, 111, 100, 57, 241, 143, 117, 172, 80, 19, 43, 142, 225, 227,
]
.to_vec(),
hash: [
177, 48, 239, 237, 6, 81, 178, 34, 44, 125, 146, 74, 170, 12, 72, 237, 128, 157,
43, 20, 70, 35, 246, 95, 240, 124, 236, 50, 211, 28, 253, 13,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
219, 177, 84, 234, 189, 172, 82, 64, 169, 100, 5, 56, 3, 43, 142, 126, 51, 235,
194, 243, 30, 130, 132, 197, 137, 36, 170, 62, 46, 44, 176, 201,
]
.to_vec(),
hash: [
75, 61, 6, 107, 79, 230, 247, 5, 216, 162, 59, 66, 230, 241, 190, 226, 105, 185,
20, 191, 117, 79, 150, 152, 104, 202, 109, 124, 142, 177, 167, 23,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
65, 81, 63, 82, 119, 126, 216, 9, 44, 18, 160, 174, 225, 8, 202, 32, 245, 140, 14,
169, 252, 209, 97, 96, 134, 165, 102, 106, 250, 196, 27, 70,
]
.to_vec(),
hash: [
18, 159, 244, 105, 187, 191, 246, 249, 87, 141, 67, 211, 58, 66, 134, 255, 150,
208, 180, 171, 192, 111, 29, 186, 91, 148, 231, 45, 113, 105, 136, 202,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
116, 92, 235, 203, 212, 105, 193, 148, 115, 246, 87, 227, 218, 75, 65, 238, 163,
237, 235, 125, 249, 153, 21, 52, 162, 96, 47, 150, 30, 182, 208, 112,
]
.to_vec(),
hash: [
42, 242, 254, 92, 95, 88, 84, 152, 206, 210, 173, 147, 63, 233, 12, 97, 179, 180,
180, 161, 15, 55, 241, 163, 79, 123, 64, 234, 13, 157, 247, 100,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
ChunkDetails {
pre_hash: [
214, 134, 86, 55, 215, 215, 208, 242, 178, 120, 200, 12, 212, 89, 92, 11, 93, 199,
19, 166, 63, 134, 155, 51, 34, 171, 194, 220, 249, 78, 72, 22,
]
.to_vec(),
hash: [
11, 138, 109, 122, 129, 132, 242, 156, 53, 48, 249, 168, 40, 130, 114, 195, 224,
98, 246, 23, 129, 45, 220, 242, 140, 12, 168, 65, 234, 0, 40, 11,
]
.to_vec(),
chunk_num: 0,
source_size: 0,
},
];
match dm {
DataMap::Content(_) | DataMap::None => panic!("Should be chunks!"),
DataMap::Chunks(chunks) => {
for (i, c) in chunks.into_iter().enumerate() {
assert_eq!(c.pre_hash, ref_datamap[i].pre_hash);
assert_eq!(c.hash, ref_datamap[i].hash);
}
}
};
Ok(())
}

0 comments on commit 42f4f2a

Please sign in to comment.