Skip to content

Commit 5ffcff6

Browse files
committed
cdh: Add test case using mkfsOpts
Add a test case which passes mkfsOpts for mkfs.ext4. Signed-off-by: Manuel Huber <manuelh@nvidia.com>
1 parent e459bb6 commit 5ffcff6

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

  • confidential-data-hub/hub/src/storage/volume_type/blockdevice

confidential-data-hub/hub/src/storage/volume_type/blockdevice/mod.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,50 @@ mod tests {
525525
bd.umount().await.unwrap();
526526
}
527527

528+
#[cfg(feature = "luks2")]
529+
#[tokio::test]
530+
#[rstest]
531+
#[serial]
532+
#[case::integrity("true")]
533+
#[case::no_integrity("false")]
534+
async fn encrypt_an_empty_device_with_mkfs_opts_using_luks2(#[case] integrity: &str) {
535+
let mut temp_device_file = tempfile::NamedTempFile::new().unwrap();
536+
temp_device_file
537+
.as_file_mut()
538+
.write_all(&vec![0; 512 * 1024 * 1024])
539+
.unwrap();
540+
let mut bd = BlockDevice::default();
541+
let device_path = temp_device_file.path().to_string_lossy().to_string();
542+
543+
let options = HashMap::from([
544+
("sourceType".to_string(), "empty".to_string()),
545+
("targetType".to_string(), "fileSystem".to_string()),
546+
("devicePath".to_string(), device_path.clone()),
547+
("encryptionType".to_string(), "luks2".to_string()),
548+
(
549+
"key".to_string(),
550+
"file://./test_files/luks2-disk-passphrase".to_string(),
551+
),
552+
("dataIntegrity".to_string(), integrity.to_string()),
553+
("filesystemType".to_string(), "ext4".to_string()),
554+
(
555+
"mkfsOpts".to_string(),
556+
"-O ^has_journal -m 0 -i 163840 -I 128".to_string(),
557+
),
558+
]);
559+
560+
let tempdir = tempfile::TempDir::new().unwrap();
561+
bd.real_mount(&options, &[], tempdir.path().to_str().unwrap())
562+
.await
563+
.unwrap();
564+
565+
tokio::fs::write(tempdir.path().join("test-file"), b"some data")
566+
.await
567+
.unwrap();
568+
569+
bd.umount().await.unwrap();
570+
}
571+
528572
#[cfg(feature = "luks2")]
529573
#[tokio::test]
530574
#[serial]

0 commit comments

Comments
 (0)