Commit 8d1c669a authored by Yadd's avatar Yadd
Browse files

#595 in progress...

parent a16d452a
......@@ -120,8 +120,8 @@ sub _del {
sub jsonResponse {
my ( $self, $path, $query ) = @_;
my $res = $self->_get( $path, $query )
or die "Manager lib has refused my get, aborting";
die "Manager lib does not return a 200 code, aborting"
or die "PSGI lib has refused my get, aborting";
die "PSGI lib does not return a 200 code, aborting"
unless ( $res->[0] == 200 );
my $href = from_json( $res->[2]->[0] ) or die 'Response is not JSON';
return $href;
......@@ -130,8 +130,8 @@ sub jsonResponse {
sub jsonPostResponse {
my ( $self, $path, $query, $body, $type, $len ) = @_;
my $res = $self->_post( $path, $query, $body, $type, $len )
or die "Manager lib has refused my post, aborting";
die "Manager lib does not return a 200 code, aborting"
or die "PSGI lib has refused my post, aborting";
die "PSGI lib does not return a 200 code, aborting"
unless ( $res->[0] == 200 );
my $href = from_json( $res->[2]->[0] ) or die 'Response is not JSON';
return $href;
......@@ -140,8 +140,8 @@ sub jsonPostResponse {
sub jsonPutResponse {
my ( $self, $path, $query, $body, $type, $len ) = @_;
my $res = $self->_put( $path, $query, $body, $type, $len )
or die "Manager lib has refused my put, aborting";
die "Manager lib does not return a 200 code, aborting"
or die "PSGI lib has refused my put, aborting";
die "PSGI lib does not return a 200 code, aborting"
unless ( $res->[0] == 200 );
my $href = from_json( $res->[2]->[0] ) or die 'Response is not JSON';
return $href;
......
......@@ -71,7 +71,7 @@ has QUERY_STRING => (
);
sub _urlcode2params {
my ( $self, $str ) = shift;
my ( $self, $str ) = @_;
my @tmp = $str ? map { uri_unescape($_) } split( /&/, $str ) : ();
foreach my $s (@tmp) {
if ( $s =~ /^(.+?)=(.+)$/ ) { $self->{_params}->{$1} = $2; }
......
......@@ -99,9 +99,6 @@ sub extractFormInfo {
# Other parameters
$req->{timezone} = $req->param('timezone');
# Check user
return PE_MALFORMEDUSER unless $self->get_user;
PE_OK;
}
......
......@@ -3,6 +3,7 @@ package Lemonldap::NG::Portal::Main::Constants;
use strict;
use Exporter 'import';
use constant HANDLER => 'Lemonldap::NG::Handler::PSGI::API';
use constant {
# Portal errors
......@@ -150,6 +151,7 @@ our @EXPORT = qw( PE_IMG_NOK PE_IMG_OK PE_INFO PE_REDIRECT PE_DONE PE_OK
PM_LAST_LOGINS PM_LAST_FAILED_LOGINS PM_OIDC_CONSENT PM_OIDC_SCOPE_OPENID
PM_OIDC_SCOPE_PROFILE PM_OIDC_SCOPE_EMAIL PM_OIDC_SCOPE_ADDRESS
PM_OIDC_SCOPE_PHONE PM_OIDC_SCOPE_OTHER PM_OIDC_CONFIRM_LOGOUT
HANDLER
);
our %EXPORT_TAGS = ( 'all' => [ @EXPORT, 'import' ], );
......
......@@ -11,6 +11,7 @@ package Lemonldap::NG::Portal::Main::Init;
use strict;
use Mouse;
use Lemonldap::NG::Common::Conf::Constants;
use Lemonldap::NG::Portal::Main::Constants;
use Lemonldap::NG::Handler::Main::Reload qw/keepConf/;
use Lemonldap::NG::Portal::Main::Plugins;
use Regexp::Assemble;
......@@ -20,8 +21,6 @@ our $VERSION = '2.0.0';
extends 'Lemonldap::NG::Handler::PSGI::Try',
'Lemonldap::NG::Portal::Main::Plugins';
use constant HANDLER => 'Lemonldap::NG::Handler::PSGI::API';
# Configuration storage
has localConfig => ( is => 'rw', default => sub { {} } );
has conf => ( is => 'rw', default => sub { {} } );
......
......@@ -5,6 +5,7 @@ use Mouse;
use Lemonldap::NG::Portal::Main::Constants;
use Lemonldap::NG::Portal::Main::Request;
use MIME::Base64;
use POSIX qw(strftime);
our $VERSION = '2.0.0';
......@@ -21,9 +22,11 @@ sub process {
my $err = PE_OK;
while ( my $sub = shift @{ $req->steps } ) {
if ( ref $sub ) {
$self->lmLog( "Processing code ref", 'debug' );
last if ( $sub->($req) );
}
else {
$self->lmLog( "Processing $sub", 'debug' );
last if ( $err = $self->$sub($req) );
}
}
......
......@@ -17,6 +17,7 @@ has datas => ( is => 'rw', default => sub { {} } );
# Session datas when created
has id => ( is => 'rw' );
has sessionInfo => ( is => 'rw' );
has user => ( is => 'rw' );
# Response cookies (list of strings built by cookie())
has respCookies => ( is => 'rw' );
......
......@@ -16,8 +16,6 @@ use Lemonldap::NG::Portal::Main::Request;
extends 'Lemonldap::NG::Portal::Main::Process';
use constant HANDLER => 'Lemonldap::NG::Handler::PSGI::API';
our $VERSION = '2.0.0';
# List constants
......@@ -86,14 +84,14 @@ sub postLogin {
'restoreArgs', 'controlUrl',
@{ $self->beforeAuth }, &authProcess,
@{ $self->betweenAuthAndDatas }, &sessionDatas,
@{ $self->afterdatas },
@{ $self->afterDatas },
]
);
}
sub authenticatedRequest {
my ( $self, $req ) = @_;
return $self->do( $req, $self->forAuthUser );
return $self->do( $req, [ 'controlUrl', @{ $self->forAuthUser } ] );
}
# RUNNING METHODS
......
......@@ -19,9 +19,9 @@ our $VERSION = '2.0.0';
sub init {
my $self = shift;
unless ( $self->p->getModule( undef, 'auth' ) =~ /^Demo/ ) {
$self->lmLog( "Use UserDBDemo only with AuthDemo", 'error' );
return PE_ERROR;
unless ( $self->p->getModule( undef, 'auth' ) =~ /Demo/ ) {
$self->p->error("Use UserDB::Demo only with Auth::Demo");
return 0;
}
# Sample accounts from Doctor Who characters
......@@ -53,9 +53,9 @@ sub getUser {
my ( $self, $req ) = @_;
# Search by login
if ( $req->{user} ) {
if ( $req->user ) {
return PE_OK
if ( defined $self->{_demoAccounts}->{ $req->{user} } );
if ( defined $self->{_demoAccounts}->{ $req->user } );
}
# Search by mail
......
use Test::More;
use strict;
use IO::String;
require 't/test-lib.pm';
print STDERR Dumper(&client->_get('/'));
my $res;
ok( $res = &client->_get('/'), 'Unauth JSON request' );
ok( $res->[0] == 401, 'Response is 401' ) or explain( $res, 401 );
count(2);
#ok( $res = &client->jsonPostResponse('/','',IO::String->new('user=dwho&password=dwho'),'application/x-www-form-urlencoded',23), 'Auth query');
#count(1);
done_testing( count() );
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment