8 BEGIN { plan tests => 15 }
10 my @global_credential_args = @ARGV;
11 my $netrc = './test.netrc';
12 print "# Testing insecure file, nothing should be found\n";
14 my $cred = run_credential(['-f', $netrc, 'get'],
15 { host => 'github.com' });
17 ok(scalar keys %$cred, 0, "Got 0 keys from insecure file");
19 print "# Testing missing file, nothing should be found\n";
21 $cred = run_credential(['-f', '///nosuchfile///', 'get'],
22 { host => 'github.com' });
24 ok(scalar keys %$cred, 0, "Got 0 keys from missing file");
28 print "# Testing with invalid data\n";
29 $cred = run_credential(['-f', $netrc, 'get'],
31 ok(scalar keys %$cred, 4, "Got first found keys with bad data");
33 print "# Testing netrc file for a missing corovamilkbar entry\n";
34 $cred = run_credential(['-f', $netrc, 'get'],
35 { host => 'corovamilkbar' });
37 ok(scalar keys %$cred, 0, "Got no corovamilkbar keys");
39 print "# Testing netrc file for a github.com entry\n";
40 $cred = run_credential(['-f', $netrc, 'get'],
41 { host => 'github.com' });
43 ok(scalar keys %$cred, 2, "Got 2 Github keys");
45 ok($cred->{password}, 'carolknows', "Got correct Github password");
46 ok($cred->{username}, 'carol', "Got correct Github username");
48 print "# Testing netrc file for a username-specific entry\n";
49 $cred = run_credential(['-f', $netrc, 'get'],
50 { host => 'imap', username => 'bob' });
52 ok(scalar keys %$cred, 2, "Got 2 username-specific keys");
54 ok($cred->{password}, 'bobwillknow', "Got correct user-specific password");
55 ok($cred->{protocol}, 'imaps', "Got correct user-specific protocol");
57 print "# Testing netrc file for a host:port-specific entry\n";
58 $cred = run_credential(['-f', $netrc, 'get'],
59 { host => 'imap2:1099' });
61 ok(scalar keys %$cred, 2, "Got 2 host:port-specific keys");
63 ok($cred->{password}, 'tzzknow', "Got correct host:port-specific password");
64 ok($cred->{username}, 'tzz', "Got correct host:port-specific username");
66 print "# Testing netrc file that 'host:port kills host' entry\n";
67 $cred = run_credential(['-f', $netrc, 'get'],
70 ok(scalar keys %$cred, 2, "Got 2 'host:port kills host' keys");
72 ok($cred->{password}, 'bobwillknow', "Got correct 'host:port kills host' password");
73 ok($cred->{username}, 'bob', "Got correct 'host:port kills host' username");
79 my $pid = open2(my $chld_out, my $chld_in,
80 './git-credential-netrc', @global_credential_args,
83 die "Couldn't open pipe to netrc credential helper: $!" unless $pid;
85 if (ref $data eq 'HASH')
87 print $chld_in "$_=$data->{$_}\n" foreach sort keys %$data;
91 print $chld_in "$data\n";
100 next unless m/^([^=]+)=(.+)/;