leejo / AWS-S3

Lightweight interface to Amazon S3 (Simple Storage Service)
5 stars 6 forks source link

"bad hostname" test may fail in presence of wildcard DNS records #19

Closed eserte closed 10 months ago

eserte commented 10 months ago

On some of my smoker systems I see failures like this:

#   Failed test 'endpoint was used'
#   at t/aws/s3.t line 39.
#                   ':2: parser error : Space required after the Public Identifier
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
#                                                              ^
# :2: parser error : SystemLiteral " or ' expected
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
#                                                              ^
# :2: parser error : SYSTEM or PUBLIC, the URI is missing
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
#                                                              ^
# :11: parser error : Opening and ending tag mismatch: img line 11 and a
# tBeat Webhosting, www.netbeat.de - soeben freigeschaltete Domain" border="0"></a
#                                                                                 ^
# :12: parser error : Opening and ending tag mismatch: a line 11 and td
#       </td>
#            ^
# :14: parser error : Opening and ending tag mismatch: td line 10 and tr
#   </tr>   
#        ^
# :15: parser error : Opening and ending tag mismatch: tr line 9 and table
# </table>
#         ^
# :17: parser error : Opening and ending tag mismatch: table line 8 and body
# </body>
#        ^
# :18: parser error : Opening and ending tag mismatch: body line 7 and html
# </html>
#        ^
# :20: parser error : Premature end of data in tag html line 3
#   
#   ^
# '
#     doesn't match '(?^:Can't connect to aws-s3-test-.*?bad\.hostname)'
# Looks like you failed 1 test of 11.
t/aws/s3.t ................ 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/11 subtests 

This is most probably caused by wildcard DNS records on this system. See https://github.com/tokuhirom/Furl/issues/128 for a discussion of this problem.

A possible fix could look like this:

diff --git a/t/aws/s3.t b/t/aws/s3.t
index 1523287..8413e22 100644
--- a/t/aws/s3.t
+++ b/t/aws/s3.t
@@ -27,7 +27,7 @@ use_ok('AWS::S3');
 my $s3 = AWS::S3->new(
   access_key_id     => $ENV{AWS_ACCESS_KEY_ID}     // 'foo',
   secret_access_key => $ENV{AWS_SECRET_ACCESS_KEY} // 'bar',
-  endpoint          => 'bad.hostname',
+  endpoint          => 'bad.hostname.',
 );

 my $bucket_name = "aws-s3-test-" . int(rand() * 1_000_000) . '-' . time() . "-foo";
@@ -58,7 +58,7 @@ subtest 'create bucket strange temporary redirect' => sub {

             # first PUT request, send a forward
             is( $req->method, 'PUT', 'bucket creation with PUT request' );
-            is( $req->uri->as_string, 'http://bar.bad.hostname/', '... and with correct URI' );
+            is( $req->uri->as_string, 'http://bar.bad.hostname./', '... and with correct URI' );

             $i++;
             return HTTP::Response->new(
@@ -81,7 +81,7 @@ subtest 'create bucket strange temporary redirect' => sub {
         else {
             # there is a call to ->bucket, which does ->buckets, which is empty.
             is( $req->method, 'GET', '->buckets with GET' );
-            is( $req->uri->as_string, 'http://bad.hostname/', '... and with correct URI' );
+            is( $req->uri->as_string, 'http://bad.hostname./', '... and with correct URI' );

             # we need to return XML in the body or xpc doesn't work
             return Mocked::HTTP::Response->new( 200,
leejo commented 10 months ago

Thanks @eserte - I guess assuming a hostname wouldn't exist was always a bad idea. I'll get this fix shortly.