2016-01-07 12:40:24 +01:00
|
|
|
# Test REST API with valid and invalid requests.
|
|
|
|
# Check also metadatas request (root of a conf)
|
2015-05-14 08:44:38 +02:00
|
|
|
|
|
|
|
use Test::More;
|
2016-01-13 20:47:56 +01:00
|
|
|
use JSON;
|
2015-05-14 08:44:38 +02:00
|
|
|
use strict;
|
|
|
|
|
2015-05-14 08:45:03 +02:00
|
|
|
require 't/test-lib.pm';
|
2017-02-22 22:48:52 +01:00
|
|
|
my $struct = 'site/htdocs/static/struct.json';
|
2015-05-14 08:44:38 +02:00
|
|
|
|
|
|
|
my @bad = qw(
|
|
|
|
/confs/1567
|
|
|
|
/confs/abc
|
|
|
|
/confs/1/virtualHosts/unknown/locationRules
|
|
|
|
/confs/1/virtualHosts/test1.example.com
|
|
|
|
/confs/1/virtualHosts/test1.example.com/vhostPorts
|
|
|
|
/confs/1/samlIDPMetaDataNodes/unknown
|
|
|
|
/confs/1/samlSPMetaDataNodes/unknown
|
|
|
|
/confs/1/samlSPMetaDataNodes/unknown/key
|
|
|
|
/confs/1/applicationList/unknown
|
|
|
|
/confs/1/portal/unknown
|
|
|
|
);
|
|
|
|
my @good = qw(
|
|
|
|
/confs/latest
|
|
|
|
/confs/1
|
|
|
|
/confs/1/portal
|
|
|
|
/confs/1/virtualHosts
|
|
|
|
/confs/1/virtualHosts/test1.example.com/locationRules
|
|
|
|
/confs/1/virtualHosts/new__new.example.com/locationRules
|
|
|
|
/confs/1/virtualHosts/test1.example.com/vhostPort
|
|
|
|
/confs/1/samlIDPMetaDataNodes
|
|
|
|
/confs/1/samlSPMetaDataNodes
|
|
|
|
/confs/1/applicationList
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach my $query (@good) {
|
2016-01-01 20:55:29 +01:00
|
|
|
my $href = &client->jsonResponse($query);
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $query (@bad) {
|
2016-01-01 20:55:35 +01:00
|
|
|
my $res = &client->_get( $query, '' );
|
2015-05-14 08:44:38 +02:00
|
|
|
ok( $res->[0] == 400, "Request reject for $query" )
|
|
|
|
or print STDERR "# Receive a $res->[0] code";
|
|
|
|
my $href;
|
|
|
|
|
2016-01-11 21:32:44 +01:00
|
|
|
ok( $href = from_json( $res->[2]->[0] ), 'Response is JSON' );
|
2015-05-14 08:44:38 +02:00
|
|
|
ok( $href->{error}, "Receive an explanation message ($href->{error})" );
|
|
|
|
count(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
open F, $struct or die "Unable to open $struct";
|
|
|
|
my @hkeys;
|
|
|
|
my $hstruct = '';
|
|
|
|
while (<F>) {
|
|
|
|
push @hkeys, ( $_ =~ /cnodes":"([^"]+)/g );
|
|
|
|
$hstruct .= $_;
|
|
|
|
}
|
|
|
|
close F;
|
|
|
|
|
2016-01-11 21:32:44 +01:00
|
|
|
ok( $hstruct = from_json($hstruct), 'struct.json is JSON' );
|
2016-01-19 22:22:05 +01:00
|
|
|
ok( ref $hstruct eq 'ARRAY', 'struct.json is an array' )
|
|
|
|
or print STDERR "Expected: ARRAY, got: " . ( ref $hstruct ) . "\n";
|
2015-05-14 08:44:38 +02:00
|
|
|
count(2);
|
|
|
|
|
|
|
|
foreach my $query (@hkeys) {
|
2016-01-01 20:55:29 +01:00
|
|
|
my $href = &client->jsonResponse( "/confs/1/$query", '' );
|
2019-02-07 09:27:56 +01:00
|
|
|
ok( (
|
2016-02-17 15:31:30 +01:00
|
|
|
( ref $href eq 'ARRAY' )
|
|
|
|
or ( ( ref $href eq 'HASH' )
|
|
|
|
and ( $href->{error} =~ /setDefault$/ ) )
|
|
|
|
),
|
2016-01-19 22:22:05 +01:00
|
|
|
'Response is an array'
|
|
|
|
);
|
2015-05-14 08:44:38 +02:00
|
|
|
count(1);
|
2016-01-19 22:22:05 +01:00
|
|
|
next if ( ( ref $href eq 'HASH' ) and ( $href->{error} =~ /setDefault$/ ) );
|
2015-05-14 08:44:38 +02:00
|
|
|
foreach my $k (@$href) {
|
|
|
|
ok( defined $k->{title}, 'Title defined' );
|
|
|
|
ok( defined $k->{id}, 'Id defined' );
|
|
|
|
count(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Metadatas
|
|
|
|
{
|
2016-01-01 20:55:29 +01:00
|
|
|
my $href = &client->jsonResponse( 'confs/1', '' );
|
2015-05-14 08:44:38 +02:00
|
|
|
foreach (qw(cfgNum cfgAuthor cfgAuthorIP cfgDate)) {
|
|
|
|
ok( exists( $href->{$_} ), "Key $_ exists" );
|
|
|
|
}
|
|
|
|
ok( $href->{cfgNum} == 1, 'cfgNum is set to 1' );
|
|
|
|
count(5);
|
|
|
|
}
|
|
|
|
|
2015-10-22 10:40:12 +02:00
|
|
|
done_testing( count() );
|
2015-05-14 08:44:38 +02:00
|
|
|
|