atrodo / App-MechaCPAN

Mechanize the installation of CPAN things
Other
2 stars 2 forks source link

Got a '301' from 'github.com' expected '200' #14

Closed eserte closed 3 years ago

eserte commented 5 years ago

In a minimal docker setup using debian/stretch (stable) the test suite fails. The Dockerfile:

# maybe: docker pull debian:stretch
# docker build -t perl-test . && docker run perl-test
FROM debian:stretch

RUN apt-get -y update
RUN apt-get -y --no-install-recommends install perl make gcc

#RUN apt-get -y --no-install-recommends install liblwp-protocol-https-perl

CMD cpan -t ATRODO/App-MechaCPAN-0.26.tar.gz

The failing tests:

Got a '301' from 'github.com' expected '200' at /root/.cpan/build/App-MechaCPAN-0.26-hPnjY9/blib/lib/App/MechaCPAN.pm line 597.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 2 just after 3.
t/07_tmpdata.t ............. 
Dubious, test returned 2 (wstat 512, 0x200)
All 3 subtests passed 
...
# Error: 'Got a '301' from 'github.com' expected '200' at /root/.cpan/build/App-MechaCPAN-0.26-hPnjY9/blib/lib/App/MechaCPAN.pm line 597.
# '

#   Failed test 'Got 'https://github.com/p5sagit/Try-Tiny/archive/v0.24.zip''
#   at t/22_install__get_targz.t line 49.
# Looks like you failed 1 test of 14.
t/22_install__get_targz.t .. 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/14 subtests 
        (less 2 skipped subtests: 11 okay)
...
#   Failed test 'Honored PERL_USE_UNSAFE_INC=: /root/.cpan/build/App-MechaCPAN-0.26-hPnjY9/t/../test_dists/UnsafeInc/UnsafeInc-1.0.tar.gz'
#   at t/gh3.t line 23.
#          got: '0'
#     expected: anything else

#   Failed test 'Honored PERL_USE_UNSAFE_INC=0: /root/.cpan/build/App-MechaCPAN-0.26-hPnjY9/t/../test_dists/UnsafeInc/UnsafeInc-1.0.tar.gz'
#   at t/gh3.t line 27.
#          got: '0'
#     expected: anything else
# Looks like you failed 2 tests of 8.
t/gh3.t .................... 
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/8 subtests 

The first two failing tests are fixed by installing LWP::Protocol::https before (see the commented out RUN line in the Dockerfile). The third test still fails (and probably should dealt into another issue).

atrodo commented 5 years ago

Thank you very much for the ticket. I have seen these failures on cpantesters, but had so far assumed that the 301 as caused because of some strange network configuration causing github URLs to be redirected. Having this information however makes it clear that the issue is that https is missing from LWP and (I assume) LWP rewriting my https url to http since it can't do https. I will be investigating how to handle this case for the next version.

atrodo commented 5 years ago

Finally got to do some digging, turns out I was on the right path but wrong assumption. The culprit actually is File::Fetch's iosock method, which is using IO::Socket to open a connection to port 80, and only port 80, and download the file. Since github always does a redirect to https, that's where the error "expected 200 got 301" comes from. Installing LWP::Protocol::https happened to work because it installed LWP. I've confirmed that LWP will skip if it can't do https and File::Fetch will move on. The bug would also go away when any other method is available, so an apt-get install curl or wget would have also fixed it.

I still need to figure out a solution. While I could skip all https downloads in the test, I'm hesitant to since the module pretty heavily relies on https to be useful.

atrodo commented 3 years ago

I ended up adding a function to check if https was supported, and if not, skips those tests. I'm not sure there was any other way. Closing as this was released as part of 0.27.