Append serach engine unit tests

This commit is contained in:
Christophe Maudoux 2018-08-25 20:07:36 +02:00
parent 944d7a5c8a
commit bc73f9d420

View File

@ -1,4 +1,4 @@
# Test sessions explorer API
# Test 2ndFA manager API
use Test::More;
use JSON;
@ -131,10 +131,10 @@ for ( my $i = 1 ; $i < 6 ; $i++ ) {
}
count(5);
# "All" query
## "All" query
$res = &client->jsonResponse( '/sfa/persistent',
'groupBy=substr(uid,1)&U2FCheck=1&TOTPCheck=1&UBKCheck=1' );
ok( $res->{result} == 1, 'Result code = 1' );
ok( $res->{result} == 1, 'Search * - Result code = 1' );
ok( $res->{count} == 3, 'Found 3 results' ) or print STDERR Dumper($res);
ok( @{ $res->{values} } == 3, 'List 3 results' );
ok( $res->{values}->[0]->{value} && $res->{values}->[0]->{value} eq 'd',
@ -151,10 +151,63 @@ ok( $res->{values}->[1]->{count} == 1, 'Found 1 session starting with "r"' );
ok( $res->{values}->[2]->{count} == 1, 'Found 1 session starting with "t"' );
count(9);
# "Filtered by U2F" query
## "Search by UID" query
# uid=d*
$res = &client->jsonResponse( '/sfa/persistent',
'uid=d*&groupBy=substr(uid,1)&U2FCheck=1&TOTPCheck=1&UBKCheck=1' );
ok( $res->{result} == 1, 'Search "uid"=d* - Result code = 1' );
ok( $res->{count} == 1, 'Found 1 result' ) or print STDERR Dumper($res);
ok( @{ $res->{values} } == 1, 'List 1 result' );
ok( $res->{values}->[0]->{value} && $res->{values}->[0]->{value} eq 'd',
'Result match "uid=d"' )
or print STDERR Dumper($res);
ok( $res->{values}->[0]->{count} == 2, 'Found 2 sessions starting with "d"' );
count(5);
# uid=dw*
$res = &client->jsonResponse( '/sfa/persistent',
'uid=dw*&groupBy=substr(uid,2)&U2FCheck=1&TOTPCheck=1&UBKCheck=1' );
ok( $res->{result} == 1, 'Search "uid"=dw* - Result code = 1' );
ok( $res->{count} == 1, 'Found 1 result' ) or print STDERR Dumper($res);
ok( @{ $res->{values} } == 1, 'List 1 result' );
ok( $res->{values}->[0]->{value} && $res->{values}->[0]->{value} eq 'dw',
'Result match "uid=dw"' )
or print STDERR Dumper($res);
ok( $res->{values}->[0]->{count} == 1, 'Found 1 session starting with "dw"' );
count(5);
# uid=d* & UBK
$res = &client->jsonResponse( '/sfa/persistent',
'uid=d*&groupBy=substr(uid,1)&U2FCheck=1&TOTPCheck=1&UBKCheck=2' );
ok( $res->{result} == 1, 'Search "uid"=d* & UBK - Result code = 1' );
ok( $res->{count} == 1, 'Found 1 result' ) or print STDERR Dumper($res);
ok( @{ $res->{values} } == 1, 'List 1 result' );
ok( $res->{values}->[0]->{value} && $res->{values}->[0]->{value} eq 'd',
'Result match "uid=d"' )
or print STDERR Dumper($res);
ok( $res->{values}->[0]->{count} == 1, 'Found 1 session starting with "d" & UBK' );
count(5);
# uid=dw* & UBK
$res = &client->jsonResponse( '/sfa/persistent',
'uid=dw*&groupBy=substr(uid,2)&U2FCheck=1&TOTPCheck=1&UBKCheck=2' );
ok( $res->{result} == 1, 'Search "uid"=dw* & UBK - Result code = 1' );
ok( $res->{count} == 1, 'Found 1 result' ) or print STDERR Dumper($res);
ok( @{ $res->{values} } == 1, 'List 1 result' );
ok( $res->{values}->[0]->{value} && $res->{values}->[0]->{value} eq 'dw',
'Result match "uid=dw"' )
or print STDERR Dumper($res);
ok( $res->{values}->[0]->{count} == 1, 'Found 1 session starting with "dw" & UBK' );
count(5);
# uid=da* & UBK
$res = &client->jsonResponse( '/sfa/persistent',
'uid=da*&groupBy=substr(uid,2)&U2FCheck=1&TOTPCheck=1&UBKCheck=2' );
ok( $res->{result} == 1, 'Search "uid"=da* & UBK - Result code = 1' );
ok( $res->{count} == 0, 'Found 0 session with "da" & UBK' ) or print STDERR Dumper($res);
ok( @{ $res->{values} } == 0, 'List 0 result' );
count(3);
## "Filtered by U2F" query
$res = &client->jsonResponse( '/sfa/persistent',
'uid=*&groupBy=substr(uid,0)&U2FCheck=2&TOTPCheck=1&UBKCheck=1' );
ok( $res->{result} == 1, 'Result code = 1' );
ok( $res->{result} == 1, 'Search "uid"=* & UBK - Result code = 1' );
ok( $res->{count} == 3, 'Found 3 results' ) or print STDERR Dumper($res);
ok( @{ $res->{values} } == 3, 'List 3 results' );
ok( $res->{values}->[0]->{value} && $res->{values}->[0]->{value} eq 'd',
@ -166,39 +219,39 @@ ok( $res->{values}->[1]->{value} && $res->{values}->[1]->{value} eq 'r',
ok( $res->{values}->[2]->{value} && $res->{values}->[2]->{value} eq 't',
'Result match "uid=t"' )
or print STDERR Dumper($res);
ok( $res->{values}->[0]->{count} == 2, 'Found 2 sessions starting with "d"' );
ok( $res->{values}->[1]->{count} == 1, 'Found 1 session starting with "r"' );
ok( $res->{values}->[2]->{count} == 1, 'Found 1 session starting with "t"' );
ok( $res->{values}->[0]->{count} == 2, 'Found 2 sessions starting with "d" & U2F' );
ok( $res->{values}->[1]->{count} == 1, 'Found 1 session starting with "r" & U2F' );
ok( $res->{values}->[2]->{count} == 1, 'Found 1 session starting with "t" & U2F' );
count(9);
# "Filtered by U2F & TOTP" query
## "Filtered by U2F & TOTP" query
$res = &client->jsonResponse( '/sfa/persistent',
'uid=*&groupBy=substr(uid,0)&U2FCheck=2&TOTPCheck=2&UBKCheck=1' );
ok( $res->{result} == 1, 'Result code = 1' );
ok( $res->{result} == 1, 'Search "uid"=* & UBK & TOTP - Result code = 1' );
ok( $res->{count} == 1, 'Found 1 result' ) or print STDERR Dumper($res);
ok( @{ $res->{values} } == 1, 'List 1 result' );
ok( $res->{values}->[0]->{value} && $res->{values}->[0]->{value} eq 'd',
'Result match "uid=d"' )
or print STDERR Dumper($res);
ok( $res->{values}->[0]->{count} == 2, 'Found 2 sessiond starting with "d"' );
ok( $res->{values}->[0]->{count} == 2, 'Found 2 sessiond starting with "d" & U2F & TOTP' );
count(5);
# "Filtered by U2F & TOTP & UBK" query
## "Filtered by U2F & TOTP & UBK" query
$res = &client->jsonResponse( '/sfa/persistent',
'uid=*&groupBy=substr(uid,0)&U2FCheck=2&TOTPCheck=2&UBKCheck=2' );
ok( $res->{result} == 1, 'Result code = 1' );
ok( $res->{result} == 1, 'Search "uid"=* & UBK & TOTP & UBK - Result code = 1' );
ok( $res->{count} == 1, 'Found 1 result' ) or print STDERR Dumper($res);
ok( @{ $res->{values} } == 1, 'List 1 result' );
ok( $res->{values}->[0]->{value} && $res->{values}->[0]->{value} eq 'd',
'Result match "uid=d"' )
or print STDERR Dumper($res);
ok( $res->{values}->[0]->{count} == 1, 'Found 1 session starting with "d"' );
ok( $res->{values}->[0]->{count} == 1, 'Found 1 session starting with "d" & U2F & TOTP & UBK' );
count(5);
# "Filtered by U2F & UBK" query
## "Filtered by U2F & UBK" query
$res = &client->jsonResponse( '/sfa/persistent',
'uid=*&groupBy=substr(uid,0)&U2FCheck=2&TOTPCheck=1&UBKCheck=2' );
ok( $res->{result} == 1, 'Result code = 1' );
ok( $res->{result} == 1, 'Search "uid"=* & UBK & UBK - Result code = 1' );
ok( $res->{count} == 2, 'Found 2 results' ) or print STDERR Dumper($res);
ok( @{ $res->{values} } == 2, 'List 2 results' );
ok( $res->{values}->[0]->{value} && $res->{values}->[0]->{value} eq 'd',
@ -207,11 +260,12 @@ ok( $res->{values}->[0]->{value} && $res->{values}->[0]->{value} eq 'd',
ok( $res->{values}->[1]->{value} && $res->{values}->[1]->{value} eq 'r',
'Result match "uid=r"' )
or print STDERR Dumper($res);
ok( $res->{values}->[0]->{count} == 1, 'Found 1 session starting with "d"' );
ok( $res->{values}->[1]->{count} == 1, 'Found 1 session starting with "r"' );
ok( $res->{values}->[0]->{count} == 1, 'Found 1 session starting with "d" & U2F & UBK' );
ok( $res->{values}->[1]->{count} == 1, 'Found 1 session starting with "r" & U2F & UBK' );
count(7);
# Delete 2F devices
## Delete 2F devices
# Delete U2F devices
foreach ( 1 .. 5 ) {
ok(
$res =
@ -223,17 +277,7 @@ foreach ( 1 .. 5 ) {
'Body is JSON and result==1' );
count(3);
}
foreach ( 2 .. 3 ) {
ok(
$res =
&client->_del( "sfa/persistent/$ids[$_]", "type=UBK&epoch=$epoch" ),
"Delete UBK from $_"
);
ok( $res->[0] == 200, 'Result code is 200' );
ok( from_json( $res->[2]->[0] )->{result} == 1,
'Body is JSON and result==1' );
count(3);
}
# Delete TOTP devices
foreach ( 3 .. 4 ) {
ok(
$res =
@ -245,12 +289,24 @@ foreach ( 3 .. 4 ) {
'Body is JSON and result==1' );
count(3);
}
# Delete UBK devices
foreach ( 2 .. 3 ) {
ok(
$res =
&client->_del( "sfa/persistent/$ids[$_]", "type=UBK&epoch=$epoch" ),
"Delete UBK from $_"
);
ok( $res->[0] == 200, 'Result code is 200' );
ok( from_json( $res->[2]->[0] )->{result} == 1,
'Body is JSON and result==1' );
count(3);
}
# Check than all devices have been deleted with "All" query
## Check than all devices have been deleted with "All" query
$res = &client->jsonResponse( '/sfa/persistent',
'groupBy=substr(uid,1)&U2FCheck=1&TOTPCheck=1&UBKCheck=1' );
ok( $res->{result} == 1, 'Result code = 1' );
ok( $res->{count} == 0, 'Found 0 result' ) or print STDERR Dumper($res);
ok( $res->{count} == 0, 'Found 0 session with 2F device' ) or print STDERR Dumper($res);
ok( @{ $res->{values} } == 0, 'List 0 result' );
count(3);