2018-09-05 22:24:23 +02:00
|
|
|
use lib 'inc';
|
2017-02-19 18:04:49 +01:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
2018-04-10 06:54:08 +02:00
|
|
|
use LWP::UserAgent;
|
2018-09-05 22:24:23 +02:00
|
|
|
use LWP::Protocol::PSGI;
|
2017-02-19 18:04:49 +01:00
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
}
|
|
|
|
|
2020-04-03 22:00:20 +02:00
|
|
|
my $maintests = 13;
|
2017-02-19 18:04:49 +01:00
|
|
|
my $client;
|
|
|
|
|
2018-04-10 06:54:08 +02:00
|
|
|
# Redefine LWP methods for tests
|
|
|
|
LWP::Protocol::PSGI->register(
|
|
|
|
sub {
|
|
|
|
my $req = Plack::Request->new(@_);
|
|
|
|
ok( $req->uri =~ m#http://auth.example.com(.*)#, ' @ SOAP REQUEST @' );
|
|
|
|
my $url = $1;
|
|
|
|
my $res;
|
|
|
|
my $s = $req->content;
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
$url,
|
|
|
|
IO::String->new($s),
|
|
|
|
length => length($s),
|
|
|
|
type => $req->header('Content-Type'),
|
|
|
|
custom => {
|
|
|
|
HTTP_SOAPACTION => $req->header('Soapaction'),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
' Execute request'
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
ok( getHeader( $res, 'Content-Type' ) =~ m#^(?:text|application)/xml#,
|
|
|
|
' Content is XML' )
|
|
|
|
or explain( $res->[1], 'Content-Type => application/xml' );
|
|
|
|
pass(' @ END OF SOAP REQUEST @');
|
|
|
|
count(4);
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-02-19 18:04:49 +01:00
|
|
|
my $xml = '<?xml version="1.0" encoding="UTF-8"?>
|
2019-12-18 21:52:38 +01:00
|
|
|
<root><notification uid="dwho" date="2016-05-30 15:35:10" reference="testref">
|
2017-02-19 18:04:49 +01:00
|
|
|
<title>Test title</title>
|
|
|
|
<subtitle>Test subtitle</subtitle>
|
|
|
|
<text>This is a test text</text>
|
|
|
|
</notification></root>';
|
|
|
|
|
2019-11-25 17:21:40 +01:00
|
|
|
my $xmlbis = '<?xml version="1.0" encoding="UTF-8"?>
|
2019-07-19 10:06:44 +02:00
|
|
|
<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>';
|
|
|
|
|
2019-11-25 17:21:40 +01:00
|
|
|
my $combined = '<?xml version="1.0" encoding="UTF-8"?>
|
2019-12-18 21:52:38 +01:00
|
|
|
<root><notification uid="dwho" date="2016-05-31 15:35:10" reference="ABC1">
|
2019-11-25 17:21:40 +01:00
|
|
|
<title>Test title</title>
|
|
|
|
<subtitle>Test subtitle</subtitle>
|
|
|
|
<text>This is a test text</text>
|
|
|
|
<check>I agree</check>
|
|
|
|
</notification>
|
2020-04-03 22:00:20 +02:00
|
|
|
<notification uid="rtyler" date="2016-05-31" reference="AB_C_2">
|
2019-11-25 17:21:40 +01:00
|
|
|
<title>Test title</title>
|
|
|
|
<subtitle>Test subtitle</subtitle>
|
|
|
|
<text>This is a test text</text>
|
|
|
|
<check>I agree</check>
|
|
|
|
<check>I am sure</check>
|
|
|
|
</notification>
|
|
|
|
<notification uid="rtyler" date="2016-05-31" reference="ABC3" condition="\$env->{REMOTE_ADDR} =~ /127\.1\.1\.1/">
|
|
|
|
<title>Test title</title>
|
|
|
|
<subtitle>Test subtitle</subtitle>
|
|
|
|
<text>This is a test text</text>
|
|
|
|
<check>I agree</check>
|
|
|
|
<check>I am sure</check>
|
|
|
|
</notification>
|
|
|
|
<notification uid="rtyler" date="2050-05-31" reference="ABC4">
|
|
|
|
<title>Test title</title>
|
|
|
|
<subtitle>Test subtitle</subtitle>
|
|
|
|
<text>This is a test text</text>
|
|
|
|
<check>I agree</check>
|
|
|
|
<check>I am sure</check>
|
|
|
|
</notification>
|
|
|
|
</root>';
|
|
|
|
|
2017-02-19 18:04:49 +01:00
|
|
|
SKIP: {
|
2017-03-07 07:30:57 +01:00
|
|
|
eval "use SOAP::Lite; use XML::LibXML; use XML::LibXSLT;";
|
2017-02-19 18:04:49 +01:00
|
|
|
if ($@) {
|
2017-03-07 07:30:57 +01:00
|
|
|
skip 'SOAP::Lite or XML::Lib* not found', $maintests;
|
2017-02-19 18:04:49 +01:00
|
|
|
}
|
|
|
|
|
2019-02-07 09:27:56 +01:00
|
|
|
$client = LLNG::Manager::Test->new( {
|
2017-02-19 18:04:49 +01:00
|
|
|
ini => {
|
2020-02-20 23:34:02 +01:00
|
|
|
logLevel => 'error',
|
|
|
|
useSafeJail => 1,
|
|
|
|
notification => 1,
|
|
|
|
notificationServer => 1,
|
|
|
|
|
|
|
|
#notificationDefaultCond => '$env->{REMOTE_ADDR} =~ /127.0.0.1/',
|
2017-02-19 18:04:49 +01:00
|
|
|
notificationStorage => 'File',
|
|
|
|
notificationStorageOptions => {
|
2019-08-29 10:04:06 +02:00
|
|
|
dirName => $main::tmpDir
|
2017-02-19 18:04:49 +01:00
|
|
|
},
|
|
|
|
oldNotifFormat => 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
my $soap;
|
|
|
|
ok(
|
|
|
|
$soap =
|
|
|
|
SOAP::Lite->new( proxy => 'http://auth.example.com/notifications' ),
|
|
|
|
'SOAP client'
|
|
|
|
);
|
|
|
|
$soap->default_ns('urn:Lemonldap/NG/Common/PSGI/SOAPService');
|
2019-07-19 10:06:44 +02:00
|
|
|
ok(
|
|
|
|
$soap->call( 'newNotification', $xml )->result() == 1,
|
|
|
|
' Append a notification -> SOAP call returns 1'
|
|
|
|
);
|
|
|
|
$soap->default_ns('urn:Lemonldap/NG/Common/PSGI/SOAPService');
|
|
|
|
ok(
|
2019-11-25 17:21:40 +01:00
|
|
|
$soap->call( 'newNotification', $xmlbis )->result() == 0,
|
2019-07-19 10:06:44 +02:00
|
|
|
' Append the same notification twice -> SOAP call returns 0'
|
|
|
|
);
|
2017-02-19 18:04:49 +01:00
|
|
|
|
2019-07-17 11:58:22 +02:00
|
|
|
# Try to authenticate
|
2017-02-19 18:04:49 +01:00
|
|
|
# -------------------
|
|
|
|
my $res;
|
|
|
|
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);
|
|
|
|
expectForm( $res, undef, '/notifback', 'reference1x1', 'url' );
|
|
|
|
|
2019-11-25 17:21:40 +01:00
|
|
|
# Insert combined notifications
|
|
|
|
$soap->default_ns('urn:Lemonldap/NG/Common/PSGI/SOAPService');
|
|
|
|
ok(
|
|
|
|
$soap->call( 'newNotification', $combined )->result() == 4,
|
|
|
|
' Append a notification -> SOAP call returns 4'
|
|
|
|
);
|
|
|
|
|
|
|
|
# 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);
|
|
|
|
expectForm( $res, undef, '/notifback', 'reference1x1', 'reference2x1' );
|
|
|
|
my @c = ( $res->[2]->[0] =~ m%<input type="checkbox"%gs );
|
|
|
|
|
|
|
|
## One entry found
|
|
|
|
ok( @c == 1, ' -> One checkbox found' )
|
|
|
|
or
|
|
|
|
explain( $res->[2]->[0], "Number of checkbox(es) found = " . scalar @c );
|
|
|
|
|
|
|
|
# Try to validate notification
|
|
|
|
my $str = 'reference1x1=ABC1&check1x1x1=accepted';
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/notifback',
|
|
|
|
IO::String->new($str),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($str),
|
|
|
|
),
|
|
|
|
"Accept notification"
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
$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' );
|
2020-04-03 22:00:20 +02:00
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
|
|
|
m%<input type="hidden" name="reference1x1" value="AB-C-2">%,
|
|
|
|
'Reference found'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
2019-11-25 17:21:40 +01:00
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
|
|
|
m%<input type="checkbox" name="check1x1x1" id="check1x1x1" value="accepted">I agree</label>%,
|
|
|
|
'Checkbox is displayed'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
|
|
|
m%<input type="checkbox" name="check1x1x2" id="check1x1x2" value="accepted">I am sure</label>%,
|
|
|
|
'Checkbox is displayed'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
@c = ( $res->[2]->[0] =~ m%<input type="checkbox"%gs );
|
|
|
|
|
|
|
|
## Two entries found
|
|
|
|
ok( @c == 2, ' -> Two checkboxes found' )
|
|
|
|
or
|
|
|
|
explain( $res->[2]->[0], "Number of checkbox(es) found = " . scalar @c );
|
|
|
|
|
2017-02-19 18:04:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
count($maintests);
|
|
|
|
clean_sessions();
|
|
|
|
done_testing( count() );
|