2017-02-19 18:04:49 +01:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
}
|
|
|
|
|
|
|
|
eval { unlink 't/20160530_dwho_dGVzdHJlZg==.json' };
|
|
|
|
|
|
|
|
my $json = '{
|
|
|
|
"date": "2016-05-30",
|
|
|
|
"reference": "testref",
|
|
|
|
"uid": "dwho",
|
|
|
|
"title": "Test title",
|
|
|
|
"text": "This is a test text"
|
|
|
|
}';
|
|
|
|
|
2019-07-21 22:35:23 +02:00
|
|
|
my $jsonbis = '{
|
2019-07-19 10:06:44 +02:00
|
|
|
"date": "2016-05-31",
|
|
|
|
"reference": "testref",
|
|
|
|
"uid": "dwho",
|
|
|
|
"title": "Test2 title",
|
|
|
|
"text": "This is a second test text"
|
|
|
|
}';
|
|
|
|
|
2019-07-25 12:00:51 +02:00
|
|
|
my $json2 = q%{
|
2019-07-21 22:35:23 +02:00
|
|
|
"date": "2016-05-30",
|
|
|
|
"reference": "testref2",
|
|
|
|
"uid": "dwho",
|
|
|
|
"title": "Test2 title",
|
2019-07-25 12:00:51 +02:00
|
|
|
"text": "This is a second test text",
|
|
|
|
"subtitle": "Application 2",
|
|
|
|
"check": ["I agree","Yes, I'm sure"]
|
|
|
|
}%;
|
2019-07-21 22:35:23 +02:00
|
|
|
|
2019-07-23 15:54:53 +02:00
|
|
|
my $jsonall = '{
|
|
|
|
"date": "2016-05-30",
|
|
|
|
"reference": "testrefall",
|
|
|
|
"uid": "everyone",
|
|
|
|
"title": "Testall title",
|
|
|
|
"text": "This is a test text for all users"
|
|
|
|
}';
|
|
|
|
|
|
|
|
my $content = '{"uid":"dwho"}';
|
2019-07-21 21:54:20 +02:00
|
|
|
|
2019-02-07 09:27:56 +01:00
|
|
|
my $client = LLNG::Manager::Test->new( {
|
2017-02-19 18:04:49 +01:00
|
|
|
ini => {
|
2019-07-25 12:00:51 +02:00
|
|
|
logLevel => 'error',
|
|
|
|
useSafeJail => 1,
|
|
|
|
notification => 1,
|
|
|
|
notificationServer => 1, # POST method enabled if undefined
|
|
|
|
notificationServerGET => 1,
|
|
|
|
notificationServerDELETE => 1,
|
2019-07-26 17:48:56 +02:00
|
|
|
notificationServerSentAttributes => 'uid reference date title text subtitle check',
|
2019-07-25 12:00:51 +02:00
|
|
|
notificationWildcard => 'everyone',
|
|
|
|
notificationStorage => 'File',
|
|
|
|
notificationStorageOptions => {
|
2017-02-19 18:04:49 +01:00
|
|
|
dirName => 't'
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
my $res;
|
2019-07-23 15:54:53 +02:00
|
|
|
foreach ( $json, $json2, $jsonall ) {
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/notifications', IO::String->new($_),
|
|
|
|
type => 'application/json',
|
|
|
|
length => length($_)
|
|
|
|
),
|
|
|
|
"POST notification $_"
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ /"result"\s*:\s*1/, 'Notification has been inserted' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(2);
|
|
|
|
}
|
2019-07-21 22:35:23 +02:00
|
|
|
|
2019-07-26 17:48:56 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/notifications', type => 'application/json',
|
|
|
|
),
|
|
|
|
'List notifications for "allusers"'
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ /"result"\s*:\s*/, 'Result found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ /"reference":"testrefall"/, 'Notification for all users found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ /"uid":"everyone"/, 'Wildcard found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(4);
|
|
|
|
|
2019-07-21 22:35:23 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
2019-07-23 15:54:53 +02:00
|
|
|
'/notifications/dwho', type => 'application/json',
|
2019-07-21 22:35:23 +02:00
|
|
|
),
|
2019-07-22 15:40:16 +02:00
|
|
|
'List notifications for "dwho"'
|
2019-07-21 22:35:23 +02:00
|
|
|
);
|
2019-07-21 22:47:48 +02:00
|
|
|
ok( $res->[2]->[0] =~ /"result"\s*:\s*/, 'Result found' )
|
2019-07-21 22:35:23 +02:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-07-21 23:21:20 +02:00
|
|
|
ok( $res->[2]->[0] =~ /"reference":"testref"/, 'First notification found' )
|
2019-07-21 22:47:48 +02:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-07-21 23:21:20 +02:00
|
|
|
ok( $res->[2]->[0] =~ /"reference":"testref2"/, 'Second notification found' )
|
2019-07-21 22:47:48 +02:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-07-25 12:00:51 +02:00
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~ /"reference":"testrefall"/,
|
|
|
|
'Third notification found (all users)'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
2019-07-23 15:54:53 +02:00
|
|
|
count(5);
|
2017-02-19 18:04:49 +01:00
|
|
|
|
2019-07-22 15:40:16 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
2019-07-23 15:54:53 +02:00
|
|
|
'/notifications/dwho/testref', type => 'application/json',
|
2019-07-22 15:40:16 +02:00
|
|
|
),
|
|
|
|
'List notification with reference "testref"'
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ /"result"\s*:\s*/, 'Result found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-07-23 15:54:53 +02:00
|
|
|
ok( $res->[2]->[0] =~ /"reference"\s*:\s*"testref"/,
|
|
|
|
'Notification reference found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ /"title"\s*:\s*"Test title"/, 'Notification title found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ /"text"\s*:\s*"This is a test text"/,
|
|
|
|
'Notification text found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ /"date"\s*:\s*"2016-05-30"/, 'Notification date found' )
|
2019-07-22 15:40:16 +02:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-07-23 15:54:53 +02:00
|
|
|
ok( $res->[2]->[0] =~ /"uid"\s*:\s*"dwho"/, 'Notification uid found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(7);
|
2019-07-22 15:40:16 +02:00
|
|
|
|
2019-07-25 12:00:51 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/notifications/dwho/testref2', type => 'application/json',
|
|
|
|
),
|
|
|
|
'List notification with reference "testref2"'
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ /"result"\s*:\s*/, 'Result found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ /"reference"\s*:\s*"testref2"/,
|
|
|
|
'Notification reference found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ /"title"\s*:\s*"Test2 title"/, 'Notification title found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ /"text"\s*:\s*"This is a second test text"/,
|
|
|
|
'Notification text found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ /"date"\s*:\s*"2016-05-30"/, 'Notification date found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ /"uid"\s*:\s*"dwho"/, 'Notification uid found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ /"subtitle"\s*:\s*"Application 2"/, 'Notification subtitle found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ /"check":\["I agree","Yes, I\'m sure"\]/, 'Notification check boxes found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(9);
|
|
|
|
|
2019-07-21 21:54:20 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_put(
|
2019-07-23 15:54:53 +02:00
|
|
|
'/notifications', IO::String->new($content),
|
2019-07-21 21:54:20 +02:00
|
|
|
type => 'application/json',
|
2019-07-23 15:54:53 +02:00
|
|
|
length => length($content)
|
2019-07-21 21:54:20 +02:00
|
|
|
),
|
|
|
|
'Try to delete notification with bad method'
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ /"error"\s*:\s*"Bad request"/, 'Bad method is refused' );
|
|
|
|
count(2);
|
|
|
|
|
2019-07-23 15:54:53 +02:00
|
|
|
foreach (qw(testrefall testref2)) {
|
|
|
|
my $user = $_ eq 'testrefall' ? 'everyone' : 'dwho';
|
|
|
|
ok(
|
|
|
|
$res = $client->_delete(
|
|
|
|
"/notifications/$user/$_", type => 'application/json',
|
|
|
|
),
|
|
|
|
"Delete notification $_"
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ /"result"\s*:\s*1/, 'Notification has been deleted' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(2);
|
|
|
|
}
|
2019-07-21 21:54:20 +02:00
|
|
|
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2019-07-21 22:35:23 +02:00
|
|
|
'/notifications', IO::String->new($jsonbis),
|
2019-07-19 10:06:44 +02:00
|
|
|
type => 'application/json',
|
2019-07-21 22:35:23 +02:00
|
|
|
length => length($jsonbis)
|
2019-07-19 10:06:44 +02:00
|
|
|
),
|
|
|
|
'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);
|
|
|
|
|
2019-07-17 11:58:22 +02:00
|
|
|
# Try to authenticate
|
2017-02-19 18:04:49 +01:00
|
|
|
# -------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new(
|
2018-09-02 17:31:58 +02:00
|
|
|
'user=dwho&password=dwho&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='),
|
2017-02-19 18:04:49 +01:00
|
|
|
accept => 'text/html',
|
|
|
|
length => 64,
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
expectOK($res);
|
|
|
|
my $id = expectCookie($res);
|
|
|
|
expectForm( $res, undef, '/notifback', 'reference1x1', 'url' );
|
|
|
|
|
|
|
|
eval { unlink 't/20160530_dwho_dGVzdHJlZg==.json' };
|
|
|
|
|
|
|
|
clean_sessions();
|
|
|
|
done_testing( count() );
|