2015-05-14 08:44:38 +02:00
|
|
|
#!/usr/bin/env perl -I pl/lib
|
|
|
|
|
|
|
|
use Test::More;
|
|
|
|
use JSON;
|
|
|
|
use strict;
|
|
|
|
use 5.10.0;
|
|
|
|
|
2015-05-14 08:45:03 +02:00
|
|
|
require 't/test-lib.pm';
|
|
|
|
my $struct = 'site/static/struct.json';
|
2015-05-14 08:44:38 +02:00
|
|
|
|
|
|
|
my @bad = qw(
|
|
|
|
/conf/latest
|
|
|
|
/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) {
|
|
|
|
my $href = jsonResponse($query);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $query (@bad) {
|
|
|
|
my $res = get( $query, '' );
|
|
|
|
ok( $res->[0] == 400, "Request reject for $query" )
|
|
|
|
or print STDERR "# Receive a $res->[0] code";
|
|
|
|
my $href;
|
|
|
|
|
|
|
|
#print STDERR Dumper($res->[2]);use Data::Dumper;
|
|
|
|
ok( $href = decode_json( $res->[2]->[0] ), 'Response is JSON' );
|
|
|
|
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;
|
|
|
|
|
|
|
|
ok( $hstruct = decode_json($hstruct), 'struct.json is JSON' );
|
|
|
|
ok( ref $hstruct eq 'ARRAY', 'struct.json is an array' );
|
|
|
|
count(2);
|
|
|
|
|
|
|
|
foreach my $query (@hkeys) {
|
2015-10-22 10:40:12 +02:00
|
|
|
my $href = jsonResponse( "/confs/1/$query", '' );
|
2015-05-14 08:44:38 +02:00
|
|
|
ok( ref $href eq 'ARRAY', 'Response is an array' );
|
|
|
|
count(1);
|
|
|
|
foreach my $k (@$href) {
|
|
|
|
ok( defined $k->{title}, 'Title defined' );
|
|
|
|
ok( defined $k->{id}, 'Id defined' );
|
|
|
|
count(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Metadatas
|
|
|
|
{
|
2015-10-22 10:40:12 +02:00
|
|
|
my $href = 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
|
|
|
|