2016-05-31 13:47:08 +02:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
|
|
|
|
my $res;
|
2017-03-27 18:51:18 +02:00
|
|
|
my $file = 't/20160530_dwho_dGVzdHJlZg==.xml';
|
2018-10-16 22:09:14 +02:00
|
|
|
my $maintests = 15;
|
2016-05-31 13:47:08 +02:00
|
|
|
|
2017-03-07 07:30:57 +01:00
|
|
|
SKIP: {
|
|
|
|
eval { require XML::LibXML; require XML::LibXSLT; };
|
|
|
|
if ($@) {
|
2018-02-08 21:55:21 +01:00
|
|
|
skip 'XML::LibX* not found', $maintests;
|
2017-03-07 07:30:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
open F, "> $file" or die($!);
|
|
|
|
print F '<?xml version="1.0" encoding="UTF-8"?>
|
2016-05-31 22:41:35 +02:00
|
|
|
<root><notification uid="dwho" date="2016-05-30" reference="testref">
|
2016-05-31 13:47:08 +02:00
|
|
|
<title>Test title</title>
|
|
|
|
<subtitle>Test subtitle</subtitle>
|
|
|
|
<text>This is a test text</text>
|
|
|
|
<check>Accept test</check>
|
2018-10-16 22:09:14 +02:00
|
|
|
<check>Accept test2</check>
|
2016-05-31 22:41:35 +02:00
|
|
|
</notification></root>';
|
2017-03-07 07:30:57 +01:00
|
|
|
close F;
|
2016-05-31 13:47:08 +02:00
|
|
|
|
2019-02-07 09:27:56 +01:00
|
|
|
my $client = LLNG::Manager::Test->new( {
|
2018-11-26 14:40:21 +01:00
|
|
|
ini => {
|
2017-03-07 07:30:57 +01:00
|
|
|
logLevel => 'error',
|
|
|
|
useSafeJail => 1,
|
|
|
|
notification => 1,
|
|
|
|
notificationStorage => 'File',
|
2018-10-15 22:07:41 +02:00
|
|
|
notificationStorageOptions => { dirName => 't' },
|
|
|
|
oldNotifFormat => 1,
|
2018-10-21 22:12:56 +02:00
|
|
|
portalMainLogo => 'common/logos/logo_llng_old.png',
|
2017-03-07 07:30:57 +01:00
|
|
|
}
|
2016-11-14 13:34:46 +01:00
|
|
|
}
|
2017-03-07 07:30:57 +01:00
|
|
|
);
|
2016-05-31 13:47:08 +02:00
|
|
|
|
2019-07-17 11:58:49 +02:00
|
|
|
# Try to authenticate
|
|
|
|
# -------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new(
|
|
|
|
'user=dwho&password=dwho&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='
|
|
|
|
),
|
|
|
|
accept => 'text/html',
|
|
|
|
length => 64,
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
expectOK($res);
|
|
|
|
my $id = expectCookie($res);
|
|
|
|
expectForm( $res, undef, '/notifback', 'reference1x1', 'url' );
|
|
|
|
|
|
|
|
# Verify that cookie is ciphered (session unvalid)
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/',
|
|
|
|
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
),
|
|
|
|
'Test cookie received'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
expectReject($res);
|
|
|
|
|
|
|
|
# Try to cancel notification
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/notifback',
|
|
|
|
query => "cancel=1",
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
length => 64,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
"Cancel notification"
|
|
|
|
);
|
|
|
|
|
|
|
|
my $c = getCookies($res);
|
2019-07-18 13:12:12 +02:00
|
|
|
ok( not( %$c{'lemonldap'} ), 'Cookie expired' ) or print STDERR Dumper($c);
|
2019-07-17 11:58:49 +02:00
|
|
|
count(2);
|
|
|
|
expectRedirection( $res, 'http://auth.example.com/' );
|
|
|
|
|
|
|
|
# Try to authenticate
|
2017-03-07 07:30:57 +01:00
|
|
|
# -------------------
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2017-03-07 07:30:57 +01:00
|
|
|
'/',
|
|
|
|
IO::String->new(
|
2018-11-26 14:40:21 +01:00
|
|
|
'user=dwho&password=dwho&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='
|
2017-03-07 07:30:57 +01:00
|
|
|
),
|
|
|
|
accept => 'text/html',
|
|
|
|
length => 64,
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
my $id = expectCookie($res);
|
|
|
|
expectForm( $res, undef, '/notifback', 'reference1x1', 'url' );
|
2016-05-31 13:47:08 +02:00
|
|
|
|
2017-03-07 07:30:57 +01:00
|
|
|
# Verify that cookie is ciphered (session unvalid)
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
2017-03-07 07:30:57 +01:00
|
|
|
'/',
|
|
|
|
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
),
|
|
|
|
'Test cookie received'
|
|
|
|
);
|
|
|
|
expectReject($res);
|
2016-05-31 22:41:35 +02:00
|
|
|
|
2017-03-07 07:30:57 +01:00
|
|
|
# Try to validate notification without accepting it
|
|
|
|
my $str = 'reference1x1=testref&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2017-03-07 07:30:57 +01:00
|
|
|
'/notifback',
|
|
|
|
IO::String->new($str),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($str),
|
|
|
|
),
|
|
|
|
"Don't accept notification"
|
|
|
|
);
|
2018-10-15 22:07:41 +02:00
|
|
|
ok( $res->[2]->[0] =~ qr%<h2 class="notifText">Test title</h2>%,
|
|
|
|
'Notification displayed' )
|
2018-11-26 14:40:21 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~ qr%<img src="/static/common/logos/logo_llng_old.png"%,
|
|
|
|
'Found custom Main Logo'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
2018-10-15 22:07:41 +02:00
|
|
|
|
|
|
|
# Try to validate notification without accepting it
|
|
|
|
$str = 'reference1x1=testref&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-10-15 22:07:41 +02:00
|
|
|
'/notifback',
|
|
|
|
IO::String->new($str),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($str),
|
|
|
|
),
|
|
|
|
"Don't accept notification"
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ qr%<h2 class="notifText">Test title</h2>%,
|
|
|
|
'Notification displayed' )
|
2018-11-26 14:40:21 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2018-10-15 22:07:41 +02:00
|
|
|
|
|
|
|
# Try to validate notification without accepting it
|
|
|
|
$str = 'reference1x1=testref&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-10-15 22:07:41 +02:00
|
|
|
'/notifback',
|
|
|
|
IO::String->new($str),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($str),
|
|
|
|
),
|
|
|
|
"Don't accept notification"
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ qr%<h2 class="notifText">Test title</h2>%,
|
|
|
|
'Notification displayed' )
|
2018-11-26 14:40:21 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2016-05-31 22:41:35 +02:00
|
|
|
|
2018-10-16 22:09:14 +02:00
|
|
|
# Try to validate notification with accepting just one checkbox
|
2018-11-26 14:40:21 +01:00
|
|
|
$str =
|
|
|
|
'reference1x1=testref&check1x1x1=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-10-16 22:09:14 +02:00
|
|
|
'/notifback',
|
|
|
|
IO::String->new($str),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($str),
|
|
|
|
),
|
|
|
|
"Don't accept notification - Accept just one checkbox"
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ qr%<h2 class="notifText">Test title</h2>%,
|
|
|
|
'Notification displayed' )
|
2018-11-26 14:40:21 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2018-10-16 22:09:14 +02:00
|
|
|
|
|
|
|
# Try to validate notification with accepting all ckeckboxes
|
2018-11-26 14:40:21 +01:00
|
|
|
$str =
|
|
|
|
'reference1x1=testref&check1x1x1=accepted&check1x1x2=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2017-03-07 07:30:57 +01:00
|
|
|
'/notifback',
|
|
|
|
IO::String->new($str),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($str),
|
|
|
|
),
|
|
|
|
"Accept notification"
|
|
|
|
);
|
|
|
|
expectRedirection( $res, qr/./ );
|
|
|
|
$file =~ s/xml$/done/;
|
|
|
|
ok( -e $file, 'Notification was deleted' );
|
|
|
|
|
2018-09-05 13:35:50 +02:00
|
|
|
$id = expectCookie($res);
|
|
|
|
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
2018-09-05 13:35:50 +02:00
|
|
|
'/',
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
length => 64,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'New auth query'
|
|
|
|
);
|
|
|
|
expectAuthenticatedAs( $res, 'dwho' );
|
|
|
|
ok( $res->[2]->[0] =~ /yourApp/s, 'Menu displayed' );
|
|
|
|
|
2017-03-07 07:30:57 +01:00
|
|
|
#print STDERR Dumper($res);
|
2016-05-31 23:52:18 +02:00
|
|
|
|
2017-03-07 07:30:57 +01:00
|
|
|
clean_sessions();
|
2016-05-31 13:47:08 +02:00
|
|
|
|
2017-03-07 07:30:57 +01:00
|
|
|
unlink $file;
|
2016-05-31 13:47:08 +02:00
|
|
|
|
2017-03-07 07:30:57 +01:00
|
|
|
}
|
2016-05-31 13:47:08 +02:00
|
|
|
|
2018-02-08 21:55:21 +01:00
|
|
|
count($maintests);
|
2016-05-31 13:47:08 +02:00
|
|
|
done_testing( count() );
|