mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
contrib: better support symbolic port names in git-credential-netrc
To improve support for symbolic port names in netrc files, this changes does the following: - Treat symbolic port names as ports, not protocols in git-credential-netrc - Validate the SMTP server port provided to send-email - Convert the above symbolic port names to their numerical values. Before this change, it was not possible to have a SMTP server port set to "smtps" in a netrc file (e.g. Emacs' ~/.authinfo.gpg), as it would be registered as a protocol and break the match for a "smtp" protocol host, as queried for by git-send-email. Signed-off-by: Maxim Cournoyer <maxim@guixotic.coop> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
53ca38298d
commit
1926d9b6da
@@ -268,13 +268,16 @@ sub load_netrc {
|
||||
next;
|
||||
}
|
||||
if (defined $nentry->{port}) {
|
||||
if ($nentry->{port} =~ m/^\d+$/) {
|
||||
$num_port = $nentry->{port};
|
||||
delete $nentry->{port};
|
||||
} else {
|
||||
$num_port = Git::port_num($nentry->{port});
|
||||
unless ($num_port) {
|
||||
printf(STDERR "ignoring invalid port `%s' " .
|
||||
"from netrc file\n", $nentry->{port});
|
||||
}
|
||||
# Since we've already validated and converted
|
||||
# the port to its numerical value, do not
|
||||
# capture it as the `protocol' value, as used
|
||||
# to be the case for symbolic port names.
|
||||
delete $nentry->{port};
|
||||
}
|
||||
|
||||
# create the new entry for the credential helper protocol
|
||||
|
||||
@@ -45,7 +45,7 @@ chmod 0600, $netrc;
|
||||
diag "Testing with invalid data\n";
|
||||
$cred = run_credential(['-f', $netrc, 'get'],
|
||||
"bad data");
|
||||
ok(scalar keys %$cred == 4, "Got first found keys with bad data");
|
||||
ok(scalar keys %$cred == 3, "Got first found keys with bad data");
|
||||
|
||||
diag "Testing netrc file for a missing corovamilkbar entry\n";
|
||||
$cred = run_credential(['-f', $netrc, 'get'],
|
||||
@@ -64,12 +64,12 @@ is($cred->{username}, 'carol', "Got correct Github username");
|
||||
|
||||
diag "Testing netrc file for a username-specific entry\n";
|
||||
$cred = run_credential(['-f', $netrc, 'get'],
|
||||
{ host => 'imap', username => 'bob' });
|
||||
{ host => 'imap:993', username => 'bob' });
|
||||
|
||||
ok(scalar keys %$cred == 2, "Got 2 username-specific keys");
|
||||
# Only the password field gets returned.
|
||||
ok(scalar keys %$cred == 1, "Got 1 username-specific keys");
|
||||
|
||||
is($cred->{password}, 'bobwillknow', "Got correct user-specific password");
|
||||
is($cred->{protocol}, 'imaps', "Got correct user-specific protocol");
|
||||
|
||||
diag "Testing netrc file for a host:port-specific entry\n";
|
||||
$cred = run_credential(['-f', $netrc, 'get'],
|
||||
|
||||
Reference in New Issue
Block a user