[svk-commit] r2126 - in trunk: lib/SVK lib/SVK/Mirror/Backend
clkao at bestpractical.com
clkao at bestpractical.com
Thu Nov 9 22:07:48 EST 2006
Author: clkao
Date: Thu Nov 9 22:07:47 2006
New Revision: 2126
Modified:
trunk/lib/SVK/Config.pm
trunk/lib/SVK/Mirror/Backend/SVNRa.pm
trunk/t/mirror/dav-authz.t
Log:
Make ra auth providers overridable.
Modified: trunk/lib/SVK/Config.pm
==============================================================================
--- trunk/lib/SVK/Config.pm (original)
+++ trunk/lib/SVK/Config.pm Thu Nov 9 22:07:47 2006
@@ -4,7 +4,31 @@
use base 'Class::Data::Inheritable';
-__PACKAGE__->mk_classdata(qw(_svnconfig));
+__PACKAGE__->mk_classdata('_svnconfig');
+__PACKAGE__->mk_classdata('auth_providers');
+
+# XXX: this is 1.3 api. use SVN::Auth::* for 1.4 and we don't have to load ::Client anymore
+require SVN::Client;
+__PACKAGE__->auth_providers(
+ sub {
+ [
+ SVN::Client::get_simple_provider(),
+ SVN::Client::get_ssl_server_trust_file_provider(),
+ SVN::Client::get_username_provider(),
+ SVN::Client::get_simple_prompt_provider( \&_simple_prompt, 2 ),
+ SVN::Client::get_ssl_server_trust_prompt_provider(
+ \&_ssl_server_trust_prompt
+ ),
+ SVN::Client::get_ssl_client_cert_prompt_provider(
+ \&_ssl_client_cert_prompt, 2
+ ),
+ SVN::Client::get_ssl_client_cert_pw_prompt_provider(
+ \&_ssl_client_cert_pw_prompt, 2
+ ),
+ SVN::Client::get_username_prompt_provider( \&_username_prompt, 2 ),
+ ];
+ }
+);
my $pool = SVN::Pool->new;
@@ -18,4 +42,132 @@
return $class->_svnconfig( SVN::Core::config_get_config(undef, $pool) );
}
+# Note: Use a proper default pool when calling get_auth_providers
+sub get_auth_providers {
+ my $class = shift;
+ return $class->auth_providers->();
+}
+
+use constant OK => $SVN::_Core::SVN_NO_ERROR;
+
+# Implement auth callbacks
+sub _simple_prompt {
+ my ($cred, $realm, $default_username, $may_save, $pool) = @_;
+
+ if (defined $default_username and length $default_username) {
+ print "Authentication realm: $realm\n" if defined $realm and length $realm;
+ $cred->username($default_username);
+ }
+ else {
+ _username_prompt($cred, $realm, $may_save, $pool);
+ }
+
+ $cred->password(_read_password("Password for '" . $cred->username . "': "));
+ $cred->may_save($may_save);
+
+ return OK;
+}
+
+sub _ssl_server_trust_prompt {
+ my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_;
+
+ print "Error validating server certificate for '$realm':\n";
+
+ print " - The certificate is not issued by a trusted authority. Use the\n",
+ " fingerprint to validate the certificate manually!\n"
+ if ($failures & $SVN::Auth::SSL::UNKNOWNCA);
+
+ print " - The certificate hostname does not match.\n"
+ if ($failures & $SVN::Auth::SSL::CNMISMATCH);
+
+ print " - The certificate is not yet valid.\n"
+ if ($failures & $SVN::Auth::SSL::NOTYETVALID);
+
+ print " - The certificate has expired.\n"
+ if ($failures & $SVN::Auth::SSL::EXPIRED);
+
+ print " - The certificate has an unknown error.\n"
+ if ($failures & $SVN::Auth::SSL::OTHER);
+
+ printf(
+ "Certificate information:\n".
+ " - Hostname: %s\n".
+ " - Valid: from %s until %s\n".
+ " - Issuer: %s\n".
+ " - Fingerprint: %s\n",
+ map $cert_info->$_, qw(hostname valid_from valid_until issuer_dname fingerprint)
+ );
+
+ print(
+ $may_save
+ ? "(R)eject, accept (t)emporarily or accept (p)ermanently? "
+ : "(R)eject or accept (t)emporarily? "
+ );
+
+ my $choice = lc(substr(<STDIN> || 'R', 0, 1));
+
+ if ($choice eq 't') {
+ $cred->may_save(0);
+ $cred->accepted_failures($failures);
+ }
+ elsif ($may_save and $choice eq 'p') {
+ $cred->may_save(1);
+ $cred->accepted_failures($failures);
+ }
+
+ return OK;
+}
+
+sub _ssl_client_cert_prompt {
+ my ($cred, $realm, $may_save, $pool) = @_;
+
+ print "Client certificate filename: ";
+ chomp(my $filename = <STDIN>);
+ $cred->cert_file($filename);
+
+ return OK;
+}
+
+sub _ssl_client_cert_pw_prompt {
+ my ($cred, $realm, $may_save, $pool) = @_;
+
+ $cred->password(_read_password("Passphrase for '%s': "));
+
+ return OK;
+}
+
+sub _username_prompt {
+ my ($cred, $realm, $may_save, $pool) = @_;
+
+ print "Authentication realm: $realm\n" if defined $realm and length $realm;
+ print "Username: ";
+ chomp(my $username = <STDIN>);
+ $username = '' unless defined $username;
+
+ $cred->username($username);
+
+ return OK;
+}
+
+sub _read_password {
+ my ($prompt) = @_;
+
+ print $prompt;
+
+ require Term::ReadKey;
+ Term::ReadKey::ReadMode('noecho');
+
+ my $password = '';
+ while (defined(my $key = Term::ReadKey::ReadKey(0))) {
+ last if $key =~ /[\012\015]/;
+ $password .= $key;
+ }
+
+ Term::ReadKey::ReadMode('restore');
+ print "\n";
+
+ return $password;
+}
+
+
1;
Modified: trunk/lib/SVK/Mirror/Backend/SVNRa.pm
==============================================================================
--- trunk/lib/SVK/Mirror/Backend/SVNRa.pm (original)
+++ trunk/lib/SVK/Mirror/Backend/SVNRa.pm Thu Nov 9 22:07:47 2006
@@ -4,13 +4,10 @@
use SVN::Core;
use SVN::Ra;
-use SVN::Client ();
use SVK::I18N;
use SVK::Editor;
use Class::Autouse qw(SVK::Editor::SubTree SVK::Editor::CopyHandler);
-use constant OK => $SVN::_Core::SVN_NO_ERROR;
-
## class SVK::Mirror::Backend::SVNRa;
## has $.mirror is weak;
## has ($!config, $!auth_baton, $!auth_ref);
@@ -274,140 +271,12 @@
my $auth_pool = SVN::Pool::create (${ $self->mirror->pool });
$auth_pool->default;
- my ($baton, $ref) = SVN::Core::auth_open_helper([
- SVN::Client::get_simple_provider (),
- SVN::Client::get_ssl_server_trust_file_provider (),
- SVN::Client::get_username_provider (),
- SVN::Client::get_simple_prompt_provider( $self->can('_simple_prompt'), 2),
- SVN::Client::get_ssl_server_trust_prompt_provider( $self->can('_ssl_server_trust_prompt') ),
- SVN::Client::get_ssl_client_cert_prompt_provider( $self->can('_ssl_client_cert_prompt'), 2 ),
- SVN::Client::get_ssl_client_cert_pw_prompt_provider( $self->can('_ssl_client_cert_pw_prompt'), 2 ),
- SVN::Client::get_username_prompt_provider( $self->can('_username_prompt'), 2),
- ]);
+ my ($baton, $ref) = SVN::Core::auth_open_helper(SVK::Config->get_auth_providers);
$self->_auth_baton($baton);
$self->_auth_ref($ref);
}
-# Implement auth callbacks
-sub _simple_prompt {
- my ($cred, $realm, $default_username, $may_save, $pool) = @_;
-
- if (defined $default_username and length $default_username) {
- print "Authentication realm: $realm\n" if defined $realm and length $realm;
- $cred->username($default_username);
- }
- else {
- _username_prompt($cred, $realm, $may_save, $pool);
- }
-
- $cred->password(_read_password("Password for '" . $cred->username . "': "));
- $cred->may_save($may_save);
-
- return OK;
-}
-
-sub _ssl_server_trust_prompt {
- my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_;
-
- print "Error validating server certificate for '$realm':\n";
-
- print " - The certificate is not issued by a trusted authority. Use the\n",
- " fingerprint to validate the certificate manually!\n"
- if ($failures & $SVN::Auth::SSL::UNKNOWNCA);
-
- print " - The certificate hostname does not match.\n"
- if ($failures & $SVN::Auth::SSL::CNMISMATCH);
-
- print " - The certificate is not yet valid.\n"
- if ($failures & $SVN::Auth::SSL::NOTYETVALID);
-
- print " - The certificate has expired.\n"
- if ($failures & $SVN::Auth::SSL::EXPIRED);
-
- print " - The certificate has an unknown error.\n"
- if ($failures & $SVN::Auth::SSL::OTHER);
-
- printf(
- "Certificate information:\n".
- " - Hostname: %s\n".
- " - Valid: from %s until %s\n".
- " - Issuer: %s\n".
- " - Fingerprint: %s\n",
- map $cert_info->$_, qw(hostname valid_from valid_until issuer_dname fingerprint)
- );
-
- print(
- $may_save
- ? "(R)eject, accept (t)emporarily or accept (p)ermanently? "
- : "(R)eject or accept (t)emporarily? "
- );
-
- my $choice = lc(substr(<STDIN> || 'R', 0, 1));
-
- if ($choice eq 't') {
- $cred->may_save(0);
- $cred->accepted_failures($failures);
- }
- elsif ($may_save and $choice eq 'p') {
- $cred->may_save(1);
- $cred->accepted_failures($failures);
- }
-
- return OK;
-}
-
-sub _ssl_client_cert_prompt {
- my ($cred, $realm, $may_save, $pool) = @_;
-
- print "Client certificate filename: ";
- chomp(my $filename = <STDIN>);
- $cred->cert_file($filename);
-
- return OK;
-}
-
-sub _ssl_client_cert_pw_prompt {
- my ($cred, $realm, $may_save, $pool) = @_;
-
- $cred->password(_read_password("Passphrase for '%s': "));
-
- return OK;
-}
-
-sub _username_prompt {
- my ($cred, $realm, $may_save, $pool) = @_;
-
- print "Authentication realm: $realm\n" if defined $realm and length $realm;
- print "Username: ";
- chomp(my $username = <STDIN>);
- $username = '' unless defined $username;
-
- $cred->username($username);
-
- return OK;
-}
-
-sub _read_password {
- my ($prompt) = @_;
-
- print $prompt;
-
- require Term::ReadKey;
- Term::ReadKey::ReadMode('noecho');
-
- my $password = '';
- while (defined(my $key = Term::ReadKey::ReadKey(0))) {
- last if $key =~ /[\012\015]/;
- $password .= $key;
- }
-
- Term::ReadKey::ReadMode('restore');
- print "\n";
-
- return $password;
-}
-
=back
=head2 METHODS
Modified: trunk/t/mirror/dav-authz.t
==============================================================================
--- trunk/t/mirror/dav-authz.t (original)
+++ trunk/t/mirror/dav-authz.t Thu Nov 9 22:07:47 2006
@@ -49,7 +49,7 @@
plan skip_all => "Can't find mod_dav_svn and mod_authz_svn";
}
-plan tests => 2;
+plan tests => 5;
my $utf8 = SVK::Util::get_encoding;
@@ -80,13 +80,55 @@
#our $DEBUG=1;
#$ENV{DEBUG_INTERACTIVE}=1;
-$svk->mirror ('//remote', "$uri/A");
+use SVK::Config;
+SVK::Config->auth_providers(
+ sub {
+ [ SVN::Client::get_simple_prompt_provider( \&my_prompt, 2 ) ]
+ }
+);
+
+my $prompt_called = 0;
+
+sub my_prompt {
+ my ($cred, $realm, $default_username, $may_save, $pool) = @_;
+ ++$prompt_called;
+ $cred->username('test');
+ $cred->password('test');
+ $cred->may_save(0);
+ return $SVN::_Core::SVN_NO_ERROR;
+}
+$svk->mirror ('//remote', "$uri/A");
is_output ($svk, 'sync', ['//remote'],
["Syncing $uri/A",
'Retrieving log information from 1 to 2',
'Committed revision 2 from revision 1.',
'Committed revision 3 from revision 2.']);
+ok($prompt_called, "prompt called");
+
+$svk->mirror('--detach', '//remote');
+
+###### readable root, C requires authz
+overwrite_file($policy, "
+[/]
+* = r
+test = rw
+[/C]
+* =
+test = rw
+");
+$svk->mkdir(-pm => 'something restricited', '/test/C/lala');
+
+$prompt_called = 0;
+$svk->mirror ('//remote-full', "$uri");
+ok($prompt_called, "prompt called");
+
+is_output ($svk, 'sync', ['//remote-full'],
+ ["Syncing $uri",
+ 'Retrieving log information from 1 to 3',
+ 'Committed revision 6 from revision 1.',
+ 'Committed revision 7 from revision 2.',
+ 'Committed revision 8 from revision 3.']);
$server->stop;
print "\n";
More information about the svk-commit
mailing list