lemonldap-ng/lemonldap-ng-manager/t/10-save-unchanged-conf.t

57 lines
1.5 KiB
Perl
Raw Normal View History

2016-01-07 12:40:24 +01:00
# Verify that an unmodified configuration is rejected
use Data::Dumper;
use Test::More;
use strict;
2016-01-13 20:47:56 +01:00
use JSON;
2015-05-14 08:45:03 +02:00
require 't/test-lib.pm';
my @struct =
2015-05-14 08:45:03 +02:00
qw[t/jsonfiles/01-base-tree.json t/jsonfiles/02-base-tree-all-nodes-opened.json];
2019-07-02 20:03:40 +02:00
my @desc = ( 'Unopened conf', 'Unchanged conf with all nodes opened' );
my $confFiles = [ 't/conf/lmConf-1.json', 't/conf/lmConf-2.json' ];
sub body {
return 0 unless (@struct);
my $t = shift @struct;
return IO::File->new( $t, 'r' );
}
# Delete lmConf-2.json if exists
eval { unlink $confFiles->[1]; };
2017-01-27 10:39:58 +01:00
mkdir 't/sessions';
# Try to save an unmodified conf
while ( my $body = &body() ) {
my $desc = shift @desc;
my ( $res, $resBody );
ok(
$res =
2016-01-01 20:55:35 +01:00
&client->_post( '/confs/', 'cfgNum=1', $body, 'application/json' ),
"$desc: positive result"
);
2016-01-22 17:53:41 +01:00
ok( $res->[0] == 200, "$desc: result code is 200" )
or print STDERR Dumper($res);
ok(
2016-01-11 21:32:44 +01:00
$resBody = from_json( $res->[2]->[0] ),
"$desc: result body contains JSON text"
);
#print STDERR Dumper($resBody);
ok( $resBody->{result} == 0, "$desc: JSON response contains \"result:0\"" );
ok( $resBody->{message} eq '__confNotChanged__',
"$desc: conf was not changed" )
or print STDERR Dumper($resBody);
ok( !-e $confFiles->[1], "$desc: file isn't created" );
#print STDERR Dumper($resBody);
count(6);
}
2017-01-27 10:39:58 +01:00
eval { unlink $confFiles->[1]; rmdir 't/sessions'; };
done_testing( count() );
2018-12-01 22:36:03 +01:00
# Remove sessions directory
`rm -rf t/sessions`;