1#!/usr/bin/perl 2# Test "sha1sum". 3 4# Copyright (C) 2000-2023 Free Software Foundation, Inc. 5 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19use strict; 20 21my $prog = 'sha1sum'; 22 23# Turn off localization of executable's output. 24@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; 25 26my $sha_degenerate = "da39a3ee5e6b4b0d3255bfef95601890afd80709"; 27 28my @Tests = 29 ( 30 ['s1', {IN=> {f=> ''}}, 31 {OUT=>"$sha_degenerate f\n"}], 32 ['s2', {IN=> {f=> 'a'}}, 33 {OUT=>"86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 f\n"}], 34 ['s3', {IN=> {f=> 'abc'}}, 35 {OUT=>"a9993e364706816aba3e25717850c26c9cd0d89d f\n"}], 36 ['s4', 37 {IN=> {f=> 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'}}, 38 {OUT=>"84983e441c3bd26ebaae4aa1f95129e5e54670f1 f\n"}], 39 ['s5', {IN=> {f=> 'abcdefghijklmnopqrstuvwxyz'}}, 40 {OUT=>"32d10c7b8cf96570ca04ce37f2a19d84240d3a89 f\n"}], 41 ['s6', {IN=> {f=> join ('', 'A'..'Z', 'a'..'z', '0'..'9')}}, 42 {OUT=>"761c457bf73b14d27e9e9265c46f4b4dda11f940 f\n"}], 43 ['s7', {IN=> {f=> '1234567890' x 8}}, 44 {OUT=>"50abf5706a150990a08b2c5ea40fa0e585554732 f\n"}], 45 ['million-a', {IN=> {f=> 'a' x 1000000}}, 46 {OUT=>"34aa973cd4c4daa4f61eeb2bdbad27316534016f f\n"}], 47 ['bs-sha-1', {IN=> {".\nfoo"=> ''}}, 48 {OUT=>"\\$sha_degenerate .\\nfoo\n"}], 49 ['bs-sha-2', {IN=> {".\\foo"=> ''}}, 50 {OUT=>"\\$sha_degenerate .\\\\foo\n"}], 51 ['bs-sha-3', {IN=> {".\rfoo"=> ''}}, 52 {OUT=>"\\$sha_degenerate .\\rfoo\n"}], 53 # The sha1sum and md5sum drivers share a lot of code. 54 # Ensure that sha1sum does *not* share the part that makes 55 # md5sum accept BSD format. 56 ['check-bsd', '--check', {IN=> {'f.md5' => "MD5 (f) = $sha_degenerate\n"}}, 57 {AUX=> {f=> ''}}, 58 {ERR=>"sha1sum: f.md5: no properly formatted " 59 . "checksum lines found\n"}, 60 {EXIT=> 1}], 61 ['check-bsd2', '--check', 62 {IN=> {'f.sha1' => "SHA1 (f) = $sha_degenerate\n"}}, 63 {AUX=> {f=> ''}}, {OUT=>"f: OK\n"}], 64 ['check-bsd3', '--check', '--status', 65 {IN=> {'f.sha1' => "SHA1 (f) = $sha_degenerate\n"}}, 66 {AUX=> {f=> 'bar'}}, {EXIT=> 1}], 67 ['check-openssl', '--check', 68 {IN=> {'f.md5' => "MD5(f)= $sha_degenerate\n"}}, 69 {AUX=> {f=> ''}}, 70 {ERR=>"sha1sum: f.md5: no properly formatted " 71 . "checksum lines found\n"}, 72 {EXIT=> 1}], 73 ['check-openssl2', '--check', 74 {IN=> {'f.sha1' => "SHA1(f)= $sha_degenerate\n"}}, 75 {AUX=> {f=> ''}}, {OUT=>"f: OK\n"}], 76 ['check-openssl3', '--check', '--status', 77 {IN=> {'f.sha1' => "SHA1(f)= $sha_degenerate\n"}}, 78 {AUX=> {f=> 'bar'}}, {EXIT=> 1}], 79 ['bsd-segv', '--check', {IN=> {'z' => "SHA1 ("}}, {EXIT=> 1}, 80 {ERR=> "$prog: z: no properly formatted checksum lines found\n"}], 81 ); 82 83# Insert the '--text' argument for each test. 84my $t; 85foreach $t (@Tests) 86 { 87 splice @$t, 1, 0, '--text' unless @$t[1] =~ /--check/; 88 } 89 90my $save_temps = $ENV{DEBUG}; 91my $verbose = $ENV{VERBOSE}; 92 93my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); 94exit $fail; 95