-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: check base's read permission in module
config
Signed-off-by: Gaoyang Zhang <[email protected]>
- Loading branch information
Showing
2 changed files
with
70 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -798,6 +798,8 @@ impl LocalGroup { | |
/// 3. Wrong type of existing [`target`] path | ||
/// 4. Path to [`target`] contains readonly parent directory | ||
/// | ||
/// 5. Base is unreadable | ||
/// | ||
/// [group name]: LocalGroup::name | ||
/// [`base`]: LocalGroup::base | ||
/// [`target`]: LocalGroup::target | ||
|
@@ -872,6 +874,15 @@ impl LocalGroup { | |
// 1-4 | ||
self._validate_with_fs_query()?; | ||
|
||
// 5. Base is unreadable | ||
if self.base.exists() { | ||
// Check read permission of `base` | ||
if let Err(e) = std::fs::read_dir(&self.base) { | ||
log::error!("Could not read base '{}'", self.base.display()); | ||
return Err(e.into()); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
@@ -1549,6 +1560,65 @@ target = "{}" | |
)) | ||
} | ||
} | ||
|
||
#[test] | ||
fn base_unreadable() -> Result<(), Report> { | ||
let base = prepare_file( | ||
get_testroot().join("base_unreadable").join("base-but-file"), | ||
0o311, | ||
)?; | ||
if let Err(err) = DTConfig::from_str(&format!( | ||
r#" | ||
[[local]] | ||
name = "base unreadable (not a directory)" | ||
base = "{}" | ||
sources = [] | ||
target = ".""#, | ||
base.display(), | ||
)) { | ||
assert_eq!( | ||
err, | ||
AppError::IoError("Not a directory (os error 20)".to_owned(),), | ||
"{}", | ||
err, | ||
); | ||
} else { | ||
return Err(eyre!( | ||
"This config should not be loaded because base is not a directory", | ||
)); | ||
} | ||
|
||
let base = prepare_directory( | ||
get_testroot() | ||
.join("base_unreadable") | ||
.join("base-unreadable"), | ||
0o311, | ||
)?; | ||
if let Err(err) = DTConfig::from_str(&format!( | ||
r#" | ||
[[local]] | ||
name = "base unreadable (permission denied)" | ||
base = "{}" | ||
sources = [] | ||
target = ".""#, | ||
base.display(), | ||
)) { | ||
assert_eq!( | ||
err, | ||
AppError::IoError( | ||
"Permission denied (os error 13)".to_owned(), | ||
), | ||
"{}", | ||
err, | ||
); | ||
} else { | ||
return Err(eyre!( | ||
"This config should not be loaded because insufficient permissions to base", | ||
)); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
// Author: Blurgy <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters