2016-02-01 12:11:31 +01:00
|
|
|
# Base library for tests
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Data::Dumper;
|
|
|
|
use 5.10.0;
|
|
|
|
use_ok('Lemonldap::NG::Common::PSGI::Cli::Lib');
|
|
|
|
|
|
|
|
our $client;
|
2016-02-01 13:15:27 +01:00
|
|
|
our $count = 1;
|
2016-02-01 20:05:14 +01:00
|
|
|
$Data::Dumper::Deparse = 1;
|
|
|
|
|
|
|
|
my $module;
|
2016-02-01 12:11:31 +01:00
|
|
|
|
2016-02-01 13:15:27 +01:00
|
|
|
sub init {
|
2016-03-23 22:55:47 +01:00
|
|
|
my $arg = shift;
|
2016-04-29 09:27:26 +02:00
|
|
|
if ($arg) {
|
2016-03-23 22:55:47 +01:00
|
|
|
$module = $arg;
|
|
|
|
use_ok($module);
|
|
|
|
}
|
2016-02-01 20:05:14 +01:00
|
|
|
ok( $client = Lemonldap::NG::Handler::PSGI::Cli::Lib->new(),
|
|
|
|
'Client object' );
|
|
|
|
count(2);
|
2016-02-01 13:15:27 +01:00
|
|
|
}
|
2016-02-01 12:11:31 +01:00
|
|
|
|
|
|
|
sub client {
|
|
|
|
return $client;
|
|
|
|
}
|
|
|
|
|
2016-03-23 22:55:47 +01:00
|
|
|
sub module {
|
2016-04-29 09:27:26 +02:00
|
|
|
if ( my $arg = shift ) {
|
2016-03-23 22:55:47 +01:00
|
|
|
$module = $arg;
|
|
|
|
}
|
|
|
|
return $module;
|
|
|
|
}
|
|
|
|
|
2016-02-01 12:11:31 +01:00
|
|
|
sub count {
|
|
|
|
my $c = shift;
|
|
|
|
$count += $c if ($c);
|
|
|
|
return $count;
|
|
|
|
}
|
|
|
|
|
2016-02-01 20:05:14 +01:00
|
|
|
sub explain {
|
|
|
|
my ( $get, $ref ) = @_;
|
|
|
|
$get = Dumper($get) if ( ref $get );
|
|
|
|
print STDERR "Expect $ref, get $get\n";
|
|
|
|
}
|
|
|
|
|
2016-02-01 13:15:27 +01:00
|
|
|
package Lemonldap::NG::Handler::PSGI::Cli::Lib;
|
|
|
|
|
|
|
|
use Mouse;
|
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Common::PSGI::Cli::Lib';
|
|
|
|
|
2016-02-01 20:05:14 +01:00
|
|
|
has app => (
|
|
|
|
is => 'ro',
|
|
|
|
isa => 'CodeRef',
|
|
|
|
builder => sub {
|
|
|
|
return $module->run(
|
|
|
|
{
|
|
|
|
configStorage => { type => 'File', dirName => 't' },
|
2016-02-17 11:07:24 +01:00
|
|
|
logLevel => 'warn',
|
|
|
|
cookieName => 'lemonldap',
|
|
|
|
securedCookie => 0,
|
|
|
|
https => 0,
|
2016-02-01 20:05:14 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-02-01 13:15:27 +01:00
|
|
|
sub _get {
|
|
|
|
my ( $self, $path, $query, $host, $cookie ) = @_;
|
|
|
|
$query //= '';
|
|
|
|
$host ||= 'test1.example.com';
|
|
|
|
return $self->app->(
|
|
|
|
{
|
|
|
|
'HTTP_ACCEPT' => 'text/html',
|
|
|
|
'SCRIPT_NAME' => 'lmAuth',
|
|
|
|
'SERVER_NAME' => '127.0.0.1',
|
|
|
|
'QUERY_STRING' => $query,
|
|
|
|
'HTTP_CACHE_CONTROL' => 'max-age=0',
|
|
|
|
'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
|
|
|
|
'PATH_INFO' => $path,
|
|
|
|
'REQUEST_METHOD' => 'GET',
|
2016-02-01 20:05:14 +01:00
|
|
|
'REQUEST_URI' => '/lmauth',
|
|
|
|
'X_ORIGINAL_URI' => $path . ( $query ? "?$query" : '' ),
|
|
|
|
'SERVER_PORT' => '80',
|
2016-02-01 13:15:27 +01:00
|
|
|
'SERVER_PROTOCOL' => 'HTTP/1.1',
|
|
|
|
'HTTP_USER_AGENT' =>
|
|
|
|
'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox',
|
|
|
|
'REMOTE_ADDR' => '127.0.0.1',
|
2016-02-01 20:05:14 +01:00
|
|
|
'HTTP_HOST' => $host,
|
2016-02-17 11:07:24 +01:00
|
|
|
( $cookie ? ( HTTP_COOKIE => $cookie ) : ( HTTP_COOKIE => '' ) )
|
2016-02-01 13:15:27 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-02-01 12:11:31 +01:00
|
|
|
1;
|