2016-03-23 22:55:47 +01:00
|
|
|
use Test::More;
|
|
|
|
use JSON;
|
|
|
|
use MIME::Base64;
|
|
|
|
|
|
|
|
require 't/test-psgi-lib.pm';
|
|
|
|
|
|
|
|
my $app;
|
|
|
|
|
|
|
|
use_ok('Lemonldap::NG::Handler::PSGI::Try');
|
|
|
|
|
|
|
|
ok( $app = module( Lemonldap::NG::Handler::PSGI::Try->new() ), 'New object' );
|
|
|
|
|
|
|
|
init();
|
|
|
|
|
|
|
|
ok(
|
|
|
|
$app->init(
|
|
|
|
{
|
2017-10-30 21:24:59 +01:00
|
|
|
configStorage => { type => 'File', dirName => 't' },
|
|
|
|
localSessionStorage => '',
|
|
|
|
logLevel => 'warn',
|
|
|
|
cookieName => 'lemonldap',
|
|
|
|
securedCookie => 0,
|
|
|
|
https => 0,
|
2018-10-12 10:04:03 +02:00
|
|
|
userLogger => 'Lemonldap::NG::Common::Logger::Null',
|
2016-03-23 22:55:47 +01:00
|
|
|
}
|
|
|
|
),
|
|
|
|
'initialization'
|
|
|
|
);
|
|
|
|
|
|
|
|
ok( $app->addAuthRoute( test => sub { [ 200, [], ['Auth'] ] }, ['GET'] ),
|
|
|
|
'Set auth route' );
|
|
|
|
|
|
|
|
ok( $app->addUnauthRoute( test => sub { [ 200, [], ['Unauth'] ] }, ['GET'] ),
|
|
|
|
'Set auth route' );
|
|
|
|
|
|
|
|
count(4);
|
|
|
|
|
|
|
|
my $res;
|
|
|
|
|
|
|
|
# Unauth tests
|
|
|
|
ok( $res = $client->_get('/test'), 'Get response' );
|
|
|
|
ok( $res->[0] == 200, 'Response code is 200' )
|
|
|
|
or print "Expect 200, got $res->[0]\n";
|
|
|
|
ok( $res->[2]->[0] eq 'Unauth', 'Get unauth result' )
|
|
|
|
or print "Expect Unauth, got $res->[2]->[0]\n";
|
|
|
|
count(3);
|
|
|
|
|
|
|
|
# Auth tests
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/test',
|
|
|
|
undef,
|
|
|
|
undef,
|
|
|
|
'lemonldap=f5eec18ebb9bc96352595e2d8ce962e8ecf7af7c9a98cb9a43f9cd181cf4b545'
|
|
|
|
),
|
|
|
|
'Get response'
|
|
|
|
);
|
|
|
|
ok( $res->[0] == 200, 'Response code is 200' )
|
|
|
|
or print "Expect 200, got $res->[0]\n";
|
|
|
|
ok( $res->[2]->[0] eq 'Auth', 'Get auth result' )
|
|
|
|
or print "Expect Auth, got $res->[2]->[0]\n";
|
|
|
|
count(3);
|
|
|
|
|
2017-01-10 07:04:38 +01:00
|
|
|
# Pad path test
|
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
ok( $res = $client->_get('/[]/test'), 'Try a bad path' );
|
2017-01-10 07:04:38 +01:00
|
|
|
ok( $res->[0] == 400, 'Response is 400' );
|
|
|
|
count(2);
|
|
|
|
|
2016-06-12 18:52:34 +02:00
|
|
|
clean();
|
|
|
|
|
2016-03-23 22:55:47 +01:00
|
|
|
done_testing( count() );
|
|
|
|
|