From b50e985ee6793808367565d1b7536ee26685d1bd Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Fri, 15 Jan 2016 06:27:45 +0000 Subject: [PATCH] Check for removed apps (#907) Not completly verified --- .../lib/Lemonldap/NG/Manager/Conf/Parser.pm | 12 ++++++++++- lemonldap-ng-manager/t/12-save-changed-conf.t | 21 +++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Parser.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Parser.pm index d8947c3c2..4510f415d 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Parser.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Parser.pm @@ -432,8 +432,18 @@ sub _scanNodes { if ( ref $subNodes ) { $self->_scanNodes($subNodes) or return 0; } + my @listCatRef = keys %{ $cmp->{$app} }; + my @listCatNew = keys %{ $cn->{$s} }; - # TODO: check for deleted + # Check for deleted + unless ( @listCatRef == @listCatNew ) { + $self->confChanged(1); + push @{ $self->changes }, + { + key => join( ', ', 'applicationList', @path ), + new => 'New cat(s)/app(s)', + }; + } } # Create new apps diff --git a/lemonldap-ng-manager/t/12-save-changed-conf.t b/lemonldap-ng-manager/t/12-save-changed-conf.t index bdd29b6a9..8fe73a34b 100644 --- a/lemonldap-ng-manager/t/12-save-changed-conf.t +++ b/lemonldap-ng-manager/t/12-save-changed-conf.t @@ -23,20 +23,29 @@ my ( $res, $resBody ); ok( $res = &client->_post( '/confs/', 'cfgNum=1', &body, 'application/json' ), "Request succeed" ); ok( $res->[0] == 200, "Result code is 200" ); -ok( $resBody = from_json( $res->[2]->[0] ), - "Result body contains JSON text" ); +ok( $resBody = from_json( $res->[2]->[0] ), "Result body contains JSON text" ); ok( $resBody->{result} == 1, "JSON response contains \"result:1\"" ) or print STDERR Dumper($resBody); ok( -f $confFiles->[1], 'File is created' ); my @changes = @{&changes}; my @cmsg = @{ $resBody->{details}->{__changes__} }; -ok( @changes == @cmsg, 'Same changes count' ); +my $bug; +ok( @changes == @cmsg, 'Same changes count' ) or $bug = 1; while ( my $c = shift @{ $resBody->{details}->{__changes__} } ) { + my $cmp1 = @changes; + my $cmp2 = @cmsg; + @changes = grep { $_->{key} ne $c->{key} } @changes; @cmsg = grep { $_->{key} ne $c->{key} } @cmsg; + ok( ( $cmp1 - @changes ) == ( $cmp2 - @cmsg ), "$c->{key} found" ); + count(1); +} +ok( !@changes, 'All changes detected' ) or $bug = 1; + +if ($bug) { + print STDERR Dumper( \@changes, \@cmsg ); } -ok( !@changes, 'All changes detected' ); #print STDERR Dumper(\@changes,\@cmsg); @@ -67,6 +76,10 @@ sub changes { 'new' => 'Application Test 3', 'key' => 'applicationList, Sample applications' }, + { + 'key' => 'applicationList', + 'new' => 'New cat(s)/app(s)' + }, { 'key' => 'userDB', 'new' => 'LDAP',