App-FileSync
view release on metacpan or search on metacpan
t/transport.t view on Meta::CPAN
'then the chosen options, the host and the pinned server command');
push @{$command}, 'tampered';
is_deeply($ssh->command(), [ @{$command}[ 0 .. $#{$command} - 1 ] ], 'command returns a copy');
is($ssh->exit_status(), undef, 'exit_status is undef before close');
is($ssh->close(), 1, 'an ssh that exits 0 is a good close');
is($ssh->exit_status(), 0, 'and exit_status is 0');
is_deeply($recorded->(), [ @{$command}[ $at + 1 .. $#{$command} - 1 ] ], 'ssh was run with exactly that argv');
}
{
local $ENV{FAKE_EXIT} = 3;
my $ssh = App::FileSync::Transport::SSH->new(server => 'host', repo => 'docs', client => 'laptop', command => $fake);
is($ssh->close(), 0, 'an ssh that exits 3 is a failed close');
is($ssh->exit_status(), 3, 'and exit_status is 3');
is($ssh->close(), 1, 'a second close returns 1');
is($ssh->exit_status(), 3, 'and keeps the status');
}
# --- Transport::SSH: extra_args ----------------------------------------------------
# The client config's ssh.extra_args go on the command line just before the
# host. Each must be a defined, plain string with no NUL or newline: the
# argv is handed to ssh as it is, and the remote end splits a command line.
{
local $ENV{FAKE_EXIT} = 0;
my $ssh = App::FileSync::Transport::SSH->new(
server => 'host', repo => 'docs', client => 'laptop', command => $fake,
extra_args => [ '-o', 'Compression=yes', '-v', 'with space', '$(not run)' ],
);
my $command = $ssh->command();
my ($host) = grep { $command->[$_] eq 'host' } 0 .. $#{$command};
is_deeply([ @{$command}[ $host - 5 .. $host - 1 ] ], [ '-o', 'Compression=yes', '-v', 'with space', '$(not run)' ],
'extra_args go in order, unchanged, just before the host');
$ssh->close();
my %bad = (
'an undefined element' => [ [ '-v', undef ], qr/bad extra_args ''/ ],
'a reference' => [ [ [ '-v' ] ], qr/bad extra_args 'ARRAY\(/ ],
'a newline' => [ [ "-v\n-oProxyCommand=evil" ], qr/bad extra_args '-v/ ],
'a NUL' => [ [ "-v\0x" ], qr/bad extra_args '-v/ ],
);
for my $case (sort keys %bad) {
my ($extra, $error) = @{ $bad{$case} };
throws_ok {
App::FileSync::Transport::SSH->new(server => 'host', repo => 'docs', client => 'laptop', command => $fake, extra_args => $extra)
} qr/\ASSH transport: $error/, "$case is refused";
}
throws_ok {
App::FileSync::Transport::SSH->new(server => 'host', repo => 'docs', client => 'laptop', command => $fake, extra_args => '-v')
} qr/'extra_args'/, 'extra_args that is not a list is refused';
my ($at) = grep { $command->[$_] eq $fake } 0 .. $#{$command};
is_deeply($recorded->(), [ @{$command}[ $at + 1 .. $#{$command} ] ],
'a refused transport starts no ssh: the last argv recorded is the good one');
}
# --- Transport::Local::error_text ------------------------------------------------
# The local server shares this process's stderr, so the transport has nothing
# of its own to add: error_text is empty before and after a whole session.
{
my $env = TestSync->new_env();
my $local = App::FileSync::Transport::Local->new(root => $env->{server}, repo => 'docs', client => 'test-1');
is($local->error_text(), '', 'error_text is empty while the session runs');
my $connection = App::FileSync::Protocol->new(in => $local->reader(), out => $local->writer());
$connection->send({ cmd => 'hello', proto => $PROTOCOL_VERSION, repo => 'docs', client => 'test-1', role => 'client' });
ok($connection->recv()->{ok}, 'the local server answers');
$connection->send({ cmd => 'done' });
$connection->recv();
is($local->close(), 1, 'the session closes');
is($local->error_text(), '', 'and error_text is still empty');
}
# --- Store::root and Store::repo ---------------------------------------------------
{
my $env = TestSync->new_env();
my $store = App::FileSync::Store->new(root => $env->{server}, repo => 'docs');
is($store->root(), $env->{server}, 'root is the server root it was given');
is($store->repo(), 'docs', 'repo is the repo name');
is($store->master_dir(), File::Spec->catdir($store->root(), 'master', $store->repo()),
'and the master tree is built from them');
}
done_testing();
( run in 0.730 second using v1.01-cache-2.11-cpan-60884a8df76 )