Skip to content

Commit

Permalink
Adds: restrict 'screenly_*' names for settings on validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
korvyashka committed Aug 2, 2024
1 parent eedf06d commit 70cae5d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/commands/edge_app_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,30 @@ settings:
assert!(result.is_ok());
}

#[test]
fn test_ensure_manifest_is_valid_when_setting_starts_with_predefined_string_should_fail() {
let dir = tempdir().unwrap();
let file_name = "screenly.yml";
let content = r#"---
syntax: manifest_v1
id: test_app
settings:
screenly_setting:
type: string
default_value: stranger
title: some_setting
optional: true
help_text: An example of a setting that is used in index.html
"#;

let file_path = write_to_tempfile(&dir, file_name, content);
let result = EdgeAppManifest::ensure_manifest_is_valid(&file_path);
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains(
"Setting \"screenly_setting\" cannot start with \"screenly_\""
));
}

#[test]
fn test_save_manifest_to_file_with_is_global_true_should_save_yaml_correctly() {
let dir = tempdir().unwrap();
Expand Down
6 changes: 6 additions & 0 deletions src/commands/edge_app_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ where
setting.name
)));
}
if setting.name.starts_with("screenly_") {
return Err(serde::de::Error::custom(format!(
"Setting \"{}\" cannot start with \"screenly_\"",
setting.name
)));
}
}

settings.sort_by_key(|s| s.name.clone());
Expand Down

0 comments on commit 70cae5d

Please sign in to comment.