Commit 8fbbf89d authored by Christophe Maudoux's avatar Christophe Maudoux 🐛
Browse files

Improve handler unit tests

parent 9102cc2a
......@@ -4,7 +4,7 @@ BEGIN {
require 't/test-psgi-lib.pm';
}
my $maintests = 4;
my $maintests = 8;
SKIP: {
eval { require Digest::HMAC_SHA1; };
......@@ -16,7 +16,8 @@ SKIP: {
{
logLevel => 'error',
zimbraPreAuthKey => '1234567890',
zimbraSsoUrl => 'testsso',
zimbraUrl => '/service/preauthtest',
zimbraSsoUrl => '^/testsso',
vhostOptions => {
'test1.example.com' => {
vhostHttps => 0,
......@@ -32,6 +33,26 @@ SKIP: {
}
}
);
# Request a non-Zimbra URL
ok(
$res = $client->_get(
'/test', undef,
'test1.example.com', "lemonldap=$sessionId",
VHOSTTYPE => 'ZimbraPreAuth',
),
'Non-Zimbra URL Query'
);
ok( $res->[0] == 200, 'Code is 200' ) or explain( $res->[0], 200 );
# Check headers
%h = @{ $res->[1] };
ok( !defined $h{'Location'}, 'Location is undefined' )
or explain( \%h, 'Location => "URL"' );
ok( $h{'Auth-User'} eq 'dwho', 'Header Auth-User is set to "dwho"' )
or explain( \%h, 'Auth-User => "dwho"' );
# Request Zimbra URL
my $timestamp = time() * 1000;
my $value =
Digest::HMAC_SHA1::hmac_sha1_hex( "dwho|id|0|$timestamp", '1234567890' );
......@@ -41,7 +62,7 @@ SKIP: {
'test1.example.com', "lemonldap=$sessionId",
VHOSTTYPE => 'ZimbraPreAuth',
),
'Query'
'Zimbra URL Query'
);
ok( $res->[0] == 302, 'Code is 302' ) or explain( $res->[0], 302 );
......@@ -49,13 +70,13 @@ SKIP: {
%h = @{ $res->[1] };
ok(
$h{'Location'} =~
m%^/service/preauth\?account=dwho&by=id&timestamp=$timestamp&expires=0&preauth=$value$%,
m%^/service/preauthtest\?account=dwho&by=id&timestamp=$timestamp&expires=0&preauth=$value$%,
'Header Location is set to Zimbra URL'
) or explain( \%h, 'Location => "Zimbra URL"' );
ok( $h{'Auth-User'} eq 'dwho', 'Header Auth-User is set to "dwho"' )
or explain( \%h, 'Auth-User => "dwho"' );
count(4);
}
count($maintests);
done_testing( count() );
clean();
......@@ -4,7 +4,7 @@ BEGIN {
require 't/test-psgi-lib.pm';
}
my $maintests = 4;
my $maintests = 12;
SKIP: {
eval { require Cache::Memcached; };
......@@ -18,9 +18,10 @@ SKIP: {
init(
'Lemonldap::NG::Handler::Server',
{
logLevel => 'error',
secureTokenUrls => ['/secured'],
vhostOptions => {
logLevel => 'error',
secureTokenUrls => [ '^/secured$', '/test$' ],
secureTokenHeader => 'AuthToken',
vhostOptions => {
'test1.example.com' => {
vhostHttps => 0,
vhostPort => 80,
......@@ -36,22 +37,61 @@ SKIP: {
}
);
## Request secured URLs
# First URL
ok(
$res = $client->_get(
'/secured', undef,
'test1.example.com', "lemonldap=$sessionId",
VHOSTTYPE => 'SecureToken',
),
'Auth query'
'Auth secured URL query 1'
);
ok( $res->[0] == 200, 'Code is 200' ) or explain( $res->[0], 200 );
# Check headers
%h = @{ $res->[1] };
ok( $h{'Auth-Token'} =~ m%[0-9a-f]{32}%, 'Header "Auth-Token" found' )
or explain( \%h, 'Auth-Token => "md5 value"' );
ok( $h{'AuthToken'} =~ m%[0-9a-f]{32}%, 'Header "AuthToken" found' )
or explain( \%h, 'AuthToken => "md5 value"' );
ok( $h{'Auth-User'} eq 'dwho', 'Header Auth-User is set to "dwho"' )
or explain( \%h, 'Auth-User => "dwho"' );
# Second URL
ok(
$res = $client->_get(
'/try/test', undef,
'test1.example.com', "lemonldap=$sessionId",
VHOSTTYPE => 'SecureToken',
),
'Auth secured URL query 2'
);
ok( $res->[0] == 200, 'Code is 200' ) or explain( $res->[0], 200 );
# Check headers
%h = @{ $res->[1] };
ok( $h{'AuthToken'} =~ m%[0-9a-f]{32}%, 'Header "AuthToken" found' )
or explain( \%h, 'AuthToken => "md5 value"' );
ok( $h{'Auth-User'} eq 'dwho', 'Header Auth-User is set to "dwho"' )
or explain( \%h, 'Auth-User => "dwho"' );
## Request an unsecured URL
ok(
$res = $client->_get(
'/try', undef,
'test1.example.com', "lemonldap=$sessionId",
VHOSTTYPE => 'SecureToken',
),
'Auth unsecured URL query'
);
ok( $res->[0] == 200, 'Code is 200' ) or explain( $res->[0], 200 );
# Check headers
%h = @{ $res->[1] };
ok( !defined $h{'AuthToken'}, 'Header "AuthToken" not found' )
or explain( \%h, 'AuthToken => "md5 value"' );
ok( $h{'Auth-User'} eq 'dwho', 'Header Auth-User is set to "dwho"' )
or explain( \%h, 'Auth-User => "dwho"' );
}
count($maintests);
......
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