Test & code refactoring(#2601)
This commit is contained in:
parent
ad1244f272
commit
d8c512547a
|
@ -67,6 +67,7 @@ t/01-Lemonldap-NG-Handler-Main.t
|
|||
t/05-Lemonldap-NG-Handler-Reload.t
|
||||
t/12-Lemonldap-NG-Handler-Jail.t
|
||||
t/13-Lemonldap-NG-Handler-Fake-Safe.t
|
||||
t/14-Lemonldap-NG-Handler-Rule-Building.t
|
||||
t/50-Lemonldap-NG-Handler-SecureToken.t
|
||||
t/51-Lemonldap-NG-Handler-Zimbra.t
|
||||
t/60-Lemonldap-NG-Handler-PSGI.t
|
||||
|
|
|
@ -510,6 +510,7 @@ t/24-AuthKerberos.t
|
|||
t/25-AuthSlave-with-Choice.t
|
||||
t/25-AuthSlave-with-Credentials.t
|
||||
t/26-AuthRemote.t
|
||||
t/27-AuthProxy-choice.t
|
||||
t/27-AuthProxy.t
|
||||
t/28-AuthChoice-and-password.t
|
||||
t/28-AuthChoice-with-captcha.t
|
||||
|
@ -574,6 +575,8 @@ t/32-OIDC-ClaimTypes.t
|
|||
t/32-OIDC-ClientCredentials-Grant.t
|
||||
t/32-OIDC-Code-Flow-with-2F-UpgradeOnly.t
|
||||
t/32-OIDC-Code-Flow-with-2F.t
|
||||
t/32-OIDC-Grant-Type-OAuth2-Handler-Rules.t
|
||||
t/32-OIDC-Grant-Type-Rules.t
|
||||
t/32-OIDC-Hooks.t
|
||||
t/32-OIDC-Macro.t
|
||||
t/32-OIDC-Offline-Session.t
|
||||
|
|
|
@ -4,28 +4,35 @@ use strict;
|
|||
use JSON;
|
||||
use Mouse;
|
||||
use Lemonldap::NG::Common::UserAgent;
|
||||
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_ERROR PE_BADCREDENTIALS);
|
||||
use Lemonldap::NG::Portal::Main::Constants qw(
|
||||
PE_OK
|
||||
PE_ERROR
|
||||
PE_BADCREDENTIALS
|
||||
);
|
||||
use Lemonldap::NG::Common::FormEncode;
|
||||
|
||||
our $VERSION = '2.0.12';
|
||||
our $VERSION = '2.0.14';
|
||||
|
||||
has ua => ( is => 'rw' );
|
||||
has ua => ( is => 'rw' );
|
||||
has sessionService => ( is => 'rw' );
|
||||
|
||||
# INITIALIZATION
|
||||
|
||||
sub init {
|
||||
my ($self) = @_;
|
||||
$self->conf->{remoteCookieName} ||= $self->conf->{cookieName};
|
||||
$self->conf->{proxySessionService} ||=
|
||||
$self->conf->{proxyAuthService} . '/session/my';
|
||||
$self->conf->{proxySessionService} =~ s#/*$##;
|
||||
$self->ua( Lemonldap::NG::Common::UserAgent->new( $self->conf ) );
|
||||
$self->ua->default_header( Accept => 'application/json' );
|
||||
|
||||
unless ( defined $self->conf->{proxyAuthService} ) {
|
||||
$self->error("Missing proxyAuthService parameter");
|
||||
return 0;
|
||||
}
|
||||
|
||||
my $sessionService = $self->conf->{proxySessionService}
|
||||
|| $self->conf->{proxyAuthService} . '/session/my';
|
||||
$sessionService =~ s#/*$##;
|
||||
$self->sessionService($sessionService);
|
||||
$self->ua( Lemonldap::NG::Common::UserAgent->new( $self->conf ) );
|
||||
$self->ua->default_header( Accept => 'application/json' );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -92,7 +99,7 @@ sub setSessionInfo {
|
|||
my ( $self, $req ) = @_;
|
||||
return PE_OK if ( $req->data->{_setSessionInfoDone} );
|
||||
my $q = HTTP::Request->new(
|
||||
GET => $self->conf->{proxySessionService} . '/global',
|
||||
GET => $self->sessionService() . '/global',
|
||||
[
|
||||
Cookie => $req->sessionInfo->{_proxyCookies},
|
||||
Accept => 'application/json'
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use IO::String;
|
||||
use LWP::UserAgent;
|
||||
|
||||
my $res;
|
||||
require 't/test-lib.pm';
|
||||
|
||||
my $client = LLNG::Manager::Test->new( {
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
useSafeJail => 1,
|
||||
authentication => 'Proxy',
|
||||
userDB => 'Same',
|
||||
proxyAuthService => 'http://auth.example.com',
|
||||
proxyAuthServiceChoiceParam => 'lmAuth',
|
||||
proxyAuthServiceChoiceValue => '2_Password',
|
||||
impersonationRule => 1
|
||||
}
|
||||
}
|
||||
);
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=dwho&password=dwho&spoofId=rtyler'),
|
||||
length => 38
|
||||
),
|
||||
'Auth query'
|
||||
);
|
||||
expectOK($res);
|
||||
my $id = expectCookie($res);
|
||||
|
||||
$client->logout($id);
|
||||
clean_sessions();
|
||||
|
||||
count(13);
|
||||
done_testing( count() );
|
||||
|
||||
# Redefine LWP methods for tests
|
||||
no warnings 'redefine';
|
||||
|
||||
sub LWP::UserAgent::request {
|
||||
my ( $self, $req ) = @_;
|
||||
|
||||
unless ( $req->uri->as_string =~
|
||||
m%http://auth.example.com(?:/session/my/global|\?logout=1)% )
|
||||
{
|
||||
ok( $req->content() =~ m%user=(?:dwho|rtyler)%, 'User found' )
|
||||
or print STDERR Dumper( $req->content() );
|
||||
ok( $req->content() =~ m%password=dwho%, 'Password found' )
|
||||
or print STDERR Dumper( $req->content() );
|
||||
ok( $req->content() =~ m%lmAuth=2_Password%, 'ChoiceParam found' )
|
||||
or print STDERR Dumper( $req->content() );
|
||||
ok( $req->content() =~ m%spoofId=rtyler%, 'SpoofId found' )
|
||||
or print STDERR Dumper( $req->content() );
|
||||
}
|
||||
|
||||
my $httpResp;
|
||||
my $s =
|
||||
'{"error":"0","id":"6e30af4ffa5689b3e49a104d1b160d316db2b2161a0f45776994eed19dbdc101","result":1}';
|
||||
$httpResp = HTTP::Response->new( 200, 'OK' );
|
||||
$httpResp->header( 'Content-Type', 'application/json' );
|
||||
$httpResp->header( 'Content-Length', length($s) );
|
||||
$httpResp->content($s);
|
||||
return $httpResp;
|
||||
}
|
|
@ -10,11 +10,11 @@ SKIP: {
|
|||
skip 'REMOTELLNG is not set', $maintests unless ( $ENV{REMOTELLNG} );
|
||||
my $client = LLNG::Manager::Test->new( {
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
useSafeJail => 1,
|
||||
authentication => 'Proxy',
|
||||
userDB => 'Same',
|
||||
soapAuthService => $ENV{REMOTELLNG},
|
||||
logLevel => 'error',
|
||||
useSafeJail => 1,
|
||||
authentication => 'Proxy',
|
||||
userDB => 'Same',
|
||||
proxyAuthService => $ENV{REMOTELLNG},
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue