Skip to content

Commit 105e3df

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 105e3df

1 file changed

Lines changed: 46 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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,52 @@ 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(
535+
#[case] integrity: &str,
536+
) {
537+
let mut temp_device_file = tempfile::NamedTempFile::new().unwrap();
538+
temp_device_file
539+
.as_file_mut()
540+
.write_all(&vec![0; 512 * 1024 * 1024])
541+
.unwrap();
542+
let mut bd = BlockDevice::default();
543+
let device_path = temp_device_file.path().to_string_lossy().to_string();
544+
545+
let options = HashMap::from([
546+
("sourceType".to_string(), "empty".to_string()),
547+
("targetType".to_string(), "fileSystem".to_string()),
548+
("devicePath".to_string(), device_path.clone()),
549+
("encryptionType".to_string(), "luks2".to_string()),
550+
(
551+
"key".to_string(),
552+
"file://./test_files/luks2-disk-passphrase".to_string(),
553+
),
554+
("dataIntegrity".to_string(), integrity.to_string()),
555+
("filesystemType".to_string(), "ext4".to_string()),
556+
(
557+
"mkfsOpts".to_string(),
558+
"-O ^has_journal -m 0 -i 163840 -I 128".to_string(),
559+
),
560+
]);
561+
562+
let tempdir = tempfile::TempDir::new().unwrap();
563+
bd.real_mount(&options, &[], tempdir.path().to_str().unwrap())
564+
.await
565+
.unwrap();
566+
567+
tokio::fs::write(tempdir.path().join("test-file"), b"some data")
568+
.await
569+
.unwrap();
570+
571+
bd.umount().await.unwrap();
572+
}
573+
528574
#[cfg(feature = "luks2")]
529575
#[tokio::test]
530576
#[serial]

0 commit comments

Comments
 (0)