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-02-08 21:55:21 +01:00
|
|
|
my $maintests = 6;
|
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>
|
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
|
|
|
|
2017-03-07 07:30:57 +01:00
|
|
|
my $client = LLNG::Manager::Test->new(
|
|
|
|
{
|
|
|
|
ini => {
|
|
|
|
logLevel => 'error',
|
|
|
|
useSafeJail => 1,
|
|
|
|
notification => 1,
|
|
|
|
templatesDir => 'site/templates/',
|
|
|
|
notificationStorage => 'File',
|
|
|
|
notificationStorageOptions => {
|
|
|
|
dirName => 't'
|
|
|
|
},
|
|
|
|
oldNotifFormat => 1,
|
|
|
|
}
|
2016-11-14 13:34:46 +01:00
|
|
|
}
|
2017-03-07 07:30:57 +01:00
|
|
|
);
|
2016-05-31 13:47:08 +02:00
|
|
|
|
2017-03-07 07:30:57 +01:00
|
|
|
# Try yo authenticate
|
|
|
|
# -------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new(
|
|
|
|
'user=dwho&password=dwho&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='
|
|
|
|
),
|
|
|
|
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)
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/',
|
|
|
|
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==';
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/notifback',
|
|
|
|
IO::String->new($str),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($str),
|
|
|
|
),
|
|
|
|
"Don't accept notification"
|
|
|
|
);
|
|
|
|
ok( $res->[0] == 200, "Don't receive redirection" )
|
|
|
|
or explain( [ $res->[0], $res->[1] ], 200 );
|
2016-05-31 22:41:35 +02:00
|
|
|
|
2017-03-07 07:30:57 +01:00
|
|
|
# Try to validate notification
|
|
|
|
$str =
|
2016-11-14 13:34:46 +01:00
|
|
|
'reference1x1=testref&check1x1x1=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
|
2017-03-07 07:30:57 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/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' );
|
|
|
|
|
|
|
|
#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() );
|