Skip to content

Commit

Permalink
Merge pull request #1630 from swaterkamp/TlsCertFilter
Browse files Browse the repository at this point in the history
Introduce TLS certificate filter type and default filter to GSA
  • Loading branch information
swaterkamp authored Sep 17, 2019
2 parents 100200d + 711d1d2 commit 02a94da
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion gsa/src/gmp/commands/__tests__/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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');
});
});
9 changes: 8 additions & 1 deletion gsa/src/gmp/commands/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ 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',
};

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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions gsa/src/web/pages/filters/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')],
];
Expand Down
1 change: 0 additions & 1 deletion gsa/src/web/pages/tlscertificates/listpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const Page = ({
<PageTitle title={_('TLS Certificates')} />
<EntitiesPage
{...props}
createFilterType="tlscertificate"
dashboard={() => (
<TlsCertificatesDashboard
filter={filter}
Expand Down
4 changes: 4 additions & 0 deletions gsa/src/web/pages/usersettings/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ let UserSettingsDialog = ({
targetsFilter,
tasksFilter,
ticketsFilter,
tlsCertificatesFilter,
usersFilter,
vulnerabilitiesFilter,
cpeFilter,
Expand Down Expand Up @@ -165,6 +166,7 @@ let UserSettingsDialog = ({
targetsFilter,
tasksFilter,
ticketsFilter,
tlsCertificatesFilter,
usersFilter,
vulnerabilitiesFilter,
cpeFilter,
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions gsa/src/web/pages/usersettings/filterpart.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const FilterPart = ({
targetsFilter,
tasksFilter,
ticketsFilter,
tlsCertificatesFilter,
usersFilter,
vulnerabilitiesFilter,
cveFilter,
Expand Down Expand Up @@ -292,6 +293,17 @@ const FilterPart = ({
onChange={onChange}
/>
</FormGroup>
<FormGroup title={_('TLS Certificates Filter')} titleSize="3">
<Select
name="tlsCertificatesFilter"
value={tlsCertificatesFilter}
items={renderSelectItems(
filterFilters(filters, 'tls_certificate'),
UNSET_VALUE,
)}
onChange={onChange}
/>
</FormGroup>
<FormGroup title={_('Users Filter')} titleSize="3">
<Select
name="usersFilter"
Expand Down Expand Up @@ -399,6 +411,7 @@ FilterPart.propTypes = {
targetsFilter: PropTypes.string,
tasksFilter: PropTypes.string,
ticketsFilter: PropTypes.string,
tlsCertificatesFilter: PropTypes.string,
usersFilter: PropTypes.string,
vulnerabilitiesFilter: PropTypes.string,
onChange: PropTypes.func,
Expand Down
13 changes: 13 additions & 0 deletions gsa/src/web/pages/usersettings/usersettingspage.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ class UserSettings extends React.Component {
targetsFilter = {},
tasksFilter = {},
ticketsFilter = {},
tlsCertificatesFilter = {},
usersFilter = {},
vulnerabilitiesFilter = {},
cpeFilter = {},
Expand Down Expand Up @@ -701,6 +702,11 @@ class UserSettings extends React.Component {
title={_('Tickets Filter')}
type="filter"
/>
<SettingTableRow
setting={tlsCertificatesFilter}
title={_('TLS Certificates Filter')}
type="filter"
/>
<SettingTableRow
setting={usersFilter}
title={_('Users Filter')}
Expand Down Expand Up @@ -815,6 +821,7 @@ class UserSettings extends React.Component {
targetsFilter={targetsFilter.id}
tasksFilter={tasksFilter.id}
ticketsFilter={ticketsFilter.id}
tlsCertificatesFilter={tlsCertificatesFilter.id}
usersFilter={usersFilter.id}
vulnerabilitiesFilter={vulnerabilitiesFilter.id}
cpeFilter={cpeFilter.id}
Expand Down Expand Up @@ -913,6 +920,7 @@ UserSettings.propTypes = {
tasksFilter: PropTypes.object,
ticketsFilter: PropTypes.object,
timezone: PropTypes.string,
tlsCertificatesFilter: PropTypes.object,
userInterfaceLanguage: PropTypes.object,
usersFilter: PropTypes.object,
vulnerabilitiesFilter: PropTypes.object,
Expand Down Expand Up @@ -1036,6 +1044,9 @@ const mapStateToProps = rootState => {
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',
Expand Down Expand Up @@ -1109,6 +1120,7 @@ const mapStateToProps = rootState => {
targetsFilter,
tasksFilter,
ticketsFilter,
tlsCertificatesFilter,
usersFilter,
vulnerabilitiesFilter,
cpeFilter,
Expand Down Expand Up @@ -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')),
Expand Down

0 comments on commit 02a94da

Please sign in to comment.