From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer v2 5/5] auto: add negative tests for root password option
Date: Fri, 29 Nov 2024 13:21:13 +0100 [thread overview]
Message-ID: <20241129122125.1494917-6-c.heiss@proxmox.com> (raw)
In-Reply-To: <20241129122125.1494917-1-c.heiss@proxmox.com>
Extends our "test runner" for the parse-answer tests such that if a test
file ends with ".fail.toml", it is considered a negative test and
expected to fail. The expected error message is stored in the
accompanying <name>.fail.json file.
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Changes v1 -> v2:
* new patch
proxmox-auto-installer/tests/parse-answer.rs | 22 ++++++++++++++++---
.../both-password-and-hashed-set.fail.json | 3 +++
.../both-password-and-hashed-set.fail.toml | 15 +++++++++++++
.../no-root-password-set.fail.json | 3 +++
.../no-root-password-set.fail.toml | 13 +++++++++++
.../parse_answer/short-password.fail.json | 3 +++
.../parse_answer/short-password.fail.toml | 14 ++++++++++++
proxmox-installer-common/src/setup.rs | 6 ++---
8 files changed, 73 insertions(+), 6 deletions(-)
create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/both-password-and-hashed-set.fail.json
create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/both-password-and-hashed-set.fail.toml
create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/no-root-password-set.fail.json
create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/no-root-password-set.fail.toml
create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/short-password.fail.json
create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/short-password.fail.toml
diff --git a/proxmox-auto-installer/tests/parse-answer.rs b/proxmox-auto-installer/tests/parse-answer.rs
index 65f8c1e..57436a2 100644
--- a/proxmox-auto-installer/tests/parse-answer.rs
+++ b/proxmox-auto-installer/tests/parse-answer.rs
@@ -64,11 +64,27 @@ fn test_parse_answers() {
let extension = p.extension().unwrap().to_str().unwrap();
if extension == "toml" {
println!("Test: {name}");
+
let answer = get_answer(p.clone()).unwrap();
- let config =
- &parse_answer(&answer, &udev_info, &runtime_info, &locales, &setup_info).unwrap();
+ let config = parse_answer(&answer, &udev_info, &runtime_info, &locales, &setup_info);
+
+ let config = if name.ends_with(".fail") {
+ let json_path = tests_path.join(format!("{name}.json"));
+ let json_raw = std::fs::read_to_string(json_path).unwrap();
+ let err_json: Value = serde_json::from_str(&json_raw).unwrap();
+
+ assert!(config.is_err());
+ assert_eq!(
+ config.unwrap_err().to_string(),
+ err_json.get("error").unwrap().as_str().unwrap()
+ );
+ continue;
+ } else {
+ config.unwrap()
+ };
+
println!("Selected disks: {:#?}", &config.disk_selection);
- let config_json = serde_json::to_string(config);
+ let config_json = serde_json::to_string(&config);
let config: Value = serde_json::from_str(config_json.unwrap().as_str()).unwrap();
let mut path = tests_path.clone();
path.push(format!("{name}.json"));
diff --git a/proxmox-auto-installer/tests/resources/parse_answer/both-password-and-hashed-set.fail.json b/proxmox-auto-installer/tests/resources/parse_answer/both-password-and-hashed-set.fail.json
new file mode 100644
index 0000000..fd1213e
--- /dev/null
+++ b/proxmox-auto-installer/tests/resources/parse_answer/both-password-and-hashed-set.fail.json
@@ -0,0 +1,3 @@
+{
+ "error": "`global.root_password` and `global.root_password_hashed` cannot be set at the same time"
+}
diff --git a/proxmox-auto-installer/tests/resources/parse_answer/both-password-and-hashed-set.fail.toml b/proxmox-auto-installer/tests/resources/parse_answer/both-password-and-hashed-set.fail.toml
new file mode 100644
index 0000000..0a56fc9
--- /dev/null
+++ b/proxmox-auto-installer/tests/resources/parse_answer/both-password-and-hashed-set.fail.toml
@@ -0,0 +1,15 @@
+[global]
+keyboard = "de"
+country = "at"
+fqdn = "both-password-and-hashed-set.fail.testinstall"
+mailto = "mail@no.invalid"
+timezone = "Europe/Vienna"
+root_password = "12345678"
+root_password_hashed = "$y$j9T$343s9MNhV4xZhW1Be6J6H1$rIxofnXWmp0FQGGIPO3BRwb1jK4ZXWaxT7OjhHJmum0"
+
+[network]
+source = "from-dhcp"
+
+[disk-setup]
+filesystem = "ext4"
+disk_list = ["sda"]
diff --git a/proxmox-auto-installer/tests/resources/parse_answer/no-root-password-set.fail.json b/proxmox-auto-installer/tests/resources/parse_answer/no-root-password-set.fail.json
new file mode 100644
index 0000000..6d75755
--- /dev/null
+++ b/proxmox-auto-installer/tests/resources/parse_answer/no-root-password-set.fail.json
@@ -0,0 +1,3 @@
+{
+ "error": "One of `global.root_password` or `global.root_password_hashed` must be set"
+}
diff --git a/proxmox-auto-installer/tests/resources/parse_answer/no-root-password-set.fail.toml b/proxmox-auto-installer/tests/resources/parse_answer/no-root-password-set.fail.toml
new file mode 100644
index 0000000..454e0b6
--- /dev/null
+++ b/proxmox-auto-installer/tests/resources/parse_answer/no-root-password-set.fail.toml
@@ -0,0 +1,13 @@
+[global]
+keyboard = "de"
+country = "at"
+fqdn = "no-root-password-set.fail.testinstall"
+mailto = "mail@no.invalid"
+timezone = "Europe/Vienna"
+
+[network]
+source = "from-dhcp"
+
+[disk-setup]
+filesystem = "ext4"
+disk_list = ["sda"]
diff --git a/proxmox-auto-installer/tests/resources/parse_answer/short-password.fail.json b/proxmox-auto-installer/tests/resources/parse_answer/short-password.fail.json
new file mode 100644
index 0000000..c424b0b
--- /dev/null
+++ b/proxmox-auto-installer/tests/resources/parse_answer/short-password.fail.json
@@ -0,0 +1,3 @@
+{
+ "error": "`global.root_password` must be at least 8 characters long"
+}
diff --git a/proxmox-auto-installer/tests/resources/parse_answer/short-password.fail.toml b/proxmox-auto-installer/tests/resources/parse_answer/short-password.fail.toml
new file mode 100644
index 0000000..a0eb1ec
--- /dev/null
+++ b/proxmox-auto-installer/tests/resources/parse_answer/short-password.fail.toml
@@ -0,0 +1,14 @@
+[global]
+keyboard = "de"
+country = "at"
+fqdn = "short-password.fail.testinstall"
+mailto = "mail@no.invalid"
+timezone = "Europe/Vienna"
+root_password = "12345"
+
+[network]
+source = "from-dhcp"
+
+[disk-setup]
+filesystem = "ext4"
+disk_list = ["sda"]
diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs
index 4adb168..c8fc118 100644
--- a/proxmox-installer-common/src/setup.rs
+++ b/proxmox-installer-common/src/setup.rs
@@ -463,14 +463,14 @@ impl Interface {
}
}
-#[derive(Clone, Deserialize, Serialize)]
+#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum InstallRootPassword {
Plain(String),
Hashed(String),
}
-#[derive(Clone, Default, Deserialize, Serialize)]
+#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct InstallFirstBootSetup {
#[serde(
serialize_with = "serialize_bool_as_u32",
@@ -501,7 +501,7 @@ pub fn spawn_low_level_installer(test_mode: bool) -> io::Result<process::Child>
}
/// See Proxmox::Install::Config
-#[derive(Deserialize, Serialize)]
+#[derive(Debug, Deserialize, Serialize)]
pub struct InstallConfig {
pub autoreboot: usize,
--
2.47.0
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2024-11-29 12:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-29 12:21 [pve-devel] [PATCH installer/{pve, pmg}-docs/proxmox-backup v2 0/8] raise minimum root password length to 8 characters Christoph Heiss
2024-11-29 12:21 ` [pve-devel] [PATCH installer v2 1/5] proxinstall: " Christoph Heiss
2024-11-29 12:21 ` [pve-devel] [PATCH installer v2 2/5] tui: " Christoph Heiss
2024-11-29 12:21 ` [pve-devel] [PATCH installer v2 3/5] common: convert `InstallRootPassword` into an enum Christoph Heiss
2024-11-29 12:21 ` [pve-devel] [PATCH installer v2 4/5] auto: raise minimum root password length to 8 characters Christoph Heiss
2024-11-29 12:21 ` Christoph Heiss [this message]
2024-11-29 12:21 ` [pve-devel] [PATCH pve-docs v2 6/8] installation: adapt to raised root password length requirement Christoph Heiss
2024-11-29 12:21 ` [pve-devel] [PATCH pmg-docs v2 7/8] " Christoph Heiss
2024-11-29 12:21 ` [pve-devel] [PATCH proxmox-backup v2 8/8] using-the-installer: " Christoph Heiss
2024-12-16 11:12 ` [pve-devel] [PATCH installer/{pve, pmg}-docs/proxmox-backup v2 0/8] raise minimum root password length to 8 characters Christoph Heiss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241129122125.1494917-6-c.heiss@proxmox.com \
--to=c.heiss@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox