Commit e6e0571c authored by Yadd's avatar Yadd
Browse files

Add handler test lib

parent 5124a489
......@@ -423,5 +423,6 @@ t/sessions2/6e30af4ffa5689b3e49a104d1b160d316db2b2161a0f45776994eed19dbdc101
t/sessions2/lock/Apache-Session-6e30af4ffa5689b3e49a104d1b160d316db2b2161a0f45776994eed19dbdc101.lock
t/test-ldap.pm
t/test-lib.pm
t/test-psgi.pm
t/testslapd/slapd.ldif
t/testslapd/users.ldif
......@@ -69,6 +69,13 @@ count(1);
expectOK($res);
expectAuthenticatedAs( $res, 'dwho' );
require 't/test-psgi.pm';
ok( $res = mirror( cookie => "lemonldap=$id" ), 'PSGI test' );
count(1);
expectOK($res);
expectAuthenticatedAs( $res, 'dwho' );
# Test logout
$client->logout($id);
......
package LLNG::Mirror;
use strict;
our @ISA = ('Lemonldap::NG::Handler::PSGI');
our $defaultIni = {
configStorage => { type => 'File', dirName => 't' },
localSessionStorage => '',
logLevel => 'error',
https => 0,
};
sub new {
my $self = Lemonldap::NG::Handler::PSGI->new();
$self->init($defaultIni);
bless $self, $_[0];
}
sub handler {
my ( $self, $req ) = @_;
my $h = $req->headers->as_string;
return [ 200, [ 'Content-Type' => 'text/plain' ], [$h] ];
}
package main;
BEGIN {
use_ok('Lemonldap::NG::Handler::PSGI');
count(1);
}
my $m = LLNG::Mirror->new;
my $app = $m->run;
sub mirror {
my (%args) = @_;
return $app->(
{
'HTTP_ACCEPT' => $args{accept}
|| 'application/json, text/plain, */*',
'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'HTTP_CACHE_CONTROL' => 'max-age=0',
( $args{cookie} ? ( HTTP_COOKIE => $args{cookie} ) : () ),
'HTTP_HOST' => $args{host} || 'test1.example.com',
'HTTP_USER_AGENT' =>
'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox',
'PATH_INFO' => $args{path} || '/',
( $args{referer} ? ( REFERER => $args{referer} ) : () ),
'REMOTE_ADDR' => '127.0.0.1',
(
$args{remote_user}
? ( 'REMOTE_USER' => $args{remote_user} )
: ()
),
'REQUEST_METHOD' => $args{method} || 'GET',
'REQUEST_URI' => ( $args{path} || '/' )
. ( $args{query} ? "?$args{query}" : '' ),
( $args{query} ? ( QUERY_STRING => $args{query} ) : () ),
'SCRIPT_NAME' => '',
'SERVER_NAME' => 'auth.example.com',
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
( $args{custom} ? %{ $args{custom} } : () ),
}
);
}
1;
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