From fb91aa30c04a7f4c62af2481af7cf8dece1c3df1 Mon Sep 17 00:00:00 2001 From: Emil Miler Date: Wed, 5 Feb 2025 19:29:02 +0100 Subject: [PATCH 1/2] Fix hash comparison The code would try to compare matching hashes with the file path included, always resulting in a failure. This change extracts only the hash itself from the sha256sum output. --- tests/security/vsftpd/lftp.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/security/vsftpd/lftp.pm b/tests/security/vsftpd/lftp.pm index 5fa68a39e76d..e727fbb63b17 100644 --- a/tests/security/vsftpd/lftp.pm +++ b/tests/security/vsftpd/lftp.pm @@ -47,16 +47,16 @@ sub run { assert_script_run('ls | grep f1.txt'); # Compare file hashes - my $hash_orig = script_output("sha256sum $ftp_users_path/$user/$ftp_served_dir/f1.txt"); - my $hash_downloaded = script_output('sha256sum f1.txt'); + my $hash_orig = script_output(qq[sha256sum "$ftp_users_path/$user/$ftp_served_dir/f1.txt" | awk '{print \$1}']); + my $hash_downloaded = script_output(qq[sha256sum f1.txt | awk '{print \$1}']); check_hash($hash_orig, $hash_downloaded); # Check if file has been uploaded assert_script_run("ls $ftp_users_path/$user/$ftp_received_dir | grep f2.txt"); # Compare file hashes - my $hash_created = script_output('sha256sum f2.txt'); - my $hash_uploaded = script_output("sha256sum $ftp_users_path/$user/$ftp_received_dir/f2.txt"); + my $hash_created = script_output(qq[sha256sum f2.txt | awk '{print \$1}']); + my $hash_uploaded = script_output(qq[sha256sum "$ftp_users_path/$user/$ftp_received_dir/f2.txt" | awk '{print \$1}']); check_hash($hash_created, $hash_uploaded); } From 13955d7cbd32028a52fe9f624d92107caf462ac5 Mon Sep 17 00:00:00 2001 From: Emil Miler Date: Thu, 6 Feb 2025 09:20:27 +0100 Subject: [PATCH 2/2] Fail on hash mismatch The logic for hash checking now marks the test as failed, when the hashes do not match, indicating a problem with the transfer, which would otherwise get overlooked. --- tests/security/vsftpd/lftp.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/security/vsftpd/lftp.pm b/tests/security/vsftpd/lftp.pm index e727fbb63b17..d34597b6f4dc 100644 --- a/tests/security/vsftpd/lftp.pm +++ b/tests/security/vsftpd/lftp.pm @@ -13,8 +13,18 @@ use utils; sub check_hash { my ($expected_hash, $calculated_hash) = @_; - my $message = ($expected_hash eq $calculated_hash) ? "Pass: Hash values matched" : "Error: Hash values did not match. Expected: $expected_hash, Got: $calculated_hash"; - record_info($message); + my $message; + my $result; + + if ($expected_hash eq $calculated_hash) { + $message = 'Pass: Hash values matched'; + $result = 'ok'; + } else { + $message = "Error: Hash values did not match. Expected: $expected_hash, Got: $calculated_hash"; + $result = 'fail'; + } + + record_info('Hash Check', $message, result => $result); } sub run {