From 4bb37e9975baceb2f3257600f7ccb3f3bbc0428b Mon Sep 17 00:00:00 2001 From: Steffen Waterkamp Date: Mon, 16 Sep 2019 17:46:42 +0200 Subject: [PATCH 1/4] Introduce TLS certificate filter type and default filter to GSA Needs [gvmd/750](https://github.com/greenbone/gvmd/pull/750) to work --- gsa/src/gmp/commands/users.js | 9 ++++++++- gsa/src/web/pages/filters/component.js | 1 + gsa/src/web/pages/usersettings/dialog.js | 4 ++++ gsa/src/web/pages/usersettings/filterpart.js | 13 +++++++++++++ gsa/src/web/pages/usersettings/usersettingspage.js | 13 +++++++++++++ 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/gsa/src/gmp/commands/users.js b/gsa/src/gmp/commands/users.js index 2e2d68aac1..b264336d2a 100644 --- a/gsa/src/gmp/commands/users.js +++ b/gsa/src/gmp/commands/users.js @@ -77,6 +77,7 @@ export const DEFAULT_FILTER_SETTINGS = { target: '236e2e41-9771-4e7a-8124-c432045985e0', task: '1c981851-8244-466c-92c4-865ffe05e721', ticket: '801544de-f06d-4377-bb77-bbb23369bad4', + tlscertificate: '34a176c1-0278-4c29-b84d-3d72117b2169', user: 'a33635be-7263-4549-bd80-c04d2dba89b4', vulnerability: '17c9d269-95e7-4bfa-b1b2-bc106a2175c7', }; @@ -84,6 +85,9 @@ export const DEFAULT_FILTER_SETTINGS = { const saveDefaultFilterSettingId = entityType => `settings_filter:${DEFAULT_FILTER_SETTINGS[entityType]}`; +export const transformSettingName = name => + name.toLowerCase().replace(/ |-/g, ''); + export class UserCommand extends EntityCommand { constructor(http) { super(http, 'user', User); @@ -151,7 +155,7 @@ export class UserCommand extends EntityCommand { const {data} = response; forEach(data.get_settings.get_settings_response.setting, setting => { // set setting keys to lowercase and remove '-' - const keyName = setting.name.toLowerCase().replace(/ |-/g, ''); + const keyName = transformSettingName(setting.name); settings[keyName] = new Setting(setting); }); return response.setData(settings); @@ -324,6 +328,9 @@ export class UserCommand extends EntityCommand { [saveDefaultFilterSettingId('target')]: data.targetsFilter, [saveDefaultFilterSettingId('task')]: data.tasksFilter, [saveDefaultFilterSettingId('ticket')]: data.ticketsFilter, + [saveDefaultFilterSettingId( + 'tlscertificate', + )]: data.tlsCertificatesFilter, [saveDefaultFilterSettingId('user')]: data.usersFilter, [saveDefaultFilterSettingId('vulnerability')]: data.vulnerabilitiesFilter, [saveDefaultFilterSettingId('cpe')]: data.cpeFilter, diff --git a/gsa/src/web/pages/filters/component.js b/gsa/src/web/pages/filters/component.js index 21341561e8..7d0f282fda 100644 --- a/gsa/src/web/pages/filters/component.js +++ b/gsa/src/web/pages/filters/component.js @@ -55,6 +55,7 @@ const FILTER_OPTIONS = [ ['target', _l('Target')], ['task', _l('Task')], ['ticket', _l('Ticket')], + ['tls_certificate', _l('TLS Certificate')], ['user', _l('User')], ['vulnerability', _l('Vulnerability')], ]; diff --git a/gsa/src/web/pages/usersettings/dialog.js b/gsa/src/web/pages/usersettings/dialog.js index 599ab2a515..d66d43bf20 100644 --- a/gsa/src/web/pages/usersettings/dialog.js +++ b/gsa/src/web/pages/usersettings/dialog.js @@ -103,6 +103,7 @@ let UserSettingsDialog = ({ targetsFilter, tasksFilter, ticketsFilter, + tlsCertificatesFilter, usersFilter, vulnerabilitiesFilter, cpeFilter, @@ -165,6 +166,7 @@ let UserSettingsDialog = ({ targetsFilter, tasksFilter, ticketsFilter, + tlsCertificatesFilter, usersFilter, vulnerabilitiesFilter, cpeFilter, @@ -270,6 +272,7 @@ let UserSettingsDialog = ({ targetsFilter={values.targetsFilter} tasksFilter={values.tasksFilter} ticketsFilter={values.ticketsFilter} + tlsCertificatesFilter={values.tlsCertificatesFilter} usersFilter={values.usersFilter} vulnerabilitiesFilter={values.vulnerabilitiesFilter} cpeFilter={values.cpeFilter} @@ -357,6 +360,7 @@ UserSettingsDialog.propTypes = { tasksFilter: PropTypes.string, ticketsFilter: PropTypes.string, timezone: PropTypes.string, + tlsCertificatesFilter: PropTypes.string, userInterfaceLanguage: PropTypes.string, usersFilter: PropTypes.string, vulnerabilitiesFilter: PropTypes.string, diff --git a/gsa/src/web/pages/usersettings/filterpart.js b/gsa/src/web/pages/usersettings/filterpart.js index c1be34f972..1f7709bd2e 100644 --- a/gsa/src/web/pages/usersettings/filterpart.js +++ b/gsa/src/web/pages/usersettings/filterpart.js @@ -54,6 +54,7 @@ const FilterPart = ({ targetsFilter, tasksFilter, ticketsFilter, + tlsCertificatesFilter, usersFilter, vulnerabilitiesFilter, cveFilter, @@ -292,6 +293,17 @@ const FilterPart = ({ onChange={onChange} /> + + + { const targetsFilter = userDefaultFilterSelector.getFilter('target'); const tasksFilter = userDefaultFilterSelector.getFilter('task'); const ticketsFilter = userDefaultFilterSelector.getFilter('ticket'); + const tlsCertificatesFilter = userDefaultFilterSelector.getFilter( + 'tlscertificate', + ); const usersFilter = userDefaultFilterSelector.getFilter('user'); const vulnerabilitiesFilter = userDefaultFilterSelector.getFilter( 'vulnerability', @@ -1109,6 +1120,7 @@ const mapStateToProps = rootState => { targetsFilter, tasksFilter, ticketsFilter, + tlsCertificatesFilter, usersFilter, vulnerabilitiesFilter, cpeFilter, @@ -1150,6 +1162,7 @@ const mapDispatchToProps = (dispatch, {gmp}) => ({ dispatch(loadUserSettingsDefaultFilter(gmp)('target')), dispatch(loadUserSettingsDefaultFilter(gmp)('task')), dispatch(loadUserSettingsDefaultFilter(gmp)('ticket')), + dispatch(loadUserSettingsDefaultFilter(gmp)('tlscertificate')), dispatch(loadUserSettingsDefaultFilter(gmp)('user')), dispatch(loadUserSettingsDefaultFilter(gmp)('vulnerability')), dispatch(loadUserSettingsDefaultFilter(gmp)('cpe')), From 16972baaac200f9ea02c23db687b37fb8fdf78cc Mon Sep 17 00:00:00 2001 From: Steffen Waterkamp Date: Mon, 16 Sep 2019 17:58:45 +0200 Subject: [PATCH 2/4] Add test for transformSettingName() --- gsa/src/gmp/commands/__tests__/user.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gsa/src/gmp/commands/__tests__/user.js b/gsa/src/gmp/commands/__tests__/user.js index 23dad79f69..3ef3e0724f 100644 --- a/gsa/src/gmp/commands/__tests__/user.js +++ b/gsa/src/gmp/commands/__tests__/user.js @@ -16,7 +16,7 @@ * 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 {UserCommand, transformSettingName} from '../users'; import {createResponse, createHttp} from '../testing'; describe('UserCommand tests', () => { @@ -78,3 +78,16 @@ describe('UserCommand tests', () => { }); }); }); + +describe('UserCommand transformSettingName() function tests', () => { + test('should transform string to lower case and remove -', () => { + const str1 = 'foo'; + const str2 = 'fooBar'; + const str3 = 'foo-bar'; + const str4 = 'foo-Bar'; + expect(transformSettingName(str1)).toEqual('foo'); + expect(transformSettingName(str2)).toEqual('foobar'); + expect(transformSettingName(str3)).toEqual('foobar'); + expect(transformSettingName(str4)).toEqual('foobar'); + }); +}); From dddd034dc9214be93c6c5b017e6bbac3a0939234 Mon Sep 17 00:00:00 2001 From: Steffen Waterkamp Date: Mon, 16 Sep 2019 18:00:52 +0200 Subject: [PATCH 3/4] Update Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df977e5eef..7b248df415 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Added +- Added TLS certificate filter type [#1630](https://github.com/greenbone/gsa/pull/1630) - Added change method to Field and TextArea component, removed withChangeHandler [#1625](https://github.com/greenbone/gsa/pull/1625) - Added custom page title to all pages [#1623](https://github.com/greenbone/gsa/pull/1623/files) - Allow to disable reload timers [#1619](https://github.com/greenbone/gsa/pull/1619) From 711d1d222cfbded157fa6d8e989b0e7687cec9f0 Mon Sep 17 00:00:00 2001 From: Steffen Waterkamp Date: Tue, 17 Sep 2019 09:54:04 +0200 Subject: [PATCH 4/4] Don't set createFilter for TLS certificate entities page --- gsa/src/web/pages/tlscertificates/listpage.js | 1 - 1 file changed, 1 deletion(-) diff --git a/gsa/src/web/pages/tlscertificates/listpage.js b/gsa/src/web/pages/tlscertificates/listpage.js index 2f66147747..c3f06fa117 100644 --- a/gsa/src/web/pages/tlscertificates/listpage.js +++ b/gsa/src/web/pages/tlscertificates/listpage.js @@ -78,7 +78,6 @@ const Page = ({ (