]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/net_ssh2.pl
4cfc5bda079354c6bdb17a2a0994b0aa7c2d671c
[Evergreen.git] / Open-ILS / src / support-scripts / test-scripts / net_ssh2.pl
1 #!/usr/bin/perl
2 #
3
4 use strict;
5 use warnings;
6
7 use Test::More qw/no_plan/;
8
9 my %config = (
10     hostname   => @ARGV ? shift @ARGV : 'example.org',
11     username   => @ARGV ? shift @ARGV : 'some_user',
12     file       => @ARGV ? shift @ARGV : '.bashrc',
13     privatekey => glob("~/.ssh/id_rsa") || glob("~/.ssh/id_dsa"),
14 );
15 $config{publickey} = $config{privatekey} . '.pub';
16
17 BEGIN {
18     use_ok( 'Net::SSH2'  );
19     use_ok( 'IO::Scalar' );
20     use_ok( 'IO::File'   );
21     use_ok( 'File::Glob', qw/:glob/ );
22 }
23
24 my $ssh;
25
26 ok($ssh = Net::SSH2->new,
27          'Net::SSH2->new');
28
29 ok($ssh->connect( $config{hostname} ),
30    "ssh->connect('$config{hostname}')");
31
32 ok($ssh->auth_publickey(@config{qw/username publickey privatekey/}),
33    "ssh->auth_publickey("
34         . join(', ', map{"'$_'"} @config{qw/username publickey privatekey/})
35    . ")"
36 );
37
38 my (@list, $io, $iofile);
39
40 my $scalar = "## This line starts in the variable before we read the file\n## This line too.\n";
41
42 ok($io     = IO::Scalar->new(\$scalar), "IO::Scalar->new");
43 ok($iofile = IO::File->new(">/tmp/io_file.tmp"),
44             "IO::File->new('>/tmp/io_file.tmp')");
45
46 ok($ssh->scp_get($config{file},  $io),
47    "ssh->scp_get($config{file}, \$io) # trying to retrieve file into IO::Scalar"
48 );
49
50 diag("Now printing remote file from IO::Scalar:");
51 print $io;
52