lemonldap-ng/lemonldap-ng-portal/t/04-Notification-File.t

104 lines
2.4 KiB
Perl
Raw Normal View History

2016-05-31 13:47:08 +02:00
use Test::More;
use strict;
use IO::String;
require 't/test-lib.pm';
my $res;
my $file = 't/20160530_dwho_dGVzdHJlZg==.xml';
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>';
2016-05-31 13:47:08 +02:00
close F;
2016-11-14 13:34:46 +01:00
my $client = LLNG::Manager::Test->new(
2016-05-31 13:47:08 +02:00
{
2016-11-14 13:34:46 +01:00
ini => {
logLevel => 'error',
useSafeJail => 1,
notifications => 1,
templatesDir => 'site/templates/',
notificationStorage => 'File',
notificationStorageOptions => {
dirName => 't'
},
}
2016-05-31 13:47:08 +02:00
}
);
# Try yo authenticate
# -------------------
ok(
2016-11-14 13:34:46 +01:00
$res = $client->_post(
2016-05-31 13:47:08 +02:00
'/',
IO::String->new(
'user=dwho&password=dwho&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='),
accept => 'text/html',
length => 64,
),
'Auth query'
);
2016-12-23 07:41:03 +01:00
count(1);
expectOK($res);
my $id = expectCookie($res);
2016-05-31 13:47:08 +02:00
2016-05-31 22:41:35 +02:00
# Verify that cookie is ciphered (session unvalid)
ok(
2016-11-14 13:34:46 +01:00
$res = $client->_get(
2016-05-31 22:41:35 +02:00
'/',
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
cookie => "lemonldap=$id",
),
'Test cookie received'
);
2016-12-23 07:41:03 +01:00
count(1);
expectReject($res);
2016-05-31 22:41:35 +02:00
# Try to validate notification without accepting it
2016-05-31 23:52:18 +02:00
my $str = 'reference1x1=testref&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
2016-05-31 22:41:35 +02:00
ok(
2016-11-14 13:34:46 +01:00
$res = $client->_post(
2016-05-31 22:41:35 +02:00
'/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 );
count(2);
2016-05-31 23:52:18 +02:00
# Try to validate notification
2016-12-23 07:41:03 +01:00
$str =
2016-11-14 13:34:46 +01:00
'reference1x1=testref&check1x1x1=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
2016-05-31 23:52:18 +02:00
ok(
2016-11-14 13:34:46 +01:00
$res = $client->_post(
2016-05-31 23:52:18 +02:00
'/notifback',
IO::String->new($str),
cookie => "lemonldap=$id",
accept => 'text/html',
length => length($str),
),
"Accept notification"
);
2016-12-23 07:41:03 +01:00
expectRedirection( $res, qr/./ );
2016-06-01 21:19:53 +02:00
$file =~ s/xml$/done/;
2016-11-14 13:34:46 +01:00
ok( -e $file, 'Notification was deleted' );
2016-12-23 07:41:03 +01:00
count(2);
2016-05-31 23:52:18 +02:00
#print STDERR Dumper($res);
2016-05-31 13:47:08 +02:00
clean_sessions();
unlink $file;
done_testing( count() );