From 58ee26a1283c3e703a53c3422dc7d15d09873fdd Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Mon, 6 Feb 2017 20:24:58 +0000 Subject: [PATCH] Combination seems finished (except tests) (#1151) --- .../Lemonldap/NG/Common/Conf/RESTServer.pm | 22 ++++++++++++ lemonldap-ng-manager/MANIFEST | 4 +++ .../lib/Lemonldap/NG/Manager/Conf.pm | 3 +- .../lib/Lemonldap/NG/Manager/Conf/Parser.pm | 19 +++++++++++ lemonldap-ng-manager/t/15-combination.t | 34 +++++++++++++++++++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 lemonldap-ng-manager/t/15-combination.t diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/RESTServer.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/RESTServer.pm index cb4a9d84d..c421cfb40 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/RESTServer.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/RESTServer.pm @@ -581,6 +581,28 @@ sub _scanCatsAndApps { return \@res; } +# 325 - Combination modules + +# Returns raw value, just transform "over" key +sub combModules { + my ( $self, $req, $key ) = @_; + return $self->sendError( 'Subkeys forbidden for combModules', 400 ) + if ($key); + my $val = $self->getConfKey( $req, 'combModules' ) // {}; + my $res = []; + foreach my $mod ( keys %$val ) { + my $tmp; + $tmp->{title} = $mod; + $tmp->{id} = "combModules/$mod"; + $tmp->{type} = 'cmbModule'; + $tmp->{data}->{$_} = $val->{$mod}->{$_} foreach (qw(type for)); + my $over = $val->{$mod}->{over} // {}; + $tmp->{data}->{over} = [ map { [ $_, $over->{$_} ] } keys %$over ]; + push @$res, $tmp; + } + return $self->sendJSONresponse($req,$res); +} + # 33 - Root queries # ----------- diff --git a/lemonldap-ng-manager/MANIFEST b/lemonldap-ng-manager/MANIFEST index 5617d185d..2eb29c609 100644 --- a/lemonldap-ng-manager/MANIFEST +++ b/lemonldap-ng-manager/MANIFEST @@ -78,6 +78,8 @@ site/static/forms/blackWhiteList.html site/static/forms/bool.html site/static/forms/boolOrExpr.html site/static/forms/catAndAppList.html +site/static/forms/cmbModule.html +site/static/forms/cmbModuleContainer.html site/static/forms/doubleHash.html site/static/forms/file.html site/static/forms/grant.html @@ -165,6 +167,7 @@ t/07-utf8.t t/10-save-unchanged-conf.t t/12-save-changed-conf.t t/14-bad-changes-in-conf.t +t/15-combination.t t/20-test-coverage.t t/40-sessions.t t/50-notifications.t @@ -176,5 +179,6 @@ t/jsonfiles/01-base-tree.json t/jsonfiles/02-base-tree-all-nodes-opened.json t/jsonfiles/12-modified.json t/jsonfiles/14-bad.json +t/jsonfiles/15-combination.json t/lemonldap-ng.ini t/test-lib.pm diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm index d0a51dc18..87fc60d2a 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm @@ -39,7 +39,8 @@ sub addRoutes { ':cfgNum' => [ qw(virtualHosts samlIDPMetaDataNodes samlSPMetaDataNodes applicationList oidcOPMetaDataNodes oidcRPMetaDataNodes - authChoiceModules grantSessionRules) + authChoiceModules grantSessionRules combModules + openIdIDPList) ] }, ['GET'] 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 facb53d89..f52d10824 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Parser.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Parser.pm @@ -643,6 +643,25 @@ sub _scanNodes { next; } + # combModules: just to replace "over" key + elsif ( $name eq 'combModules' ) { + hdebug('combModules'); + $self->newConf->{$name} = {}; + foreach my $node ( @{ $leaf->{nodes} } ) { + my $tmp; + $tmp->{$_} = $node->{data}->{$_} foreach (qw(type for)); + $tmp->{over} = {}; + foreach ( @{ $node->{data}->{over} } ) { + $tmp->{over}->{ $_->[0] } = $_->[1]; + } + $self->newConf->{$name}->{ $node->{title} } = $tmp; + } + + # TODO: check changes + $self->confChanged(1); + next; + } + #################### # Other hash nodes # #################### diff --git a/lemonldap-ng-manager/t/15-combination.t b/lemonldap-ng-manager/t/15-combination.t new file mode 100644 index 000000000..53edfd6bc --- /dev/null +++ b/lemonldap-ng-manager/t/15-combination.t @@ -0,0 +1,34 @@ +#!/usr/bin/env perl -I pl/lib +# +# Verify that bas changes are detected + +use Test::More; +use strict; +use JSON; +use Data::Dumper; +require 't/test-lib.pm'; + +my $struct = 't/jsonfiles/15-combination.json'; + +sub body { + return IO::File->new( $struct, 'r' ); +} + +unlink 't/conf/lmConf-2.json'; + +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->{result} == 1, "JSON response contains \"result:1\"" ) + or print STDERR Dumper($res); + +ok( $res = &client->_get( '/confs/2/combModules', 'application/json' ), 'Get combModules'); +ok( $resBody = from_json( $res->[2]->[0] ), "Result body contains JSON text" ); + +count(6); + +done_testing( count() ); + +unlink 't/conf/lmConf-2.json';