|
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 |
| 13 | + # from there. |
| 14 | + Test::More->builder->current_test(1); |
| 15 | + Test::More->builder->no_ending(1); |
| 16 | +} |
9 | 17 |
|
10 | 18 | my @global_credential_args = @ARGV;
|
11 |
| -my $netrc = './test.netrc'; |
12 |
| -print "# Testing insecure file, nothing should be found\n"; |
| 19 | +my $scriptDir = dirname rel2abs $0; |
| 20 | +my ($netrc, $netrcGpg, $gcNetrc) = map { catfile $scriptDir, $_; } |
| 21 | + qw(test.netrc |
| 22 | + test.netrc.gpg |
| 23 | + git-credential-netrc); |
| 24 | +local $ENV{PATH} = join ':' |
| 25 | + , $scriptDir |
| 26 | + , $ENV{PATH} |
| 27 | + ? $ENV{PATH} |
| 28 | + : (); |
| 29 | + |
| 30 | +diag "Testing insecure file, nothing should be found\n"; |
13 | 31 | chmod 0644, $netrc;
|
14 | 32 | my $cred = run_credential(['-f', $netrc, 'get'],
|
15 | 33 | { host => 'github.com' });
|
16 | 34 |
|
17 |
| -ok(scalar keys %$cred, 0, "Got 0 keys from insecure file"); |
| 35 | +ok(scalar keys %$cred == 0, "Got 0 keys from insecure file"); |
18 | 36 |
|
19 |
| -print "# Testing missing file, nothing should be found\n"; |
| 37 | +diag "Testing missing file, nothing should be found\n"; |
20 | 38 | chmod 0644, $netrc;
|
21 | 39 | $cred = run_credential(['-f', '///nosuchfile///', 'get'],
|
22 | 40 | { host => 'github.com' });
|
23 | 41 |
|
24 |
| -ok(scalar keys %$cred, 0, "Got 0 keys from missing file"); |
| 42 | +ok(scalar keys %$cred == 0, "Got 0 keys from missing file"); |
25 | 43 |
|
26 | 44 | chmod 0600, $netrc;
|
27 | 45 |
|
28 |
| -print "# Testing with invalid data\n"; |
| 46 | +diag "Testing with invalid data\n"; |
29 | 47 | $cred = run_credential(['-f', $netrc, 'get'],
|
30 | 48 | "bad data");
|
31 |
| -ok(scalar keys %$cred, 4, "Got first found keys with bad data"); |
| 49 | +ok(scalar keys %$cred == 4, "Got first found keys with bad data"); |
32 | 50 |
|
33 |
| -print "# Testing netrc file for a missing corovamilkbar entry\n"; |
| 51 | +diag "Testing netrc file for a missing corovamilkbar entry\n"; |
34 | 52 | $cred = run_credential(['-f', $netrc, 'get'],
|
35 | 53 | { host => 'corovamilkbar' });
|
36 | 54 |
|
37 |
| -ok(scalar keys %$cred, 0, "Got no corovamilkbar keys"); |
| 55 | +ok(scalar keys %$cred == 0, "Got no corovamilkbar keys"); |
38 | 56 |
|
39 |
| -print "# Testing netrc file for a github.com entry\n"; |
| 57 | +diag "Testing netrc file for a github.com entry\n"; |
40 | 58 | $cred = run_credential(['-f', $netrc, 'get'],
|
41 | 59 | { host => 'github.com' });
|
42 | 60 |
|
43 |
| -ok(scalar keys %$cred, 2, "Got 2 Github keys"); |
| 61 | +ok(scalar keys %$cred == 2, "Got 2 Github keys"); |
44 | 62 |
|
45 |
| -ok($cred->{password}, 'carolknows', "Got correct Github password"); |
46 |
| -ok($cred->{username}, 'carol', "Got correct Github username"); |
| 63 | +is($cred->{password}, 'carolknows', "Got correct Github password"); |
| 64 | +is($cred->{username}, 'carol', "Got correct Github username"); |
47 | 65 |
|
48 |
| -print "# Testing netrc file for a username-specific entry\n"; |
| 66 | +diag "Testing netrc file for a username-specific entry\n"; |
49 | 67 | $cred = run_credential(['-f', $netrc, 'get'],
|
50 | 68 | { host => 'imap', username => 'bob' });
|
51 | 69 |
|
52 |
| -ok(scalar keys %$cred, 2, "Got 2 username-specific keys"); |
| 70 | +ok(scalar keys %$cred == 2, "Got 2 username-specific keys"); |
53 | 71 |
|
54 |
| -ok($cred->{password}, 'bobwillknow', "Got correct user-specific password"); |
55 |
| -ok($cred->{protocol}, 'imaps', "Got correct user-specific protocol"); |
| 72 | +is($cred->{password}, 'bobwillknow', "Got correct user-specific password"); |
| 73 | +is($cred->{protocol}, 'imaps', "Got correct user-specific protocol"); |
56 | 74 |
|
57 |
| -print "# Testing netrc file for a host:port-specific entry\n"; |
| 75 | +diag "Testing netrc file for a host:port-specific entry\n"; |
58 | 76 | $cred = run_credential(['-f', $netrc, 'get'],
|
59 | 77 | { host => 'imap2:1099' });
|
60 | 78 |
|
61 |
| -ok(scalar keys %$cred, 2, "Got 2 host:port-specific keys"); |
| 79 | +ok(scalar keys %$cred == 2, "Got 2 host:port-specific keys"); |
62 | 80 |
|
63 |
| -ok($cred->{password}, 'tzzknow', "Got correct host:port-specific password"); |
64 |
| -ok($cred->{username}, 'tzz', "Got correct host:port-specific username"); |
| 81 | +is($cred->{password}, 'tzzknow', "Got correct host:port-specific password"); |
| 82 | +is($cred->{username}, 'tzz', "Got correct host:port-specific username"); |
65 | 83 |
|
66 |
| -print "# Testing netrc file that 'host:port kills host' entry\n"; |
| 84 | +diag "Testing netrc file that 'host:port kills host' entry\n"; |
67 | 85 | $cred = run_credential(['-f', $netrc, 'get'],
|
68 | 86 | { host => 'imap2' });
|
69 | 87 |
|
70 |
| -ok(scalar keys %$cred, 2, "Got 2 'host:port kills host' keys"); |
| 88 | +ok(scalar keys %$cred == 2, "Got 2 'host:port kills host' keys"); |
| 89 | + |
| 90 | +is($cred->{password}, 'bobwillknow', "Got correct 'host:port kills host' password"); |
| 91 | +is($cred->{username}, 'bob', "Got correct 'host:port kills host' username"); |
| 92 | + |
| 93 | +diag 'Testing netrc file decryption by git config gpg.program setting\n'; |
| 94 | +$cred = run_credential( ['-f', $netrcGpg, 'get'] |
| 95 | + , { host => 'git-config-gpg' } |
| 96 | + ); |
| 97 | + |
| 98 | +ok(scalar keys %$cred == 2, 'Got keys decrypted by git config option'); |
| 99 | + |
| 100 | +diag 'Testing netrc file decryption by gpg option\n'; |
| 101 | +$cred = run_credential( ['-f', $netrcGpg, '-g', 'test.command-option-gpg', 'get'] |
| 102 | + , { host => 'command-option-gpg' } |
| 103 | + ); |
71 | 104 |
|
72 |
| -ok($cred->{password}, 'bobwillknow', "Got correct 'host:port kills host' password"); |
73 |
| -ok($cred->{username}, 'bob', "Got correct 'host:port kills host' username"); |
| 105 | +ok(scalar keys %$cred == 2, 'Got keys decrypted by command option'); |
74 | 106 |
|
75 | 107 | sub run_credential
|
76 | 108 | {
|
77 | 109 | my $args = shift @_;
|
78 | 110 | my $data = shift @_;
|
79 | 111 | my $pid = open2(my $chld_out, my $chld_in,
|
80 |
| - './git-credential-netrc', @global_credential_args, |
| 112 | + $gcNetrc, @global_credential_args, |
81 | 113 | @$args);
|
82 | 114 |
|
83 | 115 | die "Couldn't open pipe to netrc credential helper: $!" unless $pid;
|
|
0 commit comments