Skip to content

Commit

Permalink
Bug 1851398: Allow testserver.pl to work with self-signed certs
Browse files Browse the repository at this point in the history
  • Loading branch information
justdave committed Sep 4, 2023
1 parent b225ae9 commit 07dce0b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions testserver.pl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
eval "require LWP; require LWP::UserAgent;";
my $lwp = $@ ? 0 : 1;

if ((@ARGV != 1) || ($ARGV[0] !~ /^https?:/)) {
print "Usage: $0 <URL to this Bugzilla installation>\n";
if ((@ARGV < 1) || (@ARGV > 2) || ($ARGV[0] !~ /^https?:/i) || (defined($ARGV[1]) && $ARGV[1] ne '--self-signed')) {
print "Usage: $0 <URL to this Bugzilla installation> [--self-signed]\n";
print "e.g.: $0 http://www.mycompany.com/bugzilla\n";
print "\n";
print "Pass --self-signed to prevent hostname verification of SSL certificates if needed.";
exit(1);
}

my $selfsigned = defined($ARGV[1]) ? 1 : 0;

# Try to determine the GID used by the web server.
my @pscmds
Expand Down Expand Up @@ -215,7 +217,15 @@ sub fetch {
if ($lwp) {
my $req = HTTP::Request->new(GET => $url);
my $ua = LWP::UserAgent->new;
$ua->ssl_opts( verify_hostname => 0 ) if $selfsigned;
my $res = $ua->request($req);
if (!$res->is_success) {
my $errstr = $res->status_line;
print $errstr . "\n";
if ($errstr =~ m/certificate/) {
say "Try passing --self-signed to skip certificate checks."
}
}
$rtn = ($res->is_success ? $res->content : undef);
}
elsif ($url =~ /^https:/i) {
Expand Down

0 comments on commit 07dce0b

Please sign in to comment.