2017-01-31 23:31:25 +01:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
|
|
|
|
my $res;
|
|
|
|
my $file = 't/notifications.db';
|
2018-02-08 21:55:21 +01:00
|
|
|
my $maintests = 6;
|
2017-01-31 23:31:25 +01:00
|
|
|
eval { unlink $file };
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
|
|
|
|
SKIP: {
|
|
|
|
eval { require DBI; require DBD::SQLite; };
|
|
|
|
if ($@) {
|
2018-02-08 21:55:21 +01:00
|
|
|
skip 'DBD::SQLite not found', $maintests;
|
2017-01-31 23:31:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
my $dbh = DBI->connect("dbi:SQLite:dbname=$file");
|
|
|
|
$dbh->do(
|
|
|
|
'CREATE TABLE notifications (uid text,ref text,date datetime,xml text,cond text,done datetime)'
|
|
|
|
);
|
|
|
|
$dbh->prepare(
|
|
|
|
q{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00',?,null,null)}
|
2018-11-26 14:40:21 +01:00
|
|
|
)->execute(
|
2017-01-31 23:31:25 +01:00
|
|
|
'[
|
|
|
|
{
|
|
|
|
"uid": "dwho",
|
|
|
|
"date": "2016-05-30",
|
|
|
|
"reference": "testref",
|
|
|
|
"title": "Test title",
|
|
|
|
"subtitle": "Test subtitle",
|
|
|
|
"text": "This is a test text",
|
|
|
|
"check": ["Accept test"]
|
|
|
|
}
|
|
|
|
]'
|
2018-11-26 14:40:21 +01:00
|
|
|
);
|
2017-01-31 23:31:25 +01:00
|
|
|
|
|
|
|
my $client = LLNG::Manager::Test->new(
|
|
|
|
{
|
|
|
|
ini => {
|
|
|
|
logLevel => 'error',
|
|
|
|
useSafeJail => 1,
|
2017-02-02 06:37:58 +01:00
|
|
|
notification => 1,
|
2017-01-31 23:31:25 +01:00
|
|
|
templatesDir => 'site/templates/',
|
|
|
|
notificationStorage => 'DBI',
|
|
|
|
notificationStorageOptions => {
|
|
|
|
dbiChain => "dbi:SQLite:dbname=$file",
|
|
|
|
},
|
|
|
|
oldNotifFormat => 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
# 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);
|
2017-02-15 07:41:50 +01:00
|
|
|
ok( $res->[2]->[0] =~ /1x1x1/, ' Found ref' );
|
2017-02-02 13:29:59 +01:00
|
|
|
expectForm( $res, undef, '/notifback', 'reference1x1', 'url' );
|
2017-01-31 23:31:25 +01:00
|
|
|
|
|
|
|
# Verify that cookie is ciphered (session unvalid)
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/',
|
|
|
|
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
),
|
|
|
|
'Test cookie received'
|
|
|
|
);
|
|
|
|
expectReject($res);
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
|
|
|
|
# Try to validate notification
|
|
|
|
$str =
|
|
|
|
'reference1x1=testref&check1x1x1=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/notifback',
|
|
|
|
IO::String->new($str),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($str),
|
|
|
|
),
|
|
|
|
"Accept notification"
|
|
|
|
);
|
|
|
|
expectRedirection( $res, 'http://test1.example.com/' );
|
|
|
|
|
|
|
|
# Verify that notification was tagged as 'done'
|
|
|
|
my $sth =
|
|
|
|
$dbh->prepare('SELECT * FROM notifications WHERE done IS NOT NULL');
|
|
|
|
$sth->execute;
|
|
|
|
my $i = 0;
|
|
|
|
while ( $sth->fetchrow_hashref ) { $i++ }
|
|
|
|
ok( $i == 1, 'Notification was deleted' );
|
|
|
|
|
|
|
|
clean_sessions();
|
|
|
|
|
|
|
|
eval { unlink $file };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-08 21:55:21 +01:00
|
|
|
count($maintests);
|
2017-01-31 23:31:25 +01:00
|
|
|
done_testing( count() );
|
|
|
|
|