Add a test for 'openssl passwd'
[openssl.git] / test / recipes / 20-test_passwd.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (the "License").  You may not use
5 # this file except in compliance with the License.  You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9
10 use strict;
11 use warnings;
12
13 use OpenSSL::Test;
14
15 setup("test_passwd");
16
17 plan tests => 6;
18
19 ok(compare1stline([qw{openssl passwd password}], '^.{13}\R$'),
20    'crypt password with random salt');
21 ok(compare1stline([qw{openssl passwd -1 password}], '^\$1\$.{8}\$.{22}\R$'),
22    'BSD style MD5 password with random salt');
23 ok(compare1stline([qw{openssl passwd -apr1 password}], '^\$apr1\$.{8}\$.{22}\R$'),
24    'Apache style MD5 password with random salt');
25 ok(compare1stline([qw{openssl passwd -salt xx password}], '^xxj31ZMTZzkVA\R$'),
26    'crypt password with salt xx');
27 ok(compare1stline([qw{openssl passwd -salt xxxxxxxx -1 password}], '^\$1\$xxxxxxxx\$UYCIxa628\.9qXjpQCjM4a\.\R$'),
28    'BSD style MD5 password with salt xxxxxxxx');
29 ok(compare1stline([qw{openssl passwd -salt xxxxxxxx -apr1 password}], '^\$apr1\$xxxxxxxx\$dxHfLAsjHkDRmG83UXe8K0\R$'),
30    'Apache style MD5 password with salt xxxxxxxx');
31
32
33 sub compare1stline {
34     my ($cmdarray, $regexp) = @_;
35     my @lines = run(app($cmdarray), capture => 1);
36
37     return $lines[0] =~ m|$regexp|;
38 }