fix tests for www_auth. fix deprecate for callers
This commit is contained in:
parent
5a2d4d8d03
commit
f515d85b2d
5 changed files with 32 additions and 17 deletions
|
|
@ -1102,7 +1102,7 @@ sub www_displayLogin {
|
|||
my $self = shift;
|
||||
my $method = $_[0] || "login";
|
||||
my $vars = $_[1];
|
||||
print "Auth->www_displayLogin\n";
|
||||
|
||||
# Automatically set redirectAfterLogin unless we've linked here directly
|
||||
# or it's already been set to perform another operation
|
||||
unless (
|
||||
|
|
@ -1288,7 +1288,7 @@ Override this method in your subclass to change the initialization for custom au
|
|||
|
||||
sub www_view {
|
||||
my $self = shift;
|
||||
return $self->displayLogin;
|
||||
return $self->www_displayLogin;
|
||||
}
|
||||
|
||||
deprecate init => 'www_view';
|
||||
|
|
|
|||
|
|
@ -773,7 +773,6 @@ The initial login screen an unauthenticated user sees
|
|||
sub www_displayLogin {
|
||||
my $self = shift;
|
||||
my $vars;
|
||||
print "WebGUI->www_displayLogin\n";
|
||||
return $self->www_displayAccount($_[0]) if ($self->isRegistered);
|
||||
my $i18n = WebGUI::International->new($self->session);
|
||||
$vars->{'login.message'} = '<ul>'.$_[0].'</ul>' if ($_[0]);
|
||||
|
|
|
|||
|
|
@ -33,19 +33,33 @@ sub deprecate ($$) {
|
|||
my $package = caller;
|
||||
no strict 'refs';
|
||||
no warnings 'redefine';
|
||||
*{"$package\::$old_method"} = \&{"$package\::$new_method"};
|
||||
my $proxy_method = sub {
|
||||
my $self = $_[0];
|
||||
my $sub = $self->can($old_method);
|
||||
my $class = ref $self || $self;
|
||||
if ($sub ne \&{"$package\::$old_method"}) {
|
||||
my $message = "$class contains the method $old_method. This has been deprecated and replaced with $new_method.";
|
||||
warn $message unless $warned{$message}++;
|
||||
$self->$new_method( @_ );
|
||||
}
|
||||
goto $sub;
|
||||
|
||||
my %deep;
|
||||
# keep a copy since it will be replaced
|
||||
my $new_sub = \&{"$package\::$new_method"};
|
||||
# call new method instead. if
|
||||
*{"$package\::$old_method"} = sub {
|
||||
my $self = shift;
|
||||
my $message = "$package\::$old_method is deprecated and should be replaced with $new_method at " . join( "-", (caller(0))[0,2] );
|
||||
warn $message
|
||||
unless $warned{$message}++;
|
||||
|
||||
local $deep{1} = 1;
|
||||
$self->$new_method(@_);
|
||||
};
|
||||
*{"$package\::$new_method"} = sub {
|
||||
my $self = $_[0];
|
||||
if (!$deep{1}) {
|
||||
my $old_sub = $self->can($old_method);
|
||||
if ($old_sub ne \&{"$package\::$old_method"}) {
|
||||
my $message = "Subclass of $package uses deprecated method $old_method, which should be replaced with $new_method";
|
||||
carp $message
|
||||
unless $warned{$message}++;
|
||||
goto $old_sub;
|
||||
}
|
||||
}
|
||||
goto $new_sub;
|
||||
};
|
||||
*{"$package\::$new_method"} = $proxy_method;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ sub www_auth {
|
|||
my $auth;
|
||||
($auth) = $session->db->quickArray("select authMethod from users where username=".$session->db->quote($session->form->process("username"))) if($session->form->process("username"));
|
||||
my $authMethod = getInstance($session,$auth);
|
||||
my $methodCall = shift || $session->form->process("method") || "init";
|
||||
my $methodCall = shift || $session->form->process("method") || "view";
|
||||
if(!$authMethod->isCallable($methodCall)){
|
||||
$session->log->security("access uncallable auth method: $methodCall");
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
|
|
|
|||
|
|
@ -85,13 +85,15 @@ $session->user({ userId => 3 });
|
|||
isa_ok(
|
||||
WebGUI::Operation::Auth::getInstance( $session ),
|
||||
'WebGUI::Auth::WebGUI',
|
||||
'AuthType is defined by the logged-in user',
|
||||
'AuthType is defined by the logged-in user, despite being in request',
|
||||
);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test the web method for auth operation
|
||||
# First a clean session, without an authenticated user
|
||||
$session->user({ userId => 1 });
|
||||
$session->request->setup_body({});
|
||||
|
||||
my $output = WebGUI::Operation::Auth::www_auth($session);
|
||||
like(
|
||||
$output,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue