From 124b65a44727a0ce423e6f53cf001ed869f03d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 4 Jun 2019 13:56:38 +0200 Subject: [PATCH 01/10] Add helper function to convert boolean for api calls GMP uses 0 for false and 1 for true in its api calls. --- gsa/src/gmp/commands/__tests__/convert.js | 37 +++++++++++++++++++++++ gsa/src/gmp/commands/convert.js | 34 +++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 gsa/src/gmp/commands/__tests__/convert.js create mode 100644 gsa/src/gmp/commands/convert.js diff --git a/gsa/src/gmp/commands/__tests__/convert.js b/gsa/src/gmp/commands/__tests__/convert.js new file mode 100644 index 0000000000..2d0df89cc4 --- /dev/null +++ b/gsa/src/gmp/commands/__tests__/convert.js @@ -0,0 +1,37 @@ +/* Copyright (C) 2019 Greenbone Networks GmbH + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +import {convertBoolean} from '../convert'; + +describe('convertBoolean tests', () => { + test('should convert true', () => { + expect(convertBoolean(true)).toEqual(1); + }); + + test('should convert false', () => { + expect(convertBoolean(false)).toEqual(0); + }); + + test('should convert to undefined for other value', () => { + expect(convertBoolean('true')).toBeUndefined(); + expect(convertBoolean('false')).toBeUndefined(); + expect(convertBoolean(1)).toBeUndefined(); + expect(convertBoolean(0)).toBeUndefined(); + }); +}); diff --git a/gsa/src/gmp/commands/convert.js b/gsa/src/gmp/commands/convert.js new file mode 100644 index 0000000000..2c7f467c87 --- /dev/null +++ b/gsa/src/gmp/commands/convert.js @@ -0,0 +1,34 @@ +/* Copyright (C) 2019 Greenbone Networks GmbH + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * Convert boolean true/false to API 1/0 values + * + * It converts true to int 1 and false to 0. Converting other values returns + * undefined. + */ +export const convertBoolean = value => { + if (value === true) { + return 1; + } + if (value === false) { + return 0; + } + return undefined; +}; From 06b8dd484715910f443130964a0a63f095b5eeff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 4 Jun 2019 13:58:12 +0200 Subject: [PATCH 02/10] Expect true and false for enable/disable ldap and radius Add tests for saveLdap and savRadius to ensure the new behavior. --- gsa/src/gmp/commands/__tests__/auth.js | 133 +++++++++++++++++++++++++ gsa/src/gmp/commands/auth.js | 12 ++- 2 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 gsa/src/gmp/commands/__tests__/auth.js diff --git a/gsa/src/gmp/commands/__tests__/auth.js b/gsa/src/gmp/commands/__tests__/auth.js new file mode 100644 index 0000000000..d474c14a10 --- /dev/null +++ b/gsa/src/gmp/commands/__tests__/auth.js @@ -0,0 +1,133 @@ +/* Copyright (C) 2019 Greenbone Networks GmbH + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +import {AuthenticationCommand} from '../auth'; + +import {createActionResultResponse, createHttp} from '../testing'; + +describe('AuthenticationCommand tests', () => { + test('should enable ldap', () => { + const response = createActionResultResponse(); + const fakeHttp = createHttp(response); + + const authdn = 'cn=%s,dc=devel,dc=foo,dc=bar'; + const certificate = 'foobar'; + const ldaphost = 'foo.bar'; + + expect.hasAssertions(); + + const cmd = new AuthenticationCommand(fakeHttp); + return cmd + .saveLdap({ + authdn, + certificate, + enable: true, + ldaphost, + }) + .then(() => { + expect(fakeHttp.request).toHaveBeenCalledWith('post', { + data: { + authdn, + certificate, + cmd: 'save_auth', + enable: 1, + group: 'method:ldap_connect', + ldaphost, + }, + }); + }); + }); + + test('should disable ldap', () => { + const response = createActionResultResponse(); + const fakeHttp = createHttp(response); + + const authdn = 'cn=%s,dc=devel,dc=foo,dc=bar'; + const certificate = 'foobar'; + const ldaphost = 'foo.bar'; + + expect.hasAssertions(); + + const cmd = new AuthenticationCommand(fakeHttp); + return cmd + .saveLdap({ + authdn, + certificate, + enable: false, + ldaphost, + }) + .then(() => { + expect(fakeHttp.request).toHaveBeenCalledWith('post', { + data: { + authdn, + certificate, + cmd: 'save_auth', + enable: 0, + group: 'method:ldap_connect', + ldaphost, + }, + }); + }); + }); + + test('should enable radius', () => { + const response = createActionResultResponse(); + const fakeHttp = createHttp(response); + + const radiushost = 'foo.bar'; + const radiuskey = 'foo'; + + expect.hasAssertions(); + + const cmd = new AuthenticationCommand(fakeHttp); + return cmd.saveRadius({enable: true, radiushost, radiuskey}).then(() => { + expect(fakeHttp.request).toBeCalledWith('post', { + data: { + cmd: 'save_auth', + enable: 1, + group: 'method:radius_connect', + radiushost, + radiuskey, + }, + }); + }); + }); + + test('should disable radius', () => { + const response = createActionResultResponse(); + const fakeHttp = createHttp(response); + + const radiushost = 'foo.bar'; + const radiuskey = 'foo'; + + expect.hasAssertions(); + + const cmd = new AuthenticationCommand(fakeHttp); + return cmd.saveRadius({enable: false, radiushost, radiuskey}).then(() => { + expect(fakeHttp.request).toBeCalledWith('post', { + data: { + cmd: 'save_auth', + enable: 0, + group: 'method:radius_connect', + radiushost, + radiuskey, + }, + }); + }); + }); +}); diff --git a/gsa/src/gmp/commands/auth.js b/gsa/src/gmp/commands/auth.js index daf7355acc..1bc981f63c 100644 --- a/gsa/src/gmp/commands/auth.js +++ b/gsa/src/gmp/commands/auth.js @@ -20,23 +20,25 @@ import registerCommand from '../command'; import HttpCommand from './http'; -class AuthenticationCommand extends HttpCommand { - saveLdap({authdn, certificate, enable, group, ldaphost}) { +import {convertBoolean} from './convert'; + +export class AuthenticationCommand extends HttpCommand { + saveLdap({authdn, certificate, enable, ldaphost}) { return this.httpPost({ cmd: 'save_auth', group: 'method:ldap_connect', authdn, certificate, - enable, + enable: convertBoolean(enable), ldaphost, }); } - saveRadius({enable, group, radiushost, radiuskey}) { + saveRadius({enable, radiushost, radiuskey}) { return this.httpPost({ cmd: 'save_auth', group: 'method:radius_connect', - enable, + enable: convertBoolean(enable), radiushost, radiuskey, }); From 5a26a2d3ffe3aac8719b381b17e0704b36e82585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 4 Jun 2019 15:18:11 +0200 Subject: [PATCH 03/10] Update creating Settings instance in tests The constructor of the Settings class doesn't take any arguments. --- gsa/src/gmp/models/__tests__/settings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gsa/src/gmp/models/__tests__/settings.js b/gsa/src/gmp/models/__tests__/settings.js index 65aa58abac..fe4b791088 100644 --- a/gsa/src/gmp/models/__tests__/settings.js +++ b/gsa/src/gmp/models/__tests__/settings.js @@ -21,7 +21,7 @@ import Settings from 'gmp/models/settings'; describe('Settings model tests', () => { test('settings have working setters and getters', () => { - const settings = new Settings({}); + const settings = new Settings(); settings.set('foo', 'bar'); const res = settings.get('foo'); const res2 = settings.get(''); @@ -31,7 +31,7 @@ describe('Settings model tests', () => { }); test('getEntries() should return all settings', () => { - const settings = new Settings({}); + const settings = new Settings(); settings.set('foo', 'bar'); settings.set('lorem', 'ipsum'); From 0b7213ebd781846568a09e16238b6a59ba23b8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 4 Jun 2019 15:19:04 +0200 Subject: [PATCH 04/10] Extend Settings by a has method Allow to check if a specific name is available in the settings. --- gsa/src/gmp/models/__tests__/settings.js | 12 ++++++++++++ gsa/src/gmp/models/settings.js | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/gsa/src/gmp/models/__tests__/settings.js b/gsa/src/gmp/models/__tests__/settings.js index fe4b791088..c5bcff2ace 100644 --- a/gsa/src/gmp/models/__tests__/settings.js +++ b/gsa/src/gmp/models/__tests__/settings.js @@ -37,6 +37,18 @@ describe('Settings model tests', () => { expect(settings.getEntries()).toEqual([['foo', 'bar'], ['lorem', 'ipsum']]); }); + + test('should not have non existing key', () => { + const settings = new Settings(); + expect(settings.has('foo')).toEqual(false); + }); + + test('should have existing key', () => { + const settings = new Settings(); + settings.set('foo', 'bar'); + + expect(settings.has('foo')).toEqual(true); + }); }); // vim: set ts=2 sw=2 tw=80: diff --git a/gsa/src/gmp/models/settings.js b/gsa/src/gmp/models/settings.js index 890728ee87..2526bfd174 100644 --- a/gsa/src/gmp/models/settings.js +++ b/gsa/src/gmp/models/settings.js @@ -26,6 +26,10 @@ class Settings { this._settings = {}; } + has(name) { + return name in this._settings; + } + set(name, value) { this._settings[name] = value; } From 2c934096cbad2291015a7f1c3d5a3f4cd59b4d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 4 Jun 2019 15:40:53 +0200 Subject: [PATCH 05/10] Add simple createResponse function for command testing With this new function it is easier to create generic responses for testing of command classes. --- gsa/src/gmp/commands/testing.js | 60 ++++++++++++++------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/gsa/src/gmp/commands/testing.js b/gsa/src/gmp/commands/testing.js index 705fd395fa..470ff9fa77 100644 --- a/gsa/src/gmp/commands/testing.js +++ b/gsa/src/gmp/commands/testing.js @@ -29,55 +29,45 @@ const createEntitiesCounts = entities => ({ _page: entities.length, }); +export const createResponse = data => new Response({}, data); + export const createEntitiesResponse = (name, entities) => - new Response( - {}, - { - [`get_${name}s`]: { - [`get_${name}s_response`]: { - [name]: entities, - [`${name}s`]: entitiesRange, - [`${name}_count`]: createEntitiesCounts(entities), - }, + createResponse({ + [`get_${name}s`]: { + [`get_${name}s_response`]: { + [name]: entities, + [`${name}s`]: entitiesRange, + [`${name}_count`]: createEntitiesCounts(entities), }, }, - ); + }); export const createEntityResponse = (name, entity) => - new Response( - {}, - { - [`get_${name}`]: { - [`get_${name}s_response`]: { - [name]: entity, - }, + createResponse({ + [`get_${name}`]: { + [`get_${name}s_response`]: { + [name]: entity, }, }, - ); + }); export const createActionResultResponse = () => - new Response( - {}, - { - action_result: { - action: 'ipsum', - id: 'foo', - message: 'OK', - }, + createResponse({ + action_result: { + action: 'ipsum', + id: 'foo', + message: 'OK', }, - ); + }); export const createAggregatesResponse = (data = {}) => - new Response( - {}, - { - get_aggregate: { - get_aggregates_response: { - aggregate: data, - }, + createResponse({ + get_aggregate: { + get_aggregates_response: { + aggregate: data, }, }, - ); + }); export const createHttp = response => ({ request: jest.fn().mockReturnValue(Promise.resolve(response)), From 116040ecfc609d2bfc0385e4155f419ec522059f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 4 Jun 2019 15:42:04 +0200 Subject: [PATCH 06/10] Adjust UserCommand currentAuthSettings to use bool for enable Als rename enable variable to enabled and add test for currentAuthSettings. --- gsa/src/gmp/commands/__tests__/user.js | 80 ++++++++++++++++++++++++++ gsa/src/gmp/commands/users.js | 6 +- 2 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 gsa/src/gmp/commands/__tests__/user.js diff --git a/gsa/src/gmp/commands/__tests__/user.js b/gsa/src/gmp/commands/__tests__/user.js new file mode 100644 index 0000000000..23dad79f69 --- /dev/null +++ b/gsa/src/gmp/commands/__tests__/user.js @@ -0,0 +1,80 @@ +/* Copyright (C) 2019 Greenbone Networks GmbH + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +import {UserCommand} from '../users'; + +import {createResponse, createHttp} from '../testing'; +describe('UserCommand tests', () => { + test('should parse auth settinngs in currentAuthSettings', () => { + const response = createResponse({ + auth_settings: { + describe_auth_response: { + group: [ + { + _name: 'foo', + auth_conf_setting: [ + { + key: 'enable', + value: 'true', + }, + ], + }, + { + _name: 'bar', + auth_conf_setting: [ + { + key: 'foo', + value: 'true', + }, + { + certificate_info: 'ipsum', + }, + ], + }, + ], + }, + }, + }); + const fakeHttp = createHttp(response); + + expect.hasAssertions(); + + const cmd = new UserCommand(fakeHttp); + return cmd.currentAuthSettings().then(resp => { + expect(fakeHttp.request).toHaveBeenCalledWith('get', { + args: { + cmd: 'auth_settings', + name: '--', + }, + }); + + const {data: settings} = resp; + + expect(settings.has('foo')).toEqual(true); + expect(settings.has('bar')).toEqual(true); + expect(settings.has('ipsum')).toEqual(false); + + const fooSettings = settings.get('foo'); + expect(fooSettings.enabled).toEqual(true); + + const barSettings = settings.get('bar'); + expect(barSettings.foo).toEqual('true'); + expect(barSettings.certificateInfo).toEqual('ipsum'); + }); + }); +}); diff --git a/gsa/src/gmp/commands/users.js b/gsa/src/gmp/commands/users.js index a56d7254f4..ce3fa63622 100644 --- a/gsa/src/gmp/commands/users.js +++ b/gsa/src/gmp/commands/users.js @@ -20,8 +20,6 @@ import logger from '../log'; import registerCommand from '../command'; -import {YES_VALUE, NO_VALUE} from 'gmp/parser'; - import {forEach, map} from '../utils/array'; import {isDefined} from '../utils/identity'; import {severityValue} from '../utils/number'; @@ -86,7 +84,7 @@ export const DEFAULT_FILTER_SETTINGS = { const saveDefaultFilterSettingId = entityType => `settings_filter:${DEFAULT_FILTER_SETTINGS[entityType]}`; -class UserCommand extends EntityCommand { +export class UserCommand extends EntityCommand { constructor(http) { super(http, 'user', User); } @@ -113,7 +111,7 @@ class UserCommand extends EntityCommand { forEach(group.auth_conf_setting, setting => { if (setting.key === 'enable') { - values.enable = setting.value === 'true' ? YES_VALUE : NO_VALUE; + values.enabled = setting.value === 'true'; } else { values[setting.key] = setting.value; } From c16adbb2b167c5ff35518c76dc15bfaec9f399c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 4 Jun 2019 15:45:21 +0200 Subject: [PATCH 07/10] Use bool values for enabled/disabled radius and ldap in dialogs Update User, Ldap and Radius dialog to use bool values for enable. --- gsa/src/web/pages/ldap/__tests__/dialog.js | 12 +++++----- gsa/src/web/pages/ldap/dialog.js | 23 +++++++++++--------- gsa/src/web/pages/radius/__tests__/dialog.js | 12 +++++----- gsa/src/web/pages/radius/dialog.js | 23 +++++++++++--------- gsa/src/web/pages/users/dialog.js | 8 ++----- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/gsa/src/web/pages/ldap/__tests__/dialog.js b/gsa/src/web/pages/ldap/__tests__/dialog.js index 517b70c12d..ceac37fef0 100644 --- a/gsa/src/web/pages/ldap/__tests__/dialog.js +++ b/gsa/src/web/pages/ldap/__tests__/dialog.js @@ -31,7 +31,7 @@ describe('Ldap dialog component tests', () => { const {baseElement} = render( { const {getByTestId} = render( { fireEvent.click(checkBox); expect(handleSave).toHaveBeenCalledWith({ authdn: 'foo', - enable: 1, + enable: true, ldaphost: 'bar', }); }); @@ -74,7 +74,7 @@ describe('Ldap dialog component tests', () => { const {getByTestId} = render( { const {getByTestId} = render( { expect(handleSave).toHaveBeenCalledWith({ authdn: 'lorem', - enable: 0, + enable: false, ldaphost: 'ipsum', }); }); diff --git a/gsa/src/web/pages/ldap/dialog.js b/gsa/src/web/pages/ldap/dialog.js index 71f6437693..ba126049cd 100644 --- a/gsa/src/web/pages/ldap/dialog.js +++ b/gsa/src/web/pages/ldap/dialog.js @@ -21,8 +21,6 @@ import React from 'react'; import _ from 'gmp/locale'; -import {YES_VALUE, NO_VALUE} from 'gmp/parser'; - import PropTypes from 'web/utils/proptypes'; import SaveDialog from 'web/components/dialog/savedialog'; @@ -34,13 +32,18 @@ import TextField from 'web/components/form/textfield'; import Layout from 'web/components/layout/layout'; -const LdapDialog = ({authdn, enable, ldaphost, onClose, onSave}) => { +const LdapDialog = ({ + authdn = '', + enable = false, + ldaphost = '', + onClose, + onSave, +}) => { const uncontrolledValues = { authdn, enable, ldaphost, }; - return ( { @@ -91,9 +94,9 @@ const LdapDialog = ({authdn, enable, ldaphost, onClose, onSave}) => { }; LdapDialog.propTypes = { - authdn: PropTypes.string.isRequired, - enable: PropTypes.number.isRequired, - ldaphost: PropTypes.string.isRequired, + authdn: PropTypes.string, + enable: PropTypes.bool, + ldaphost: PropTypes.string, onClose: PropTypes.func.isRequired, onSave: PropTypes.func.isRequired, }; diff --git a/gsa/src/web/pages/radius/__tests__/dialog.js b/gsa/src/web/pages/radius/__tests__/dialog.js index f1f8a813bd..c4a4800fab 100644 --- a/gsa/src/web/pages/radius/__tests__/dialog.js +++ b/gsa/src/web/pages/radius/__tests__/dialog.js @@ -29,7 +29,7 @@ describe('RADIUS dialog component tests', () => { const {baseElement} = render( { const {getByTestId} = render( { const checkBox = getByTestId('dialog-save-button'); fireEvent.click(checkBox); expect(handleSave).toHaveBeenCalledWith({ - enable: 1, + enable: true, radiushost: 'foo', radiuskey: 'bar', }); @@ -69,7 +69,7 @@ describe('RADIUS dialog component tests', () => { const {getByTestId} = render( { const {getByTestId} = render( { expect(handleSave).toHaveBeenCalledWith({ radiushost: 'lorem', - enable: 0, + enable: false, radiuskey: 'ipsum', }); }); diff --git a/gsa/src/web/pages/radius/dialog.js b/gsa/src/web/pages/radius/dialog.js index 80d5fb257a..d73d61e543 100644 --- a/gsa/src/web/pages/radius/dialog.js +++ b/gsa/src/web/pages/radius/dialog.js @@ -21,8 +21,6 @@ import React from 'react'; import _ from 'gmp/locale'; -import {YES_VALUE, NO_VALUE} from 'gmp/parser'; - import PropTypes from 'web/utils/proptypes'; import SaveDialog from 'web/components/dialog/savedialog'; @@ -34,13 +32,18 @@ import TextField from 'web/components/form/textfield'; import Layout from 'web/components/layout/layout'; -const RadiusDialog = ({enable, radiushost, radiuskey, onClose, onSave}) => { +const RadiusDialog = ({ + enable = false, + radiushost = '', + radiuskey = '', + onClose, + onSave, +}) => { const uncontrolledValues = { enable, radiushost, radiuskey, }; - return ( { @@ -85,9 +88,9 @@ const RadiusDialog = ({enable, radiushost, radiuskey, onClose, onSave}) => { }; RadiusDialog.propTypes = { - enable: PropTypes.number.isRequired, - radiushost: PropTypes.string.isRequired, - radiuskey: PropTypes.string.isRequired, + enable: PropTypes.bool, + radiushost: PropTypes.string, + radiuskey: PropTypes.string, onClose: PropTypes.func.isRequired, onSave: PropTypes.func.isRequired, }; diff --git a/gsa/src/web/pages/users/dialog.js b/gsa/src/web/pages/users/dialog.js index 5d2fab98d9..84c466e48a 100644 --- a/gsa/src/web/pages/users/dialog.js +++ b/gsa/src/web/pages/users/dialog.js @@ -21,8 +21,6 @@ import React from 'react'; import _ from 'gmp/locale'; -import {YES_VALUE} from 'gmp/parser'; - import {isDefined} from 'gmp/utils/identity'; import {map} from 'gmp/utils/array'; @@ -148,10 +146,8 @@ class Dialog extends React.Component { value: group.id, })); - const hasLdapEnabled = - settings.get('method:ldap_connect').enable === YES_VALUE; - const hasRadiusEnabled = - settings.get('method:radius_connect').enable === YES_VALUE; + const hasLdapEnabled = settings.get('method:ldap_connect').enabled; + const hasRadiusEnabled = settings.get('method:radius_connect').enabled; return ( Date: Tue, 4 Jun 2019 15:46:49 +0200 Subject: [PATCH 08/10] Improve input field layout at Radius dialog Adjust textfield sizes at Radius dialog. --- .../web/pages/radius/__tests__/__snapshots__/dialog.js.snap | 3 ++- gsa/src/web/pages/radius/dialog.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gsa/src/web/pages/radius/__tests__/__snapshots__/dialog.js.snap b/gsa/src/web/pages/radius/__tests__/__snapshots__/dialog.js.snap index 17b4c448c1..a7ba9c9bf1 100644 --- a/gsa/src/web/pages/radius/__tests__/__snapshots__/dialog.js.snap +++ b/gsa/src/web/pages/radius/__tests__/__snapshots__/dialog.js.snap @@ -573,6 +573,7 @@ exports[`RADIUS dialog component tests should render dialog 1`] = ` class="c20 c21" data-testid="radiushost-textfield" name="radiushost" + size="50" type="text" value="foo" /> @@ -596,7 +597,7 @@ exports[`RADIUS dialog component tests should render dialog 1`] = ` class="c20 c21" data-testid="radiuskey-textfield" name="radiuskey" - size="30" + size="50" type="password" value="bar" /> diff --git a/gsa/src/web/pages/radius/dialog.js b/gsa/src/web/pages/radius/dialog.js index d73d61e543..2040e17a9e 100644 --- a/gsa/src/web/pages/radius/dialog.js +++ b/gsa/src/web/pages/radius/dialog.js @@ -68,6 +68,7 @@ const RadiusDialog = ({ @@ -76,8 +77,8 @@ const RadiusDialog = ({ From ac7454bd6726af2e3d74728b3bc29cc39ea1cef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 4 Jun 2019 15:48:52 +0200 Subject: [PATCH 09/10] Update Radius and LDAP pages Simplify the code, use enabled instead of enable variable from settings, check if ldap and radius are enabled in gvm-libs and display text if they are disabled because of missing support in gvm-libs. --- gsa/src/web/pages/ldap/ldappage.js | 157 +++++++++++++------------ gsa/src/web/pages/radius/radiuspage.js | 109 +++++++++-------- 2 files changed, 140 insertions(+), 126 deletions(-) diff --git a/gsa/src/web/pages/ldap/ldappage.js b/gsa/src/web/pages/ldap/ldappage.js index 48bd8818d3..34f7856f0c 100644 --- a/gsa/src/web/pages/ldap/ldappage.js +++ b/gsa/src/web/pages/ldap/ldappage.js @@ -71,42 +71,43 @@ class LdapAuthentication extends React.Component { super(...args); this.state = { - authdn: '', - ldaphost: '', - enable: '', - certificateInfo: {}, - loading: 'true', + hasLdapSupport: true, + loading: true, + initial: true, dialogVisible: false, }; - this.getLdapAuth = this.getLdapAuth.bind(this); this.handleSaveSettings = this.handleSaveSettings.bind(this); - this.handleValueChange = this.handleValueChange.bind(this); this.closeDialog = this.closeDialog.bind(this); this.openDialog = this.openDialog.bind(this); } componentDidMount() { - this.load(); + this.loadLdapAuthSettings(); } - load() { - this.getLdapAuth().then(this.setState({loading: false})); - } - - getLdapAuth() { + loadLdapAuthSettings() { const {gmp} = this.props; - const authData = gmp.user.currentAuthSettings().then(response => { - const data = response.data.get('method:ldap_connect'); - const {authdn, certificateInfo, enable, ldaphost} = data; + + this.setState({loading: true}); + + return gmp.user.currentAuthSettings().then(response => { + const {data: settings} = response; + // ldap support is enabled in gvm-libs + const hasLdapSupport = settings.has('method:ldap_connect'); + const {authdn, certificateInfo, enabled, ldaphost} = settings.get( + 'method:ldap_connect', + ); this.setState({ + hasLdapSupport, authdn, certificateInfo, - enable, + enabled, ldaphost, + loading: false, + initial: false, }); }); - return authData; } handleInteraction() { @@ -116,27 +117,22 @@ class LdapAuthentication extends React.Component { } } - handleSaveSettings(state) { - const {authdn, certificate, enable, ldaphost} = state; - - const data = { - authdn, - certificate, - enable, - ldaphost, - }; + handleSaveSettings({authdn, certificate, enable, ldaphost}) { const {gmp} = this.props; this.handleInteraction(); - return gmp.auth.saveLdap(data).then(() => { - this.getLdapAuth(); - this.setState({dialogVisible: false}); - }); - } - - handleValueChange(value, name) { - this.setState({[name]: value}); + return gmp.auth + .saveLdap({ + authdn, + certificate, + enable, + ldaphost, + }) + .then(() => { + this.loadLdapAuthSettings(); + this.setState({dialogVisible: false}); + }); } openDialog() { @@ -148,68 +144,75 @@ class LdapAuthentication extends React.Component { } render() { - const {loading} = this.state; - if (loading) { + const {loading, initial} = this.state; + if (loading && initial) { return ; } - const { authdn, certificateInfo = {}, dialogVisible, - enable, + enabled, + hasLdapSupport, ldaphost, } = this.state; return ( - + {hasLdapSupport && ( + + )}
} title={_('LDAP per-User Authentication')} /> - - - - - - - - {_('Enabled')} - {renderYesNo(enable)} - - - {_('LDAP Host')} - {ldaphost} - - - {_('Auth. DN')} - {authdn} - - - {_('Activation')} - {certificateInfo.activation_time} - - - {_('Expiration')} - {certificateInfo.expiration_time} - - - {_('MD5 Fingerprint')} - {certificateInfo.md5_fingerprint} - - - {_('Issued by')} - {certificateInfo.issuer} - - -
+ {hasLdapSupport ? ( + + + + + + + + {_('Enabled')} + {renderYesNo(enabled)} + + + {_('LDAP Host')} + {ldaphost} + + + {_('Auth. DN')} + {authdn} + + + {_('Activation')} + {certificateInfo.activation_time} + + + {_('Expiration')} + {certificateInfo.expiration_time} + + + {_('MD5 Fingerprint')} + {certificateInfo.md5_fingerprint} + + + {_('Issued by')} + {certificateInfo.issuer} + + +
+ ) : ( +

{_('Support for LDAP is not available.')}

+ )} + {dialogVisible && ( { - const data = response.data.get('method:radius_connect'); - const {enable, radiushost, radiuskey} = data; + const {data: settings} = response; + // radius support is enabled in gvm-libs + const hasRadiusSupport = settings.has('method:radius_connect'); + const {enabled, radiushost, radiuskey} = settings.get( + 'method:radius_connect', + ); this.setState({ - enable, + hasRadiusSupport, + enabled, radiushost, radiuskey, + loading: false, + initial: false, }); }); return authData; @@ -113,23 +114,21 @@ class RadiusAuthentication extends React.Component { } } - handleSaveSettings(state) { - const {enable, radiushost, radiuskey} = state; - - const data = { - enable, - radiushost, - radiuskey, - }; - + handleSaveSettings({enable, radiushost, radiuskey}) { const {gmp} = this.props; this.handleInteraction(); - return gmp.auth.saveRadius(data).then(() => { - this.getRadiusAuth(); - this.setState({dialogVisible: false}); - }); + return gmp.auth + .saveRadius({ + enable, + radiushost, + radiuskey, + }) + .then(() => { + this.loadRadiusAuthSettings(); + this.setState({dialogVisible: false}); + }); } openDialog() { @@ -146,40 +145,52 @@ class RadiusAuthentication extends React.Component { return ; } - const {dialogVisible, enable, radiushost, radiuskey} = this.state; + const { + hasRadiusSupport, + dialogVisible, + enabled, + radiushost, + radiuskey, + } = this.state; return ( - + {hasRadiusSupport && ( + + )}
} title={_('RADIUS Authentication')} /> - - - - - - - - {_('Enabled')} - {renderYesNo(enable)} - - - {_('RADIUS Host')} - {radiushost} - - - {_('Secret Key')} - ******** - - -
+ {hasRadiusSupport ? ( + + + + + + + + {_('Enabled')} + {renderYesNo(enabled)} + + + {_('RADIUS Host')} + {radiushost} + + + {_('Secret Key')} + ******** + + +
+ ) : ( +

{_('Support for Radius is not available.')}

+ )} {dialogVisible && ( Date: Tue, 4 Jun 2019 15:55:26 +0200 Subject: [PATCH 10/10] Add changelog entry for ldap/radius settings changes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c074951cb5..bf763066a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Cleanup get_report function in gsad [#1263](https://github.com/greenbone/gsa/pull/1263) ### Fixed +- Display text if gvm-libs is build without LDAP and/or Radius support [#1437](https://github.com/greenbone/gsa/pull/1437) - Fix sending related resources in permission.create() [#1432](https://github.com/greenbone/gsa/pull/1432) - Don't allow bulk tagging vulnerabilities [#1429](https://github.com/greenbone/gsa/pull/1429) - Fix "given type was invalid" error for saving filters [#1428](https://github.com/greenbone/gsa/pull/1428)