File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77//! The configuration is typically loaded from YAML files using the
88//! `load_profile` function.
99
10- use anyhow:: { Context , Ok , Result } ;
10+ use anyhow:: { Context , Ok , Result , bail } ;
1111use camino:: { Utf8Path , Utf8PathBuf } ;
1212use serde:: Deserialize ;
1313use std:: fs:: File ;
@@ -63,6 +63,9 @@ impl Bootstrap {
6363impl Profile {
6464 /// Validate configuration semantics beyond basic deserialization.
6565 pub fn validate ( & self ) -> Result < ( ) > {
66+ if self . dir . exists ( ) && !self . dir . is_dir ( ) {
67+ bail ! ( "dir must be a directory: {}" , self . dir) ;
68+ }
6669 for ( index, provisioner) in self . provisioners . iter ( ) . enumerate ( ) {
6770 provisioner
6871 . validate ( )
Original file line number Diff line number Diff line change @@ -277,6 +277,32 @@ provisioners:
277277 Ok ( ( ) )
278278}
279279
280+ #[ test]
281+ fn test_profile_validation_rejects_dir_file ( ) -> Result < ( ) > {
282+ let dir_file = NamedTempFile :: new ( ) ?;
283+ let mut file = NamedTempFile :: new ( ) ?;
284+ // editorconfig-checker-disable
285+ writeln ! (
286+ file,
287+ r#"---
288+ dir: {}
289+ bootstrap:
290+ type: mmdebstrap
291+ suite: bookworm
292+ target: rootfs.tar.zst
293+ "# ,
294+ dir_file. path( ) . display( )
295+ ) ?;
296+ // editorconfig-checker-enable
297+
298+ let path = Utf8Path :: from_path ( file. path ( ) ) . unwrap ( ) ;
299+ let profile = load_profile ( path) ?;
300+
301+ assert ! ( profile. validate( ) . is_err( ) ) ;
302+
303+ Ok ( ( ) )
304+ }
305+
280306#[ test]
281307fn test_load_profile_resolves_shell_script_relative_to_profile_dir ( ) -> Result < ( ) > {
282308 let temp_dir = tempdir ( ) ?;
You can’t perform that action at this time.
0 commit comments