From 1a16c2dbc85a0d606f37f451fab7187fc7a46cb1 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Sun, 3 Apr 2016 16:27:13 +0000 Subject: [PATCH] First running test (#595) --- .../NG/Handler/Main/SharedVariables.pm | 2 +- lemonldap-ng-manager/t/05-rest-api.t | 2 - .../lib/Lemonldap/NG/Portal/Main.pm | 1 - .../lib/Lemonldap/NG/Portal/Main/Run.pm | 2 + .../lib/Lemonldap/NG/Portal/Plugins/CDA.pm | 2 +- lemonldap-ng-portal/t/01-AuthDemo.t | 8 +++ lemonldap-ng-portal/t/lmConf-1.js | 58 +++++++++++++++++++ lemonldap-ng-portal/t/test-lib.pm | 46 +++++++++++++++ 8 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 lemonldap-ng-portal/t/01-AuthDemo.t create mode 100644 lemonldap-ng-portal/t/lmConf-1.js create mode 100644 lemonldap-ng-portal/t/test-lib.pm diff --git a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/SharedVariables.pm b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/SharedVariables.pm index 3a1e45798..800bcf129 100644 --- a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/SharedVariables.pm +++ b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/SharedVariables.pm @@ -36,7 +36,7 @@ our $_v = { session => {}, datas => {} }; BEGIN { # Thread shared accessors foreach ( - qw(tsv cfgNum lastCheck checkTime confAcc localConfig logLevel _logLevel logLevels) + qw(tsv cfgNum lastCheck checkTime confAcc localConfig logLevel _logLevel logLevels lmConf) ) { eval " sub $_ { diff --git a/lemonldap-ng-manager/t/05-rest-api.t b/lemonldap-ng-manager/t/05-rest-api.t index 24e8f87f0..0385564f6 100644 --- a/lemonldap-ng-manager/t/05-rest-api.t +++ b/lemonldap-ng-manager/t/05-rest-api.t @@ -1,5 +1,3 @@ -#!/usr/bin/env perl -I pl/lib -# # Test REST API with valid and invalid requests. # Check also metadatas request (root of a conf) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main.pm index e7f5cb11d..ba1b703cd 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main.pm @@ -9,7 +9,6 @@ extends( 'Lemonldap::NG::Handler::PSGI::Try', 'Lemonldap::NG::Portal::Main::Init', 'Lemonldap::NG::Portal::Main::Run', - 'Lemonldap::NG::Portal::Main::Process', ); 1; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm index 4d0466e3a..c6ad2a7e2 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -14,6 +14,8 @@ use Mouse; use Lemonldap::NG::Portal::Main::Constants; use Lemonldap::NG::Portal::Main::Request; +extends 'Lemonldap::NG::Portal::Main::Process'; + our $VERSION = '2.0.0'; # List constants diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/CDA.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/CDA.pm index 73b63b2f8..56f216968 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/CDA.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/CDA.pm @@ -14,7 +14,7 @@ sub changeUrldc { my $urldc = $req->datas->{urldc}; if ( $req->id and $urldc !~ m#^https?://[^/]*$self->{conf}->{domain}(:\d+)?/#oi - and $self->isTrustedUrl($urldc) ) + and $self->p->isTrustedUrl($urldc) ) { my $ssl = $urldc =~ /^https/; $self->lmLog( 'CDA request', 'debug' ); diff --git a/lemonldap-ng-portal/t/01-AuthDemo.t b/lemonldap-ng-portal/t/01-AuthDemo.t new file mode 100644 index 000000000..ff100f805 --- /dev/null +++ b/lemonldap-ng-portal/t/01-AuthDemo.t @@ -0,0 +1,8 @@ +use Test::More; +use strict; + +require 't/test-lib.pm'; + +print STDERR Dumper(&client); + +done_testing( count() ); diff --git a/lemonldap-ng-portal/t/lmConf-1.js b/lemonldap-ng-portal/t/lmConf-1.js new file mode 100644 index 000000000..fe9eecd9e --- /dev/null +++ b/lemonldap-ng-portal/t/lmConf-1.js @@ -0,0 +1,58 @@ +{ + "authentication": "Demo", + "cfgAuthor": "The LemonLDAP::NG team", + "cfgAuthorIP": "127.0.0.1", + "cfgDate": 1428138808, + "cfgLog": "Handler test conf", + "cfgNum": "1", + "cookieName": "lemonldap", + "demoExportedVars": { + "cn": "cn", + "mail": "mail", + "uid": "uid" + }, + "domain": "example.com", + "exportedHeaders": { + "test1.example.com": { + "Auth-User": "$uid" + }, + "test2.example.com": { + "Auth-User": "$uid" + } + }, + "exportedVars": { + "UA": "HTTP_USER_AGENT" + }, + "globalStorage": "Apache::Session::File", + "globalStorageOptions": { + "Directory": "t/sessions", + "LockDirectory": "t/sessions/lock", + "generateModule": "Lemonldap::NG::Common::Apache::Session::Generate::SHA256" + }, + "groups": {}, + "key": "qwertyui", + "locationRules": { + "manager.example.com": { + "(?#Configuration)^/(manager\\.html|conf/)": "$uid eq \"dwho\"", + "(?#Notifications)^/notifications": "$uid eq \"dwho\" or $uid eq \"rtyler\"", + "(?#Sessions)^/sessions": "$uid eq \"dwho\" or $uid eq \"rtyler\"", + "default": "$uid eq \"dwho\"" + }, + "test1.example.com": { + "^/logout": "logout_sso", + "^/deny": "deny", + "default": "accept" + }, + "test2.example.com": { + "^/logout": "logout_sso", + "default": "accept" + } + }, + "macros": { + "_whatToTrace": "$_auth eq 'SAML' ? \"$_user\\@$_idpConfKey\" : \"$_user\"" + }, + "portal": "http://auth.example.com/", + "reloadUrls": {}, + "userDB": "Demo", + "whatToTrace": "_whatToTrace" +} diff --git a/lemonldap-ng-portal/t/test-lib.pm b/lemonldap-ng-portal/t/test-lib.pm new file mode 100644 index 000000000..2def5738a --- /dev/null +++ b/lemonldap-ng-portal/t/test-lib.pm @@ -0,0 +1,46 @@ +# Base library for portal tests + +use strict; +use Data::Dumper; +use 5.10.0; +use_ok('Lemonldap::NG::Common::PSGI::Cli::Lib'); +use_ok('Lemonldap::NG::Portal::Main'); + +our $client; +our $count = 3; +$Data::Dumper::Deparse = 1; + +ok( + $client = Lemonldap::NG::Common::PSGI::Cli::Lib->new( + { + app => Lemonldap::NG::Portal::Main->run( + { + configStorage => { type => 'File', dirName => 't' }, + logLevel => 'warn', + cookieName => 'lemonldap', + securedCookie => 0, + https => 0, + } + ), + } + ), + 'Portal app' +); + +sub client { + return $client; +} + +sub count { + my $c = shift; + $count += $c if ($c); + return $count; +} + +sub explain { + my ( $get, $ref ) = @_; + $get = Dumper($get) if ( ref $get ); + print STDERR "Expect $ref, get $get\n"; +} + +1;