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