First JSON notif test (#868)
This commit is contained in:
parent
2d95ac991a
commit
be55c43316
|
@ -362,6 +362,7 @@ t/34-Auth-Proxy-and-REST-Server.t
|
||||||
t/34-Auth-Proxy-and-SOAP-Server.t
|
t/34-Auth-Proxy-and-SOAP-Server.t
|
||||||
t/35-REST-sessions-with-REST-server.t
|
t/35-REST-sessions-with-REST-server.t
|
||||||
t/35-SOAP-sessions-with-SOAP-server.t
|
t/35-SOAP-sessions-with-SOAP-server.t
|
||||||
|
t/40-Notifications-JSON-DBI.t
|
||||||
t/40-Notifications-XML-DBI.t
|
t/40-Notifications-XML-DBI.t
|
||||||
t/40-Notifications-XML-File.t
|
t/40-Notifications-XML-File.t
|
||||||
t/41-Captcha.t
|
t/41-Captcha.t
|
||||||
|
|
|
@ -12,6 +12,11 @@ no warnings 'redefine';
|
||||||
# addUnauthRoute() methods in addition of Lemonldap::NG::Common::Module.
|
# addUnauthRoute() methods in addition of Lemonldap::NG::Common::Module.
|
||||||
extends 'Lemonldap::NG::Portal::Main::Plugin';
|
extends 'Lemonldap::NG::Portal::Main::Plugin';
|
||||||
|
|
||||||
|
# PROPERTIES
|
||||||
|
|
||||||
|
# Underlying notifications storage object (File, DBI, LDAP,...)
|
||||||
|
has notifObject => ( is => 'rw' );
|
||||||
|
|
||||||
# INITIALIZATION
|
# INITIALIZATION
|
||||||
|
|
||||||
sub init {
|
sub init {
|
||||||
|
@ -124,8 +129,8 @@ sub getNotifBack {
|
||||||
if ( my $refId = $refs->{$reference} ) {
|
if ( my $refId = $refs->{$reference} ) {
|
||||||
|
|
||||||
# Verity that checkboxes have been checked
|
# Verity that checkboxes have been checked
|
||||||
if ( $json->{check} ) {
|
if ( $notif->{check} ) {
|
||||||
if ( my $toCheckCount = @{ $json->{check} } ) {
|
if ( my $toCheckCount = @{ $notif->{check} } ) {
|
||||||
unless ($checks->{$refId}
|
unless ($checks->{$refId}
|
||||||
and $toCheckCount == @{ $checks->{$refId} } )
|
and $toCheckCount == @{ $checks->{$refId} } )
|
||||||
{
|
{
|
||||||
|
|
125
lemonldap-ng-portal/t/40-Notifications-JSON-DBI.t
Normal file
125
lemonldap-ng-portal/t/40-Notifications-JSON-DBI.t
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
use Test::More;
|
||||||
|
use strict;
|
||||||
|
use IO::String;
|
||||||
|
|
||||||
|
my $res;
|
||||||
|
my $file = 't/notifications.db';
|
||||||
|
my $mainTests = 5;
|
||||||
|
eval { unlink $file };
|
||||||
|
require 't/test-lib.pm';
|
||||||
|
|
||||||
|
SKIP: {
|
||||||
|
eval { require DBI; require DBD::SQLite; };
|
||||||
|
if ($@) {
|
||||||
|
skip 'DBD::SQLite not found', $mainTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)}
|
||||||
|
)->execute(
|
||||||
|
'[
|
||||||
|
{
|
||||||
|
"uid": "dwho",
|
||||||
|
"date": "2016-05-30",
|
||||||
|
"reference": "testref",
|
||||||
|
"title": "Test title",
|
||||||
|
"subtitle": "Test subtitle",
|
||||||
|
"text": "This is a test text",
|
||||||
|
"check": ["Accept test"]
|
||||||
|
}
|
||||||
|
]'
|
||||||
|
);
|
||||||
|
|
||||||
|
my $client = LLNG::Manager::Test->new(
|
||||||
|
{
|
||||||
|
ini => {
|
||||||
|
logLevel => 'error',
|
||||||
|
useSafeJail => 1,
|
||||||
|
notifications => 1,
|
||||||
|
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);
|
||||||
|
|
||||||
|
# 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 };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
count($mainTests);
|
||||||
|
done_testing( count() );
|
||||||
|
|
Loading…
Reference in New Issue
Block a user