From 826e0b723d0e5778e470f2b125f37617695ff2d0 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Wed, 23 Sep 2020 09:34:05 -0400 Subject: [PATCH] Require network testing enabled for t/redirect.t Fixes #350 --- Changes | 1 + t/redirect.t | 36 +++++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Changes b/Changes index 5e78ead4b..e6f2dd9e7 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Change history for libwww-perl {{$NEXT}} + - Require network testing enabled for t/redirect.t (GH#351) (Olaf Alders) 6.48 2020-09-20 15:25:51Z - Support 308 Permanent Redirect (GH#349) (Galen Huntington) diff --git a/t/redirect.t b/t/redirect.t index ec859cad4..e443c52b5 100644 --- a/t/redirect.t +++ b/t/redirect.t @@ -1,17 +1,36 @@ use strict; use warnings; + +# This is a regression test for #171 + use Test::More; -use LWP::UserAgent; -plan tests => 4; +# Test::RequiresInternet is used here basically just to SKIP tests if +# NO_NETWORK_TESTING has been enabled. We would want to do this particularly if +# there is a badly behaved router on the network where the tests are being run. +use Test::RequiresInternet; -# This is a regression test for #171 +use LWP::UserAgent (); + +# Regarding the choice of 198.51.100.123 as a test IP address, please see +# https://tools.ietf.org/html/rfc5737 +# +# The RFC contains the following description for the block to which this +# address belongs: +# +# Documentation Address Blocks +# +# The blocks 192.0.2.0/24 (TEST-NET-1), 198.51.100.0/24 (TEST-NET-2), and +# 203.0.113.0/24 (TEST-NET-3) are provided for use in documentation. + +my $url = 'http://198.51.100.123/'; my $ua = LWP::UserAgent->new(); -{ # default number of redirects +# default number of redirects +{ $ua->timeout(1); - my $res = $ua->get('http://198.51.100.123/'); + my $res = $ua->get($url); like( $res->header("Client-Warning"), qr/Internal Response/i, @@ -24,10 +43,11 @@ my $ua = LWP::UserAgent->new(); ); } -{ # no redirects +# no redirects +{ $ua->timeout(1); $ua->max_redirect(0); - my $res = $ua->get('http://198.51.100.123/'); + my $res = $ua->get($url); like( $res->header("Client-Warning"), qr/Internal Response/i, @@ -39,3 +59,5 @@ my $ua = LWP::UserAgent->new(); '... and has tells us about the problem' ); } + +done_testing();