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