From c60c7b9941da3756a0b46130dfa15ad31132dbfa Mon Sep 17 00:00:00 2001 From: Micah Cowan Date: Tue, 11 Nov 2008 12:53:01 -0800 Subject: [PATCH] Test --auth-no-challenge, for URL- and option-specified user/pass. --- tests/ChangeLog | 11 +++++++ tests/HTTPServer.pm | 6 ++-- tests/Test-auth-no-challenge-url.px | 49 ++++++++++++++++++++++++++++ tests/Test-auth-no-challenge.px | 50 +++++++++++++++++++++++++++++ tests/run-px | 2 ++ 5 files changed, 116 insertions(+), 2 deletions(-) create mode 100755 tests/Test-auth-no-challenge-url.px create mode 100755 tests/Test-auth-no-challenge.px diff --git a/tests/ChangeLog b/tests/ChangeLog index 751402d0..e432c35c 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,14 @@ +2008-11-11 Micah Cowan + + * HTTPServer.pm (handle_auth): Allow testing of + --auth-no-challenge. + + * Test-auth-no-challenge.px, Test-auth-no-challenge-url.px: + Added. + + * run-px: Add Test-auth-no-challenge.px, + Test-auth-no-challenge-url.px. + 2008-11-07 Steven Schubiger * run-px: Use some colors for the summary part of the test diff --git a/tests/HTTPServer.pm b/tests/HTTPServer.pm index b76f0985..57b0499f 100644 --- a/tests/HTTPServer.pm +++ b/tests/HTTPServer.pm @@ -144,8 +144,7 @@ sub handle_auth { my $authhdr = $req->header('Authorization'); # Have we sent the challenge yet? - unless (defined $url_rec->{auth_challenged} - && $url_rec->{auth_challenged}) { + unless ($url_rec->{auth_challenged} || $url_rec->{auth_no_challenge}) { # Since we haven't challenged yet, we'd better not # have received authentication (for our testing purposes). if ($authhdr) { @@ -166,6 +165,9 @@ sub handle_auth { # failed it. $code = 400; $msg = "You didn't send auth after I sent challenge"; + if ($url_rec->{auth_no_challenge}) { + $msg = "--auth-no-challenge but no auth sent." + } } else { my ($sent_method) = ($authhdr =~ /^(\S+)/g); unless ($sent_method eq $url_rec->{'auth_method'}) { diff --git a/tests/Test-auth-no-challenge-url.px b/tests/Test-auth-no-challenge-url.px new file mode 100755 index 00000000..53f6245b --- /dev/null +++ b/tests/Test-auth-no-challenge-url.px @@ -0,0 +1,49 @@ +#!/usr/bin/perl -w + +use strict; + +use HTTPTest; + + +############################################################################### + +my $wholefile = "You're all authenticated.\n"; + +# code, msg, headers, content +my %urls = ( + '/needs-auth.txt' => { + auth_no_challenge => 1, + auth_method => 'Basic', + user => 'fiddle-dee-dee', + passwd => 'Dodgson', + code => "200", + msg => "You want fries with that?", + headers => { + "Content-type" => "text/plain", + }, + content => $wholefile, + }, +); + +my $cmdline = $WgetTest::WGETPATH . " --auth-no-challenge " + . "http://fiddle-dee-dee:Dodgson\@localhost:{{port}}/needs-auth.txt"; + +my $expected_error_code = 0; + +my %expected_downloaded_files = ( + 'needs-auth.txt' => { + content => $wholefile, + }, +); + +############################################################################### + +my $the_test = HTTPTest->new (name => "Test-auth-no-challenge-url", + input => \%urls, + cmdline => $cmdline, + errcode => $expected_error_code, + output => \%expected_downloaded_files); +exit $the_test->run(); + +# vim: et ts=4 sw=4 + diff --git a/tests/Test-auth-no-challenge.px b/tests/Test-auth-no-challenge.px new file mode 100755 index 00000000..19b2a6d6 --- /dev/null +++ b/tests/Test-auth-no-challenge.px @@ -0,0 +1,50 @@ +#!/usr/bin/perl -w + +use strict; + +use HTTPTest; + + +############################################################################### + +my $wholefile = "You're all authenticated.\n"; + +# code, msg, headers, content +my %urls = ( + '/needs-auth.txt' => { + auth_no_challenge => 1, + auth_method => 'Basic', + user => 'fiddle-dee-dee', + passwd => 'Dodgson', + code => "200", + msg => "You want fries with that?", + headers => { + "Content-type" => "text/plain", + }, + content => $wholefile, + }, +); + +my $cmdline = $WgetTest::WGETPATH . " --auth-no-challenge" + . " --user=fiddle-dee-dee --password=Dodgson" + . " http://localhost:{{port}}/needs-auth.txt"; + +my $expected_error_code = 0; + +my %expected_downloaded_files = ( + 'needs-auth.txt' => { + content => $wholefile, + }, +); + +############################################################################### + +my $the_test = HTTPTest->new (name => "Test-auth-no-challenge", + input => \%urls, + cmdline => $cmdline, + errcode => $expected_error_code, + output => \%expected_downloaded_files); +exit $the_test->run(); + +# vim: et ts=4 sw=4 + diff --git a/tests/run-px b/tests/run-px index 92e9061e..ef38418c 100755 --- a/tests/run-px +++ b/tests/run-px @@ -12,6 +12,8 @@ my $top_srcdir = shift @ARGV; my @tests = ( 'Test-auth-basic.px', + 'Test-auth-no-challenge.px', + 'Test-auth-no-challenge-url.px', 'Test-proxy-auth-basic.px', 'Test-proxied-https-auth.px', 'Test-N-HTTP-Content-Disposition.px', -- 2.39.2