2017-02-19 18:04:49 +01:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
2019-12-19 20:00:55 +01:00
|
|
|
use JSON qw(from_json);
|
2017-02-19 18:04:49 +01:00
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
}
|
|
|
|
|
|
|
|
my $json = '{
|
2019-12-18 21:52:38 +01:00
|
|
|
"date": "2016-05-30 15:35:10",
|
2017-02-19 18:04:49 +01:00
|
|
|
"reference": "testref",
|
|
|
|
"uid": "dwho",
|
|
|
|
"title": "Test title",
|
|
|
|
"text": "This is a test text"
|
|
|
|
}';
|
|
|
|
|
2019-12-23 21:18:44 +01:00
|
|
|
my $bad_json = '{
|
|
|
|
"date": "2016-13-30 15:35:10",
|
|
|
|
"reference": "testref",
|
|
|
|
"uid": "dwho",
|
|
|
|
"title": "Test title",
|
|
|
|
"text": "This is a test text"
|
|
|
|
}';
|
|
|
|
|
|
|
|
my $bad_json2 = '{
|
|
|
|
"date": "2016-13_30 15:35:10",
|
|
|
|
"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",
|
2020-04-03 22:00:20 +02:00
|
|
|
"reference": "test_ref2",
|
2019-07-21 22:35:23 +02:00
|
|
|
"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"
|
|
|
|
}';
|
|
|
|
|
2019-11-15 21:40:05 +01:00
|
|
|
my $notifs = q%[{
|
|
|
|
"uid": "dwho",
|
2019-12-18 21:52:38 +01:00
|
|
|
"date": "2019-11-15 15:35:10",
|
2019-11-15 21:40:05 +01:00
|
|
|
"reference": "ABC1",
|
|
|
|
"title": "You have new authorizations",
|
|
|
|
"subtitle": "Application 1",
|
|
|
|
"text": "You have been granted to access to appli-1",
|
|
|
|
"check": "I agree"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uid": "rtyler",
|
|
|
|
"date": "2019-11-15",
|
|
|
|
"reference": "ABC2",
|
|
|
|
"title": "You have new authorizations",
|
|
|
|
"subtitle": "Application 1",
|
|
|
|
"text": "You have been granted to access to appli-1",
|
|
|
|
"check": ["I agree", "I am sure"]
|
2019-11-25 17:21:40 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"uid": "rtyler",
|
|
|
|
"date": "2019-11-15",
|
|
|
|
"reference": "ABC3",
|
|
|
|
"condition": "$env->{REMOTE_ADDR} =~ /127.1.1.1/",
|
|
|
|
"title": "You have new authorizations",
|
|
|
|
"subtitle": "Application 1",
|
|
|
|
"text": "You have been granted to access to appli-1",
|
|
|
|
"check": ["I agree", "I am sure"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uid": "rtyler",
|
|
|
|
"date": "2050-11-15",
|
|
|
|
"reference": "ABC4",
|
|
|
|
"title": "You have new authorizations",
|
|
|
|
"subtitle": "Application 1",
|
|
|
|
"text": "You have been granted to access to appli-1",
|
|
|
|
"check": ["I agree", "I am sure"]
|
|
|
|
}
|
|
|
|
]%;
|
2019-11-15 21:40:05 +01:00
|
|
|
|
2019-07-23 15:54:53 +02:00
|
|
|
my $content = '{"uid":"dwho"}';
|
2019-07-21 21:54:20 +02:00
|
|
|
|
2020-08-25 00:24:54 +02:00
|
|
|
my $client = LLNG::Manager::Test->new(
|
|
|
|
{
|
2017-02-19 18:04:49 +01:00
|
|
|
ini => {
|
2019-11-25 17:21:40 +01:00
|
|
|
logLevel => 'error',
|
|
|
|
useSafeJail => 1,
|
|
|
|
notification => 1,
|
|
|
|
notificationServer => 1, # POST method enabled if undefined
|
|
|
|
notificationDefaultCond => '$env->{REMOTE_ADDR} =~ /127.0.0.1/',
|
|
|
|
notificationServerGET => 1,
|
2019-11-15 21:40:05 +01:00
|
|
|
notificationServerDELETE => 1,
|
|
|
|
notificationServerSentAttributes =>
|
|
|
|
'uid reference date title text subtitle check',
|
|
|
|
notificationWildcard => 'everyone',
|
|
|
|
notificationStorage => 'File',
|
|
|
|
notificationStorageOptions => {
|
2019-08-29 10:04:06 +02:00
|
|
|
dirName => $main::tmpDir,
|
2017-02-19 18:04:49 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
my $res;
|
2019-12-23 21:18:44 +01:00
|
|
|
foreach ( $bad_json, $bad_json2 ) {
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/notifications', IO::String->new($_),
|
|
|
|
type => 'application/json',
|
|
|
|
length => length($_)
|
|
|
|
),
|
|
|
|
"POST notification $_"
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ /"error"\s*:\s*"Bad date/,
|
|
|
|
'Notification not inserted' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(2);
|
|
|
|
}
|
|
|
|
|
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] );
|
2019-11-15 21:40:05 +01:00
|
|
|
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' )
|
2019-07-26 17:48:56 +02:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(4);
|
|
|
|
|
2019-12-19 20:00:55 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/notifications/bad_uid', type => 'application/json',
|
|
|
|
),
|
|
|
|
'List notifications for bad uid'
|
|
|
|
);
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~ /"reference":"testrefall"/,
|
|
|
|
'Notification for all users found'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(2);
|
|
|
|
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
2019-12-20 21:34:52 +01:00
|
|
|
'/notifications/_allPending_', type => 'application/json',
|
2019-12-19 20:00:55 +01:00
|
|
|
),
|
2019-12-20 21:34:52 +01:00
|
|
|
'List all pending notifications'
|
2019-12-19 20:00:55 +01:00
|
|
|
);
|
|
|
|
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' );
|
2020-08-25 00:24:54 +02:00
|
|
|
ok( scalar @{ $json->{result} } == 3, 'Three notifications found' )
|
2019-12-19 20:00:55 +01:00
|
|
|
or print STDERR Dumper($json);
|
|
|
|
|
2019-12-23 21:18:44 +01:00
|
|
|
foreach ( @{ $json->{result} } ) {
|
2020-04-03 22:00:20 +02:00
|
|
|
ok( $_->{reference} =~ /^test-?ref/, "Reference \'$_->{reference}\' found" )
|
2019-12-19 20:00:55 +01:00
|
|
|
or print STDERR Dumper($json);
|
|
|
|
ok( $_->{uid} =~ /^(dwho|everyone)$/, "UID \'$_->{uid}\' found" )
|
|
|
|
or print STDERR Dumper($json);
|
|
|
|
}
|
|
|
|
count(9);
|
|
|
|
|
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] );
|
2020-04-03 22:00:20 +02:00
|
|
|
ok( $res->[2]->[0] =~ /"reference":"test-ref2"/, '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(
|
2020-04-03 22:00:20 +02:00
|
|
|
'/notifications/dwho/test-ref2',
|
2019-11-15 21:40:05 +01:00
|
|
|
type => 'application/json',
|
2019-07-25 12:00:51 +02:00
|
|
|
),
|
2020-04-03 22:00:20 +02:00
|
|
|
'List notification with reference "test-ref2"'
|
2019-07-25 12:00:51 +02:00
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ /"result"\s*:\s*/, 'Result found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2020-04-03 22:00:20 +02:00
|
|
|
ok( $res->[2]->[0] =~ /"reference"\s*:\s*"test-ref2"/,
|
2019-07-25 12:00:51 +02:00
|
|
|
'Notification reference found' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-11-15 21:40:05 +01:00
|
|
|
ok( $res->[2]->[0] =~ /"title"\s*:\s*"Test2 title"/,
|
|
|
|
'Notification title found' )
|
2019-07-25 12:00:51 +02:00
|
|
|
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] );
|
2019-11-15 21:40:05 +01:00
|
|
|
ok( $res->[2]->[0] =~ /"subtitle"\s*:\s*"Application 2"/,
|
|
|
|
'Notification subtitle found' )
|
2019-07-25 12:00:51 +02:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-11-15 21:40:05 +01:00
|
|
|
ok( $res->[2]->[0] =~ /"check":\["I agree","Yes, I\'m sure"\]/,
|
|
|
|
'Notification check boxes found' )
|
2019-07-25 12:00:51 +02:00
|
|
|
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);
|
|
|
|
|
2020-04-03 22:00:20 +02:00
|
|
|
foreach (qw(testrefall test-ref2)) {
|
2019-07-23 15:54:53 +02:00
|
|
|
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' );
|
|
|
|
|
2019-11-15 21:40:05 +01:00
|
|
|
# Insert combined notifications
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/notifications', IO::String->new($notifs),
|
|
|
|
type => 'application/json',
|
|
|
|
length => length($notifs)
|
|
|
|
),
|
|
|
|
"POST combined notifications $notifs"
|
|
|
|
);
|
2019-11-25 17:21:40 +01:00
|
|
|
ok( $res->[2]->[0] =~ /"result"\s*:\s*4/, 'Notifications have been inserted' )
|
2019-11-15 21:40:05 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(2);
|
|
|
|
|
2019-12-20 21:34:52 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
2019-12-23 21:18:44 +01:00
|
|
|
'/notifications/_allExisting_',
|
|
|
|
type => 'application/json',
|
2019-12-20 21:34:52 +01:00
|
|
|
),
|
|
|
|
'List all existing notifications'
|
|
|
|
);
|
|
|
|
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' );
|
2020-08-25 00:24:54 +02:00
|
|
|
ok( scalar @{ $json->{result} } == 5, 'Five notifications found' )
|
2019-12-20 21:34:52 +01:00
|
|
|
or print STDERR Dumper($json);
|
|
|
|
count(3);
|
|
|
|
|
2019-11-15 21:40:05 +01:00
|
|
|
# Try to authenticate with "dwho"
|
|
|
|
# -------------------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new(
|
|
|
|
'user=dwho&password=dwho'),
|
|
|
|
accept => 'text/html',
|
|
|
|
length => 23,
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
$id = expectCookie($res);
|
2019-11-25 17:21:40 +01:00
|
|
|
expectForm( $res, undef, '/notifback', 'reference1x1', 'reference1x2' );
|
|
|
|
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2020-08-25 00:24:54 +02:00
|
|
|
m%<input type="hidden" name="reference1x1" value="testref"/>%,
|
2019-11-25 17:21:40 +01:00
|
|
|
'Checkbox is displayed'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok(
|
2020-08-25 00:24:54 +02:00
|
|
|
$res->[2]->[0] =~
|
|
|
|
m%<input type="hidden" name="reference1x2" value="ABC1"/>%,
|
2019-11-25 17:21:40 +01:00
|
|
|
'Checkbox is displayed'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
2019-11-15 21:40:05 +01:00
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2020-11-05 10:14:42 +01:00
|
|
|
m%<input class="form-check-input" type="checkbox" name="check1x2x1" id="1x2x1" value="accepted"/>%,
|
2019-11-15 21:40:05 +01:00
|
|
|
'Checkbox is displayed'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
2020-11-05 10:14:42 +01:00
|
|
|
my @c = ( $res->[2]->[0] =~ m%<input class="form-check-input" type="checkbox"%gs );
|
2019-11-15 22:08:28 +01:00
|
|
|
|
2019-11-25 17:21:40 +01:00
|
|
|
## One entry found
|
2019-11-15 22:08:28 +01:00
|
|
|
ok( @c == 1, ' -> One checkbox found' )
|
|
|
|
or explain( $res->[2]->[0], "Number of checkbox(es) found = " . scalar @c );
|
2019-11-25 17:21:40 +01:00
|
|
|
count(6);
|
2019-11-15 21:40:05 +01:00
|
|
|
|
|
|
|
# Try to validate notification
|
2019-11-25 17:21:40 +01:00
|
|
|
my $str = 'reference1x2=ABC1&check1x2x1=accepted';
|
2019-11-15 21:40:05 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/notifback',
|
|
|
|
IO::String->new($str),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($str),
|
|
|
|
),
|
|
|
|
"Accept notification"
|
|
|
|
);
|
|
|
|
expectOK($res);
|
2019-12-20 21:34:52 +01:00
|
|
|
$id = expectCookie($res);
|
2019-11-15 21:40:05 +01:00
|
|
|
$client->logout($id);
|
|
|
|
|
|
|
|
# Try to authenticate with "rtyler"
|
|
|
|
# -------------------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new(
|
|
|
|
'user=rtyler&password=rtyler'),
|
|
|
|
accept => 'text/html',
|
|
|
|
length => 27,
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
$id = expectCookie($res);
|
|
|
|
expectForm( $res, undef, '/notifback', 'reference1x1' );
|
2019-11-25 17:21:40 +01:00
|
|
|
|
2019-11-15 21:40:05 +01:00
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2020-11-05 10:14:42 +01:00
|
|
|
m%<input class="form-check-input" type="checkbox" name="check1x1x1" id="1x1x1" value="accepted"/>%
|
2020-08-25 00:24:54 +02:00
|
|
|
and m%<label class="form-check-label" for="1x1x1">I agree</label>%,
|
2019-11-15 21:40:05 +01:00
|
|
|
'Checkbox is displayed'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2020-11-05 10:14:42 +01:00
|
|
|
m%<input class="form-check-input" type="checkbox" name="check1x1x2" id="1x1x2" value="accepted"/>%
|
2020-08-25 00:24:54 +02:00
|
|
|
and m%<label class="form-check-label" for="1x1x2">I am sure</label>%,
|
2019-11-15 21:40:05 +01:00
|
|
|
'Checkbox is displayed'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
2020-11-05 10:14:42 +01:00
|
|
|
@c = ( $res->[2]->[0] =~ m%<input class="form-check-input" type="checkbox"%gs );
|
2019-11-15 22:08:28 +01:00
|
|
|
|
2019-11-25 17:21:40 +01:00
|
|
|
## Two entries found
|
2019-11-15 22:08:28 +01:00
|
|
|
ok( @c == 2, ' -> Two checkboxes found' )
|
|
|
|
or explain( $res->[2]->[0], "Number of checkbox(es) found = " . scalar @c );
|
|
|
|
count(5);
|
2019-11-15 21:40:05 +01:00
|
|
|
|
|
|
|
# Try to validate notification
|
2019-11-25 17:21:40 +01:00
|
|
|
$str = 'reference1x1=ABC2&check1x1x1=accepted&check1x1x2=accepted';
|
2019-11-15 21:40:05 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/notifback',
|
|
|
|
IO::String->new($str),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($str),
|
|
|
|
),
|
|
|
|
"Accept notification"
|
|
|
|
);
|
|
|
|
expectOK($res);
|
2019-12-20 21:34:52 +01:00
|
|
|
$id = expectCookie($res);
|
2019-11-15 21:40:05 +01:00
|
|
|
$client->logout($id);
|
|
|
|
|
2019-12-20 21:34:52 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/notifications/_allPending_', type => 'application/json',
|
|
|
|
),
|
|
|
|
'List all pending notifications'
|
|
|
|
);
|
|
|
|
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' );
|
2020-08-25 00:24:54 +02:00
|
|
|
ok( scalar @{ $json->{result} } == 3, 'Three notifications found' )
|
2019-12-20 21:34:52 +01:00
|
|
|
or print STDERR Dumper($json);
|
|
|
|
count(3);
|
|
|
|
|
2017-02-19 18:04:49 +01:00
|
|
|
clean_sessions();
|
|
|
|
done_testing( count() );
|