|
1 | 1 | #!/usr/bin/perl
|
| 2 | +use lib (split(/:/, $ENV{GITPERLLIB})); |
2 | 3 |
|
3 | 4 | use warnings;
|
4 | 5 | use strict;
|
5 |
| -use Test; |
| 6 | +use Test::More qw(no_plan); |
| 7 | +use File::Basename; |
| 8 | +use File::Spec::Functions qw(:DEFAULT rel2abs); |
6 | 9 | use IPC::Open2;
|
7 | 10 |
|
8 |
| -BEGIN { plan tests => 15 } |
| 11 | +BEGIN { |
| 12 | + # t-git-credential-netrc.sh kicks off our testing, so we have to go from there. |
| 13 | + Test::More->builder->current_test(1); |
| 14 | + Test::More->builder->no_ending(1); |
| 15 | +} |
9 | 16 |
|
10 | 17 | my @global_credential_args = @ARGV;
|
11 |
| -my $netrc = './test.netrc'; |
12 |
| -print "# Testing insecure file, nothing should be found\n"; |
| 18 | +my $scriptDir = dirname rel2abs $0; |
| 19 | +my $netrc = catfile $scriptDir, 'test.netrc'; |
| 20 | +my $gcNetrc = catfile $scriptDir, 'git-credential-netrc'; |
| 21 | +local $ENV{PATH} = join ':' |
| 22 | + , $scriptDir |
| 23 | + , $ENV{PATH} |
| 24 | + ? $ENV{PATH} |
| 25 | + : (); |
| 26 | + |
| 27 | +diag "Testing insecure file, nothing should be found\n"; |
13 | 28 | chmod 0644, $netrc;
|
14 | 29 | my $cred = run_credential(['-f', $netrc, 'get'],
|
15 | 30 | { host => 'github.com' });
|
16 | 31 |
|
17 |
| -ok(scalar keys %$cred, 0, "Got 0 keys from insecure file"); |
| 32 | +ok(scalar keys %$cred == 0, "Got 0 keys from insecure file"); |
18 | 33 |
|
19 |
| -print "# Testing missing file, nothing should be found\n"; |
| 34 | +diag "Testing missing file, nothing should be found\n"; |
20 | 35 | chmod 0644, $netrc;
|
21 | 36 | $cred = run_credential(['-f', '///nosuchfile///', 'get'],
|
22 | 37 | { host => 'github.com' });
|
23 | 38 |
|
24 |
| -ok(scalar keys %$cred, 0, "Got 0 keys from missing file"); |
| 39 | +ok(scalar keys %$cred == 0, "Got 0 keys from missing file"); |
25 | 40 |
|
26 | 41 | chmod 0600, $netrc;
|
27 | 42 |
|
28 |
| -print "# Testing with invalid data\n"; |
| 43 | +diag "Testing with invalid data\n"; |
29 | 44 | $cred = run_credential(['-f', $netrc, 'get'],
|
30 | 45 | "bad data");
|
31 |
| -ok(scalar keys %$cred, 4, "Got first found keys with bad data"); |
| 46 | +ok(scalar keys %$cred == 4, "Got first found keys with bad data"); |
32 | 47 |
|
33 |
| -print "# Testing netrc file for a missing corovamilkbar entry\n"; |
| 48 | +diag "Testing netrc file for a missing corovamilkbar entry\n"; |
34 | 49 | $cred = run_credential(['-f', $netrc, 'get'],
|
35 | 50 | { host => 'corovamilkbar' });
|
36 | 51 |
|
37 |
| -ok(scalar keys %$cred, 0, "Got no corovamilkbar keys"); |
| 52 | +ok(scalar keys %$cred == 0, "Got no corovamilkbar keys"); |
38 | 53 |
|
39 |
| -print "# Testing netrc file for a github.com entry\n"; |
| 54 | +diag "Testing netrc file for a github.com entry\n"; |
40 | 55 | $cred = run_credential(['-f', $netrc, 'get'],
|
41 | 56 | { host => 'github.com' });
|
42 | 57 |
|
43 |
| -ok(scalar keys %$cred, 2, "Got 2 Github keys"); |
| 58 | +ok(scalar keys %$cred == 2, "Got 2 Github keys"); |
44 | 59 |
|
45 |
| -ok($cred->{password}, 'carolknows', "Got correct Github password"); |
46 |
| -ok($cred->{username}, 'carol', "Got correct Github username"); |
| 60 | +is($cred->{password}, 'carolknows', "Got correct Github password"); |
| 61 | +is($cred->{username}, 'carol', "Got correct Github username"); |
47 | 62 |
|
48 |
| -print "# Testing netrc file for a username-specific entry\n"; |
| 63 | +diag "Testing netrc file for a username-specific entry\n"; |
49 | 64 | $cred = run_credential(['-f', $netrc, 'get'],
|
50 | 65 | { host => 'imap', username => 'bob' });
|
51 | 66 |
|
52 |
| -ok(scalar keys %$cred, 2, "Got 2 username-specific keys"); |
| 67 | +ok(scalar keys %$cred == 2, "Got 2 username-specific keys"); |
53 | 68 |
|
54 |
| -ok($cred->{password}, 'bobwillknow', "Got correct user-specific password"); |
55 |
| -ok($cred->{protocol}, 'imaps', "Got correct user-specific protocol"); |
| 69 | +is($cred->{password}, 'bobwillknow', "Got correct user-specific password"); |
| 70 | +is($cred->{protocol}, 'imaps', "Got correct user-specific protocol"); |
56 | 71 |
|
57 |
| -print "# Testing netrc file for a host:port-specific entry\n"; |
| 72 | +diag "Testing netrc file for a host:port-specific entry\n"; |
58 | 73 | $cred = run_credential(['-f', $netrc, 'get'],
|
59 | 74 | { host => 'imap2:1099' });
|
60 | 75 |
|
61 |
| -ok(scalar keys %$cred, 2, "Got 2 host:port-specific keys"); |
| 76 | +ok(scalar keys %$cred == 2, "Got 2 host:port-specific keys"); |
62 | 77 |
|
63 |
| -ok($cred->{password}, 'tzzknow', "Got correct host:port-specific password"); |
64 |
| -ok($cred->{username}, 'tzz', "Got correct host:port-specific username"); |
| 78 | +is($cred->{password}, 'tzzknow', "Got correct host:port-specific password"); |
| 79 | +is($cred->{username}, 'tzz', "Got correct host:port-specific username"); |
65 | 80 |
|
66 |
| -print "# Testing netrc file that 'host:port kills host' entry\n"; |
| 81 | +diag "Testing netrc file that 'host:port kills host' entry\n"; |
67 | 82 | $cred = run_credential(['-f', $netrc, 'get'],
|
68 | 83 | { host => 'imap2' });
|
69 | 84 |
|
70 |
| -ok(scalar keys %$cred, 2, "Got 2 'host:port kills host' keys"); |
| 85 | +ok(scalar keys %$cred == 2, "Got 2 'host:port kills host' keys"); |
| 86 | + |
| 87 | +is($cred->{password}, 'bobwillknow', "Got correct 'host:port kills host' password"); |
| 88 | +is($cred->{username}, 'bob', "Got correct 'host:port kills host' username"); |
71 | 89 |
|
72 |
| -ok($cred->{password}, 'bobwillknow', "Got correct 'host:port kills host' password"); |
73 |
| -ok($cred->{username}, 'bob', "Got correct 'host:port kills host' username"); |
74 | 90 |
|
75 | 91 | sub run_credential
|
76 | 92 | {
|
77 | 93 | my $args = shift @_;
|
78 | 94 | my $data = shift @_;
|
79 | 95 | my $pid = open2(my $chld_out, my $chld_in,
|
80 |
| - './git-credential-netrc', @global_credential_args, |
| 96 | + $gcNetrc, @global_credential_args, |
81 | 97 | @$args);
|
82 | 98 |
|
83 | 99 | die "Couldn't open pipe to netrc credential helper: $!" unless $pid;
|
|
0 commit comments