1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
use Test2::V0 -no_srand => 1;
use Test::Alien::Build;
use Path::Tiny qw( path );
our $download_filename;
our $cwd_url;
subtest 'basic' => sub {
local $Alien::Build::VERSION = $Alien::Build::VERSION || 2.57;
my $build = alienfile_ok q{
use alienfile;
probe sub { 'share' };
share {
plugin 'Digest' => [ SHA256 => 'a7e79996a02d3dfc47f6f3ec043c67690dc06a10d091bf1d760fee7c8161391a' ];
plugin 'Fetch::Local';
download sub {
$main::download_filename->copy($main::download_filename->basename);
};
};
};
is
$build->meta->prop->{check_digest},
T(),
'set meta.check_digest flag';
alienfile_skip_if_missing_prereqs;
subtest 'check_digest method' => sub {
is
$build->check_digest('corpus/alien_build_plugin_digest_shapp/foo.txt.gz'),
T(),
'check digest works';
is
dies { $build->check_digest(__FILE__) },
match qr/SHA256 digest does not match/,
'check digest throws exception on bad signature';
};
subtest 'fetch method' => sub {
is
$build->fetch('corpus/alien_build_plugin_digest_shapp/foo.txt.gz'),
hash {
field type => 'file';
field filename => 'foo.txt.gz';
etc;
},
'fetch works with right signature';
is
dies { $build->fetch(__FILE__) },
match qr/SHA256 digest does not match/,
'fetch dies with wrong signature';
};
subtest 'download method' => sub {
local $download_filename = path('corpus/alien_build_plugin_digest_shapp/foo.txt.gz')->absolute;
is
$build,
object {
call download => T();
call install_prop => hash {
field download => match qr/foo.txt.gz/;
etc;
};
},
'download works with right signature';
delete $build->install_prop->{complete};
delete $build->install_prop->{download};
$download_filename = path(__FILE__)->absolute;
is
dies { $build->download },
match qr/SHA256 digest does not match/,
'download dies with wrong signature';
};
};
subtest 'two signatures' => sub {
local $Alien::Build::VERSION = $Alien::Build::VERSION || 2.57;
my $build = alienfile_ok q{
use alienfile;
probe sub { 'share' };
share {
plugin 'Digest' => {
'foo.txt.gz' => [ SHA256 => 'a7e79996a02d3dfc47f6f3ec043c67690dc06a10d091bf1d760fee7c8161391a' ],
'foo.txt' => [ SHA256 => '032772271db8f134e4914bca0e933361e1946c91c21e43610d301d39cbdb9d51' ],
'alien_build_plugin_digest_negotiate.t' => [ SHA256 => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ],
};
plugin 'Fetch::Local';
download sub {
$main::download_filename->copy($main::download_filename->basename);
};
};
};
alienfile_skip_if_missing_prereqs;
subtest 'check_digest method' => sub {
is
$build->check_digest('corpus/alien_build_plugin_digest_shapp/foo.txt.gz'),
T(),
'check digest works foo.txt.gz';
is
$build->check_digest('corpus/alien_build_plugin_digest_shapp/foo.txt'),
T(),
'check digest works foo.txt';
is
dies { $build->check_digest(__FILE__) },
match qr/SHA256 digest does not match/,
'check digest throws exception on bad signature';
};
subtest 'fetch method' => sub {
is
$build->fetch('corpus/alien_build_plugin_digest_shapp/foo.txt.gz'),
hash {
field type => 'file';
field filename => 'foo.txt.gz';
etc;
},
'fetch works foo.txt.gz';
is
$build->fetch('corpus/alien_build_plugin_digest_shapp/foo.txt'),
hash {
field type => 'file';
field filename => 'foo.txt';
etc;
},
'fetch works foo.txt';
is
dies { $build->fetch(__FILE__) },
match qr/SHA256 digest does not match/,
'fetch throws exception on bad signature';
};
subtest 'download method' => sub {
local $download_filename = path('corpus/alien_build_plugin_digest_shapp/foo.txt')->absolute;
is
$build,
object {
call download => T();
call install_prop => hash {
field download => match qr/foo.txt/;
etc;
};
},
'download works with right signature';
delete $build->install_prop->{download};
delete $build->install_prop->{complete};
$download_filename = path('corpus/alien_build_plugin_digest_shapp/foo.txt.gz')->absolute;
is
$build,
object {
call download => T();
call install_prop => hash {
field download => match qr/foo.txt.gz/;
etc;
};
},
'download works with right signature';
delete $build->install_prop->{download};
delete $build->install_prop->{complete};
$download_filename = path(__FILE__)->absolute;
is
dies { $build->download },
match qr/SHA256 digest does not match/,
'download dies with wrong signature';
};
};
subtest 'listing' => sub {
local $Alien::Build::VERSION = $Alien::Build::VERSION || 2.57;
skip_all 'test require URI::file' unless eval { require URI::file };
my $url = URI::file->cwd;
subtest 'default' => sub {
my $build = alienfile_ok q{
use alienfile;
probe sub { 'share' };
share {
plugin 'Digest';
start_url 'file:///';
plugin 'Fetch::LWP';
};
};
alienfile_skip_if_missing_prereqs;
is
$build->fetch($url),
hash {
field type => 'html';
etc;
},
'works by default';
};
subtest 'allowed' => sub {
my $build = alienfile_ok q{
use alienfile;
probe sub { 'share' };
share {
plugin 'Digest', allow_listing => 1;
start_url 'file:///';
plugin 'Fetch::LWP';
};
};
alienfile_skip_if_missing_prereqs;
is
$build->fetch($url),
hash {
field type => 'html';
etc;
},
'works by default';
};
subtest 'not allowed' => sub {
my $build = alienfile_ok q{
use alienfile;
probe sub { 'share' };
share {
plugin 'Digest', allow_listing => 0;
start_url 'file:///';
plugin 'Fetch::LWP';
};
};
alienfile_skip_if_missing_prereqs;
is
dies { $build->fetch($url) },
match qr/^listing fetch not allowed/,
'works by default';
};
};
done_testing;
|