App-MtAws
view release on metacpan or search on metacpan
t/integration/config_engine_upload_file_real.t view on Meta::CPAN
test_file_and_dir "dir/filename should work with ..",
".", "d3/myfile", "d3/myfile";
test_file_and_dir "dir/filename should work with ..",
"..", "d3/myfile", "d2/d3/myfile";
test_file_and_dir "dir/filename should work with ../..",
"../..", "d3/myfile", "d1/d2/d3/myfile";
test_file_and_dir "dir/filename should work with ../..",
"../d2", "d3/myfile", "d3/myfile";
test_file_and_dir "dir/filename should work with ../..",
"../d2/../d2", "d3/myfile", "d3/myfile";
test_file_and_dir "dir/filename should work with ../..",
"../d2/.", "./d3/myfile", "d3/myfile";
test_file_and_dir "dir/filename should work with ../..",
"../d2", "../d2/d3/myfile", "d3/myfile";
test_file_and_dir "dir/filename should work with ../..",
".", "../d2/d3/myfile", "d3/myfile";
test_file_and_dir "dir/filename should work with ../..",
"../..", "../../d1/d2/d3/myfile", "d1/d2/d3/myfile";
};
with_my_dir "d1/d2", "d1/d2/d3", "d1/d2/d3/d4", sub {
touch "d3/myfile";
touch "d3/d4/myfile2";
symlink "d3", "ds" or confess;
test_file_and_dir "dir/filename should work with symlinks 1",
"d3", "d3/myfile", "myfile";
test_file_and_dir "dir/filename should work with symlinks 1",
"d3/", "d3/myfile", "myfile";
test_file_and_dir "dir/filename should work with symlinks 2",
"ds", "d3/myfile", "myfile";
test_file_and_dir "dir/filename should work with symlinks 3",
"d3", "ds/myfile", "myfile";
test_file_and_dir "dir/filename should work with symlinks 4",
"ds", "ds/myfile", "myfile";
test_file_and_dir "dir/filename should work with symlinks 5",
"d3", "d3/d4/myfile2", "d4/myfile2";
test_file_and_dir "dir/filename should work with symlinks 6",
"ds", "d3/d4/myfile2", "d4/myfile2";
test_file_and_dir "dir/filename should work with symlinks 7",
"d3", "ds/d4/myfile2", "d4/myfile2";
test_file_and_dir "dir/filename should work with symlinks 8",
"ds", "ds/d4/myfile2", "d4/myfile2";
test_file_and_dir "dir/filename should work with symlinks 8",
"ds/", "ds/d4/myfile2", "d4/myfile2";
};
my @filename_inside_dir = ('filename_inside_dir', a => 'filename', b => 'dir');
my @not_a_file = ('%option a% not a file', a => 'filename');
my @not_a_dir = ('%option a% not a directory', a => 'dir');
with_my_dir "d1/d2", "d1/d2/d3", sub {
my ($curdir) = @_;
touch "../myfile1";
touch "myfile2";
touch "d3/myfile3";
fails_file_and_dir "filename inside dir",
"d3", "myfile2", @filename_inside_dir;
fails_file_and_dir "filename inside dir",
"$curdir/d3", "$curdir/myfile2", @filename_inside_dir;
fails_file_and_dir "filename inside dir",
"d3", "../myfile1", @filename_inside_dir;
fails_file_and_dir "filename inside dir",
".", "../myfile1", @filename_inside_dir;
fails_file_and_dir "file not found",
".", "../notafile", @not_a_file, value => '../notafile';
fails_file_and_dir "file not found",
"d3", "../notafile", @not_a_file, value => '../notafile';
fails_file_and_dir "file not found",
"d3", "notafile", @not_a_file, value => 'notafile';
fails_file_and_dir "filename inside dir",
"notadir", "myfile2", @not_a_dir, value => 'notadir';
fails_file_and_dir "filename inside dir",
"$curdir/notadir", "$curdir/myfile2", @not_a_dir, value => "$curdir/notadir";
fails_file_and_dir "filename inside dir",
"notadir", "notafile", @not_a_dir, value => 'notadir';
# TODO: test also for bad filename
fails_file_and_dir "filename inside dir",
('x' x 2048), "myfile2", '%option a% should be less than 512 characters', a => 'dir', value => ("x" x 2048);
};
SKIP: {
skip "Cannot run under root", 24 if $^O eq 'cygwin' || is_posix_root; # too britle even under cygwin non-root
my $restricted_abs = "$mtroot/restricted";
my $normal_abs = "$restricted_abs/normal";
my $file_abs = "$normal_abs/file";
with_my_dir "restricted/normal", "restricted/normal/another", sub {
touch $file_abs;
mkpath "top";
my $file_rel = "file";
my $normal_rel = "../normal";
is stat($file_rel)->ino, stat($file_abs)->ino;
is stat($normal_rel)->ino, stat($normal_abs)->ino;
ok -f $file_rel;
ok -f $file_abs;
ok -d $normal_rel;
ok -d $normal_rel;
test_file_and_dir "dir/filename should work",
"another/..", $file_rel, $file_rel;
test_file_and_dir "dir/filename should work",
"$mtroot/restricted/normal", $file_rel, $file_rel;
chmod 000, $restricted_abs;
ok -f $file_rel;
ok !-f $file_abs;
ok !-d $normal_rel;
ok !-d $normal_abs;
fails_file_and_dir "filename inside dir - dir is unresolvable",
"another/..", $file_rel, 'cannot_resolve_dir', a => 'dir';
fails_file_and_dir "filename inside dir - file is unresolvable",
$mtroot, $file_rel, 'cannot_resolve_file', a => 'filename';
chmod 700, $restricted_abs;
}
};
# TODO: also test with non-ascii filenames
with_my_dir "d1", sub {
touch "myfile";
touch "unreadable";
touch "empty", "";
chmod 000, "unreadable";
assert_fails_on_filesystem "should check --filename for readability",
[qw!upload-file --config glacier.cfg --vault myvault --journal j --set-rel-filename somefile!, '--filename', "notafile"],
[],
'%option a% not a file', a => 'filename', value => 'notafile';
assert_fails_on_filesystem "should check --filename for readability",
[qw!upload-file --config glacier.cfg --vault myvault --journal j --set-rel-filename somefile!, '--filename', "empty"],
[],
'%option a% file size is zero', a => 'filename', value => 'empty';
SKIP: {
skip "Cannot run under root", 4 if is_posix_root;
assert_fails_on_filesystem "should check --filename for readability",
[qw!upload-file --config glacier.cfg --vault myvault --journal j --set-rel-filename somefile!, '--filename', "unreadable"],
[],
'%option a% file not readable', a => 'filename', value => 'unreadable';
}
assert_passes_on_filesystem "should check --filename for readability",
[qw!upload-file --config glacier.cfg --vault myvault --journal j --set-rel-filename somefile!, '--filename', "myfile"],
'name-type' => 'rel-filename',
'data-type' => 'filename',
'set-rel-filename' => 'somefile',
'relfilename' => 'somefile',
filename => 'myfile',
'filenames-encoding' => 'UTF-8';
};
1;
( run in 1.042 second using v1.01-cache-2.11-cpan-98e64b0badf )