734417
From 8de0fd45cde4826951842f80b6ce109988d47f4f Mon Sep 17 00:00:00 2001
734417
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
734417
Date: Mon, 7 Apr 2014 12:31:28 +0200
734417
Subject: [PATCH] t/op/crypt.t: Perform SHA-256 algorithm if default one is
734417
 disabled
734417
MIME-Version: 1.0
734417
Content-Type: text/plain; charset=UTF-8
734417
Content-Transfer-Encoding: 8bit
734417
734417
The crypt(3) call may return NULL. This is the case of FIPS-enabled
734417
platforms. Then "salt makes a difference" test would fail.
734417
734417
Signed-off-by: Petr Písař <ppisar@redhat.com>
734417
---
734417
 t/op/crypt.t | 14 ++++++++++----
734417
 1 file changed, 10 insertions(+), 4 deletions(-)
734417
734417
diff --git a/t/op/crypt.t b/t/op/crypt.t
734417
index 27c878f..6c43992 100644
734417
--- a/t/op/crypt.t
734417
+++ b/t/op/crypt.t
734417
@@ -28,19 +28,25 @@ BEGIN {
734417
 # bets, given alternative encryption/hashing schemes like MD5,
734417
 # C2 (or higher) security schemes, and non-UNIX platforms.
734417
 
734417
+# Platforms implementing FIPS mode return undef on weak crypto algorithms.
734417
+my $alg = '';       # Use default algorithm
734417
+if ( !defined(crypt("ab", "cd")) ) {
734417
+    $alg = '$5$';   # Use SHA-256
734417
+}
734417
+
734417
 SKIP: {
734417
 	skip ("VOS crypt ignores salt.", 1) if ($^O eq 'vos');
734417
-	ok(substr(crypt("ab", "cd"), 2) ne substr(crypt("ab", "ce"), 2), "salt makes a difference");
734417
+	ok(substr(crypt("ab", $alg . "cd"), 2) ne substr(crypt("ab", $alg. "ce"), 2), "salt makes a difference");
734417
 }
734417
 
734417
 $a = "a\xFF\x{100}";
734417
 
734417
-eval {$b = crypt($a, "cd")};
734417
+eval {$b = crypt($a, $alg . "cd")};
734417
 like($@, qr/Wide character in crypt/, "wide characters ungood");
734417
 
734417
 chop $a; # throw away the wide character
734417
 
734417
-eval {$b = crypt($a, "cd")};
734417
+eval {$b = crypt($a, $alg . "cd")};
734417
 is($@, '',                   "downgrade to eight bit characters");
734417
-is($b, crypt("a\xFF", "cd"), "downgrade results agree");
734417
+is($b, crypt("a\xFF", $alg . "cd"), "downgrade results agree");
734417
 
734417
-- 
734417
1.9.0
734417