Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[io grant] Test IO::Path.child-secure
Also add a nul byte test to IO::Path.child.
  • Loading branch information
zoffixznet committed Apr 16, 2017
1 parent a716962 commit f3c5dae
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
35 changes: 34 additions & 1 deletion S32-io/io-path.t
Expand Up @@ -3,7 +3,7 @@ use lib <t/spec/packages/>;
use Test;
use Test::Util;

plan 29;
plan 30;

# L<S32::IO/IO::Path>

Expand Down Expand Up @@ -179,3 +179,36 @@ subtest '.link' => {
'fail when link already exists';
}
}

subtest '.child-secure' => {
my $parent = make-temp-dir;
my $non-resolving-parent = make-temp-file.child('bar');

fails-like { $non-resolving-parent.child-secure('../foo') }, X::IO::Resolve,
'non-resolving parent fails (given path is non-child)';

fails-like { $non-resolving-parent.child-secure('foo') }, X::IO::Resolve,
'non-resolving parent fails (given path is child)';

fails-like { $parent.child-secure('foo/bar') }, X::IO::Resolve,
'resolving parent fails (given path is a child, but not resolving)';

fails-like { $parent.child-secure('../foo') }, X::IO::NotAChild,
'resolved parent fails (given path is not a child)';

is-path $parent.child-secure('foo'), $parent.child('foo'),
'resolved parent with resolving, non-existent child';

$parent.child-secure('foo').mkdir;
is-path $parent.child-secure('foo'), $parent.child('foo'),
'resolved parent with resolving, existent child';

is-path $parent.child-secure('foo/bar'), $parent.child('foo/bar'),
'resolved parent with resolving, existent child in a subdir';

is-path $parent.child-secure('foo/../bar'), $parent.child('bar'),
'resolved parent with resolving, non-existent child, with ../';

fails-like { $parent.child-secure('foo/../../bar') }, X::IO::NotAChild,
'resolved parent fails (given path is not a child, via child + ../)';
}
5 changes: 4 additions & 1 deletion S32-io/null-char.t
Expand Up @@ -6,7 +6,7 @@ use Test::Util;
# Tests for ensuring NUL byte is rejected from paths
constant @nuls = ("\0foobar", "foo\0bar", "foobar\0", "\0foo\0bar\0");

plan 5*@nuls;
plan 7*@nuls;

{
temp $*CWD = make-temp-dir;
Expand All @@ -17,6 +17,9 @@ plan 5*@nuls;
throws-like { chdir $nul }, X::IO::Null, "&chdir $d";
throws-like { $nul.IO }, X::IO::Null, ".IO $d";
throws-like { IO::Path.new: $nul }, X::IO::Null, "IO::Path.new $d";
throws-like { $*CWD.child: $nul }, X::IO::Null, ".child $d";
throws-like { $*CWD.child-secure: $nul }, X::IO::Null,
".child-secure $d";
}
}

Expand Down

0 comments on commit f3c5dae

Please sign in to comment.