lemonldap-ng/lemonldap-ng-portal/t/65-CheckState.t

108 lines
2.5 KiB
Perl
Raw Normal View History

2020-12-09 18:01:44 +01:00
use Test::More;
2021-11-23 12:02:17 +01:00
use Lemonldap::NG::Portal;
2020-12-09 18:01:44 +01:00
use strict;
require 't/test-lib.pm';
my $res;
my $client = LLNG::Manager::Test->new( {
ini => {
logLevel => 'error',
2021-09-10 12:22:30 +02:00
requireToken => 1,
2020-12-09 18:01:44 +01:00
checkStateSecret => 'x',
checkState => 1,
2021-09-10 12:22:30 +02:00
authentication => 'Combination',
2020-12-09 18:01:44 +01:00
userDB => 'Same',
2021-09-10 12:22:30 +02:00
combination => '[K,Dm] or [Dm]',
combModules => {
K => {
for => 1,
type => 'Kerberos',
},
Dm => {
for => 0,
type => 'Demo',
},
},
krbKeytab => '/etc/keytab',
krbByJs => 1,
2020-12-09 18:01:44 +01:00
}
}
);
ok( $res = $client->_get( '/checkstate', accept => 'application/json' ),
'Test no secret' );
expectReject( $res, 500, "Bad secret" );
ok(
$res = $client->_get(
'/checkstate',
accept => 'application/json',
query => 'secret=xx'
),
'Test bad secret, no user auth'
);
expectReject( $res, 500, "Bad secret" );
ok(
$res = $client->_get(
'/checkstate',
accept => 'application/json',
query => 'secret=x'
),
'Test correct secret, no user auth'
);
my $j = expectJSON($res);
is( $j->{result}, 1, "response has a result key with value 1" );
2021-11-23 12:02:17 +01:00
is(
$j->{version},
$Lemonldap::NG::Portal::VERSION,
"response version is correct"
);
2020-12-09 18:01:44 +01:00
ok(
$res = $client->_get(
'/checkstate',
accept => 'application/json',
query => 'user=dwho&password=dwho'
),
'Test no secret with user auth'
);
expectReject( $res, 500, "Bad secret" );
ok(
$res = $client->_get(
'/checkstate',
accept => 'application/json',
query => 'secret=xx&user=dwho&password=dwho'
),
'Test incorrect secret with user auth'
);
expectReject( $res, 500, "Bad secret" );
ok(
$res = $client->_get(
'/checkstate',
accept => 'application/json',
query => 'secret=x&user=dwho&password=davros'
),
'Test correct secret with bad user auth'
);
expectReject( $res, 500, "Bad result during auth: 5" );
is( $j->{result}, 1, "response has a result key with value 1" );
ok(
$res = $client->_get(
'/checkstate',
accept => 'application/json',
query => 'secret=x&user=dwho&password=dwho'
),
'Test correct secret with good user auth'
);
2020-12-23 16:23:28 +01:00
$j = expectJSON($res);
2020-12-09 18:01:44 +01:00
is( $j->{result}, 1, "response has a result key with value 1" );
done_testing();