2018-09-05 22:24:23 +02:00
|
|
|
use lib 'inc';
|
2018-03-19 17:51:52 +01:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
use LWP::UserAgent;
|
2018-09-05 22:24:23 +02:00
|
|
|
use LWP::Protocol::PSGI;
|
2018-03-19 17:51:52 +01:00
|
|
|
use Plack::Request;
|
|
|
|
|
|
|
|
require 't/test-lib.pm';
|
2018-09-09 23:18:49 +02:00
|
|
|
my $maintests = 6;
|
2018-03-19 17:51:52 +01:00
|
|
|
|
|
|
|
LWP::Protocol::PSGI->register(
|
|
|
|
sub {
|
|
|
|
my $req = Plack::Request->new(@_);
|
|
|
|
if ( $req->path_info eq '/init' ) {
|
|
|
|
ok( $req->content eq '{"name":"dwho"}', ' Init req gives dwho' )
|
2018-11-26 14:40:21 +01:00
|
|
|
or explain( $req->content, '{"name":"dwho"}' );
|
2018-03-19 17:51:52 +01:00
|
|
|
}
|
|
|
|
elsif ( $req->path_info eq '/vrfy' ) {
|
|
|
|
ok( $req->content eq '{"code":"1234"}', ' Code is 1234' )
|
2018-11-26 14:40:21 +01:00
|
|
|
or explain( $req->content, '{"code":"1234"}' );
|
2018-03-19 17:51:52 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fail( ' Bad REST call ' . $req->path_info );
|
|
|
|
}
|
|
|
|
return [
|
|
|
|
200,
|
|
|
|
[ 'Content-Type' => 'application/json', 'Content-Length' => 12 ],
|
|
|
|
['{"result":1}']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-02-07 09:27:56 +01:00
|
|
|
my $client = LLNG::Manager::Test->new( {
|
2018-11-26 14:40:21 +01:00
|
|
|
ini => {
|
2018-10-12 10:04:03 +02:00
|
|
|
logLevel => 'error',
|
|
|
|
rest2fActivation => 1,
|
|
|
|
rest2fInitUrl => 'http://auth.example.com/init',
|
|
|
|
rest2fInitArgs => { name => 'uid' },
|
|
|
|
rest2fVerifyUrl => 'http://auth.example.com/vrfy',
|
|
|
|
rest2fVerifyArgs => { code => 'code' },
|
|
|
|
loginHistoryEnabled => 1,
|
2018-09-09 23:18:49 +02:00
|
|
|
authentication => 'Demo',
|
|
|
|
userDB => 'Same',
|
2018-10-21 22:12:56 +02:00
|
|
|
portalMainLogo => 'common/logos/logo_llng_old.png',
|
2018-03-19 17:51:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
my $res;
|
|
|
|
|
|
|
|
# Try to authenticate
|
|
|
|
# -------------------
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-03-19 17:51:52 +01:00
|
|
|
'/',
|
2018-09-09 23:18:49 +02:00
|
|
|
IO::String->new('user=dwho&password=dwho&checkLogins=1'),
|
|
|
|
length => 37,
|
2018-03-19 17:51:52 +01:00
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
2018-10-21 22:12:56 +02:00
|
|
|
ok( $res->[2]->[0] =~ qr%<img src="/static/common/logos/logo_llng_old.png"%,
|
2018-10-13 22:26:09 +02:00
|
|
|
'Found custom Main Logo' )
|
2018-11-26 14:40:21 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2018-10-13 22:26:09 +02:00
|
|
|
count(1);
|
|
|
|
|
2018-11-26 14:40:21 +01:00
|
|
|
my ( $host, $url, $query ) =
|
|
|
|
expectForm( $res, undef, '/rest2fcheck', 'token', 'code', 'checkLogins' );
|
2018-03-19 17:51:52 +01:00
|
|
|
$query =~ s/code=/code=1234/;
|
|
|
|
|
2018-11-26 14:40:21 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-03-19 17:51:52 +01:00
|
|
|
'/rest2fcheck',
|
|
|
|
IO::String->new($query),
|
|
|
|
length => length($query),
|
2018-09-09 23:18:49 +02:00
|
|
|
accept => 'text/html',
|
2018-03-19 17:51:52 +01:00
|
|
|
),
|
|
|
|
'Post code'
|
|
|
|
);
|
|
|
|
my $id = expectCookie($res);
|
2018-09-09 23:18:49 +02:00
|
|
|
|
|
|
|
ok( $res->[2]->[0] =~ /trspan="lastLogins"/, 'History found' )
|
2018-11-26 14:40:21 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2018-09-09 23:18:49 +02:00
|
|
|
my @c = ( $res->[2]->[0] =~ /<td>127.0.0.1/gs );
|
|
|
|
ok( @c == 1, 'One entry found' );
|
|
|
|
|
2018-03-19 17:51:52 +01:00
|
|
|
$client->logout($id);
|
|
|
|
|
|
|
|
#print STDERR Dumper($res);
|
|
|
|
|
|
|
|
count($maintests);
|
|
|
|
|
|
|
|
clean_sessions();
|
|
|
|
|
|
|
|
done_testing( count() );
|
|
|
|
|