Merge branch 'v2.0'

This commit is contained in:
Christophe Maudoux 2019-07-19 10:13:33 +02:00
commit b81ccf7517
7 changed files with 173 additions and 13 deletions

View File

@ -38,6 +38,12 @@ sub newNotification {
$self->logger->error("Attribute $_ is missing");
return 0;
}
if ( $self->get( $notif->{uid}, $notif->{reference} ) ) {
my $err = "A notification already exists with reference "
. $notif->{reference};
$self->logger->error("$err");
return 0;
}
push @data, $tmp;
}

View File

@ -30,6 +30,21 @@ q{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00',?,nul
"text": "This is a test text",
"check": ["Accept test"]
}
]'
);
$dbh->prepare(
q{INSERT INTO notifications VALUES ('dwho','testref2','2016-05-30 00:00:00',?,null,null)}
)->execute(
'[
{
"uid": "dwho",
"date": "2016-05-30",
"reference": "testref2",
"title": "Test2 title",
"subtitle": "Test2 subtitle",
"text": "This is a second test text",
"check": ["Accept test"]
}
]'
);
@ -90,9 +105,9 @@ q{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00',?,nul
);
expectOK($res);
# Try to validate notification
# Try to validate notifications
$str =
'reference1x1=testref&check1x1x1=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
'reference1x1=testref&check1x1x1=accepted&reference1x2=testref2&check1x2x1=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
ok(
$res = $client->_post(
'/notifback',
@ -101,7 +116,7 @@ q{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00',?,nul
accept => 'text/html',
length => length($str),
),
"Accept notification"
"Accept notifications"
);
expectRedirection( $res, 'http://test1.example.com/' );
@ -111,7 +126,7 @@ q{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00',?,nul
$sth->execute;
my $i = 0;
while ( $sth->fetchrow_hashref ) { $i++ }
ok( $i == 1, 'Notification was deleted' );
ok( $i == 2, 'Notification was deleted' );
clean_sessions();

View File

@ -34,7 +34,53 @@ my $client = LLNG::Manager::Test->new( {
}
);
# Try yo authenticate
# 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);
ok( not( %$c{'lemonldap'} ), 'Cookie expired' ) or print STDERR Dumper($c);
count(2);
expectRedirection( $res, 'http://auth.example.com/' );
# Try to authenticate
# -------------------
ok(
$res = $client->_post(

View File

@ -14,6 +14,14 @@ my $json = '{
"text": "This is a test text"
}';
my $json2 = '{
"date": "2016-05-31",
"reference": "testref",
"uid": "dwho",
"title": "Test2 title",
"text": "This is a second test text"
}';
my $client = LLNG::Manager::Test->new( {
ini => {
logLevel => 'error',
@ -39,6 +47,21 @@ ok(
);
count(1);
ok(
$res = $client->_post(
'/notifications', IO::String->new($json2),
type => 'application/json',
length => length($json2)
),
'Try to create the same notification twice'
);
ok(
$res->[2]->[0] =~
/"error"\s*:\s*"A notification already exists with reference testref"/,
'Append the same notification is refused'
);
count(2);
# Try to authenticate
# -------------------
ok(

View File

@ -29,6 +29,15 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
<subtitle>Test subtitle</subtitle>
<text>This is a test text</text>
<check>Accept test</check>
</notification></root>',null,null)}
);
$dbh->do(
qq{INSERT INTO notifications VALUES ('dwho','testref2','2016-05-30 00:00:00','<?xml version="1.0" encoding="UTF-8"?>
<root><notification uid="dwho" date="2016-05-30" reference="testref2">
<title>Test2 title</title>
<subtitle>Test2 subtitle</subtitle>
<text>This is a second test text</text>
<check>Accept test</check>
</notification></root>',null,null)}
);
@ -89,9 +98,9 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
);
expectOK($res);
# Try to validate notification
# Try to validate notifications
$str =
'reference1x1=testref&check1x1x1=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
'reference1x1=testref&check1x1x1=accepted&reference1x2=testref2&check1x2x1=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
ok(
$res = $client->_post(
'/notifback',
@ -100,7 +109,7 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
accept => 'text/html',
length => length($str),
),
"Accept notification"
"Accept notifications"
);
expectRedirection( $res, 'http://test1.example.com/' );
@ -110,7 +119,7 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
$sth->execute;
my $i = 0;
while ( $sth->fetchrow_hashref ) { $i++ }
ok( $i == 1, 'Notification was deleted' );
ok( $i == 2, 'Notification was deleted' );
clean_sessions();
}

View File

@ -38,7 +38,54 @@ SKIP: {
}
);
# Try yo authenticate
# 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);
ok( not( %$c{'lemonldap'} ), 'Cookie expired' ) or print STDERR Dumper($c);
count(2);
expectRedirection( $res, 'http://auth.example.com/' );
# Try to authenticate
# -------------------
ok(
$res = $client->_post(

View File

@ -9,7 +9,7 @@ BEGIN {
require 't/test-lib.pm';
}
my $maintests = 3;
my $maintests = 4;
my $debug = 'error';
my $client;
@ -50,6 +50,13 @@ my $xml = '<?xml version="1.0" encoding="UTF-8"?>
<text>This is a test text</text>
</notification></root>';
my $xml2 = '<?xml version="1.0" encoding="UTF-8"?>
<root><notification uid="dwho" date="2016-05-31" reference="testref">
<title>Test title</title>
<subtitle>Test subtitle</subtitle>
<text>This is a test text</text>
</notification></root>';
SKIP: {
eval "use SOAP::Lite; use XML::LibXML; use XML::LibXSLT;";
if ($@) {
@ -77,8 +84,15 @@ SKIP: {
'SOAP client'
);
$soap->default_ns('urn:Lemonldap/NG/Common/PSGI/SOAPService');
ok( $soap->call( 'newNotification', $xml )->result() == 1,
' SOAP call returns 1' );
ok(
$soap->call( 'newNotification', $xml )->result() == 1,
' Append a notification -> SOAP call returns 1'
);
$soap->default_ns('urn:Lemonldap/NG/Common/PSGI/SOAPService');
ok(
$soap->call( 'newNotification', $xml2 )->result() == 0,
' Append the same notification twice -> SOAP call returns 0'
);
# Try to authenticate
# -------------------