From 65c0579f4030fdb8c2cfa75c1d9187174a6fd32a Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 20 Oct 2023 11:10:44 +0200 Subject: [PATCH 1/8] Remove: Removed the logic for client certificates credential type. This credential type was once used for (custom) OSP scanners, a functionality that was removed with GOS 22.04.0. --- src/gmp/models/credential.js | 2 -- src/web/pages/credentials/details.js | 11 ++++------- src/web/pages/credentials/dialog.js | 15 ++------------- src/web/pages/credentials/downloadicon.js | 8 -------- src/web/pages/scanners/component.js | 8 -------- src/web/pages/scanners/detailspage.js | 7 ++++++- src/web/pages/scanners/dialog.js | 21 +++------------------ 7 files changed, 15 insertions(+), 57 deletions(-) diff --git a/src/gmp/models/credential.js b/src/gmp/models/credential.js index 7ff443ebe6..738a8ed44b 100644 --- a/src/gmp/models/credential.js +++ b/src/gmp/models/credential.js @@ -26,7 +26,6 @@ import {parseYesNo, NO_VALUE, parseDate} from 'gmp/parser'; export const USERNAME_PASSWORD_CREDENTIAL_TYPE = 'up'; export const USERNAME_SSH_KEY_CREDENTIAL_TYPE = 'usk'; -export const CLIENT_CERTIFICATE_CREDENTIAL_TYPE = 'cc'; export const SNMP_CREDENTIAL_TYPE = 'snmp'; export const SMIME_CREDENTIAL_TYPE = 'smime'; export const PGP_CREDENTIAL_TYPE = 'pgp'; @@ -55,7 +54,6 @@ export const VFIRE_CREDENTIAL_TYPES = [USERNAME_PASSWORD_CREDENTIAL_TYPE]; export const ALL_CREDENTIAL_TYPES = [ USERNAME_PASSWORD_CREDENTIAL_TYPE, USERNAME_SSH_KEY_CREDENTIAL_TYPE, - CLIENT_CERTIFICATE_CREDENTIAL_TYPE, SNMP_CREDENTIAL_TYPE, SMIME_CREDENTIAL_TYPE, PGP_CREDENTIAL_TYPE, diff --git a/src/web/pages/credentials/details.js b/src/web/pages/credentials/details.js index 70b1330772..dd30406ff8 100644 --- a/src/web/pages/credentials/details.js +++ b/src/web/pages/credentials/details.js @@ -20,7 +20,6 @@ import React from 'react'; import _ from 'gmp/locale'; import { - CLIENT_CERTIFICATE_CREDENTIAL_TYPE, SNMP_CREDENTIAL_TYPE, SNMP_PRIVACY_ALOGRITHM_NONE, getCredentialTypeName, @@ -86,12 +85,10 @@ const CredentialDetails = ({entity}) => { - {credential_type !== CLIENT_CERTIFICATE_CREDENTIAL_TYPE && ( - - {_('Login')} - {login} - - )} + + - {_('Login')}-{' '} + {login}-{' '} + {credential_type === SNMP_CREDENTIAL_TYPE && ( {_('Auth Algorithm')} diff --git a/src/web/pages/credentials/dialog.js b/src/web/pages/credentials/dialog.js index c509f52106..2749147035 100644 --- a/src/web/pages/credentials/dialog.js +++ b/src/web/pages/credentials/dialog.js @@ -26,7 +26,6 @@ import {isDefined} from 'gmp/utils/identity'; import {first, map} from 'gmp/utils/array'; import { - CLIENT_CERTIFICATE_CREDENTIAL_TYPE, SNMP_CREDENTIAL_TYPE, USERNAME_PASSWORD_CREDENTIAL_TYPE, USERNAME_SSH_KEY_CREDENTIAL_TYPE, @@ -332,9 +331,7 @@ class CredentialsDialog extends React.Component { )} - {(state.credential_type === USERNAME_SSH_KEY_CREDENTIAL_TYPE || - state.credential_type === - CLIENT_CERTIFICATE_CREDENTIAL_TYPE) && ( + {state.credential_type === USERNAME_SSH_KEY_CREDENTIAL_TYPE && ( {is_edit && ( @@ -381,15 +378,7 @@ class CredentialsDialog extends React.Component { )} - {state.credential_type === CLIENT_CERTIFICATE_CREDENTIAL_TYPE && ( - - - - )} - - {(state.credential_type === USERNAME_SSH_KEY_CREDENTIAL_TYPE || - state.credential_type === - CLIENT_CERTIFICATE_CREDENTIAL_TYPE) && ( + {state.credential_type === USERNAME_SSH_KEY_CREDENTIAL_TYPE && ( diff --git a/src/web/pages/credentials/downloadicon.js b/src/web/pages/credentials/downloadicon.js index 52893226ea..59c93c127f 100644 --- a/src/web/pages/credentials/downloadicon.js +++ b/src/web/pages/credentials/downloadicon.js @@ -22,7 +22,6 @@ import _ from 'gmp/locale'; import { USERNAME_PASSWORD_CREDENTIAL_TYPE, USERNAME_SSH_KEY_CREDENTIAL_TYPE, - CLIENT_CERTIFICATE_CREDENTIAL_TYPE, } from 'gmp/models/credential'; import IconDivider from 'web/components/layout/icondivider'; @@ -66,13 +65,6 @@ const CredentialDownloadIcon = ({credential, onDownload}) => { onClick={cred => onDownload(cred, 'exe')} /> )} - {type === CLIENT_CERTIFICATE_CREDENTIAL_TYPE && ( - onDownload(cred, 'pem')} - /> - )} ); }; diff --git a/src/web/pages/scanners/component.js b/src/web/pages/scanners/component.js index 4a1f65b760..4ef7c37770 100644 --- a/src/web/pages/scanners/component.js +++ b/src/web/pages/scanners/component.js @@ -25,8 +25,6 @@ import {isDefined} from 'gmp/utils/identity'; import {shorten} from 'gmp/utils/string'; import {hasId} from 'gmp/utils/id'; -import {CLIENT_CERTIFICATE_CREDENTIAL_TYPE} from 'gmp/models/credential'; - import {renewSessionTimeout} from 'web/store/usersettings/actions'; import {loadUserSettingDefaults} from 'web/store/usersettings/defaults/actions'; import {getUserSettingsDefaults} from 'web/store/usersettings/defaults/selectors'; @@ -134,12 +132,6 @@ class ScannerComponent extends React.Component { openCredentialsDialog() { this.handleInteraction(); - - this.setState({ - base: CLIENT_CERTIFICATE_CREDENTIAL_TYPE, - credentialDialogVisible: true, - credentialTypes: [CLIENT_CERTIFICATE_CREDENTIAL_TYPE], - }); } closeCredentialsDialog() { diff --git a/src/web/pages/scanners/detailspage.js b/src/web/pages/scanners/detailspage.js index 0661033edc..70ef4500e3 100644 --- a/src/web/pages/scanners/detailspage.js +++ b/src/web/pages/scanners/detailspage.js @@ -68,6 +68,8 @@ import PropTypes from 'web/utils/proptypes'; import ScannerComponent from './component'; import ScannerDetails from './details'; +import useGmp from 'web/utils/useGmp'; + const ToolBarIcons = ({ entity, onScannerCertificateDownloadClick, @@ -79,6 +81,7 @@ const ToolBarIcons = ({ onScannerEditClick, onScannerVerifyClick, }) => { + const gmp = useGmp(); return ( @@ -90,7 +93,9 @@ const ToolBarIcons = ({ - + {gmp.settings.enableGreenboneSensor && ( + + )} { - return credential.credential_type === CLIENT_CERTIFICATE_CREDENTIAL_TYPE; -}; - const render_certificate_info = (info, tz) => { if (!isDefined(info)) { return null; @@ -125,10 +119,7 @@ const ScannerDialog = ({ const handleTypeChange = (value, name) => { if (onScannerTypeChange) { value = parseInt(value); - const scan_credentials = filter( - credentials, - client_cert_credentials_filter, - ); + const scan_credentials = filter(credentials); onScannerTypeChange(value, name); onScannerTypeChange( @@ -167,15 +158,9 @@ const ScannerDialog = ({ value: scannerType, })); - const scanner_credentials = filter( - credentials, - client_cert_credentials_filter, - ); + const scanner_credentials = filter(credentials); const isInUse = isDefined(scanner) && scanner.isInUse(); - const show_cred_info = - isDefined(scanner) && - isDefined(scanner.credential) && - scanner.credential.credential_type === CLIENT_CERTIFICATE_CREDENTIAL_TYPE; + const show_cred_info = isDefined(scanner) && isDefined(scanner.credential); const isGreenboneSensorType = type === GREENBONE_SENSOR_SCANNER_TYPE; From cce5c37f4a49448cefff5f8ce608ca78436e7cd6 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 20 Oct 2023 12:27:56 +0200 Subject: [PATCH 2/8] Small amendment. --- src/web/pages/credentials/details.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/web/pages/credentials/details.js b/src/web/pages/credentials/details.js index dd30406ff8..118015d4fc 100644 --- a/src/web/pages/credentials/details.js +++ b/src/web/pages/credentials/details.js @@ -86,8 +86,7 @@ const CredentialDetails = ({entity}) => { - - {_('Login')}-{' '} - {login}-{' '} + {_('Login')}- {login}-{' '} {credential_type === SNMP_CREDENTIAL_TYPE && ( From 76bdb4c567c3770f353789f07b1ad7e8b9137d65 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 20 Oct 2023 14:10:23 +0200 Subject: [PATCH 3/8] Removed tests for removed client certificate logic from test suite. --- src/gmp/models/__tests__/credential.js | 12 ------ src/web/pages/credentials/__tests__/dialog.js | 43 ++----------------- .../pages/credentials/__tests__/listpage.js | 4 -- 3 files changed, 4 insertions(+), 55 deletions(-) diff --git a/src/gmp/models/__tests__/credential.js b/src/gmp/models/__tests__/credential.js index e008c0258b..37a7dad2a7 100644 --- a/src/gmp/models/__tests__/credential.js +++ b/src/gmp/models/__tests__/credential.js @@ -23,7 +23,6 @@ import {setLocale} from 'gmp/locale/lang'; import Model from 'gmp/model'; import Credential, { - CLIENT_CERTIFICATE_CREDENTIAL_TYPE, SNMP_CREDENTIAL_TYPE, USERNAME_PASSWORD_CREDENTIAL_TYPE, USERNAME_SSH_KEY_CREDENTIAL_TYPE, @@ -47,15 +46,11 @@ const USERNAME_PASSWORD_CREDENTIAL = Credential.fromElement({ const USERNAME_SSH_KEY_CREDENTIAL = Credential.fromElement({ type: USERNAME_SSH_KEY_CREDENTIAL_TYPE, }); -const CLIENT_CERTIFICATE_CREDENTIAL = Credential.fromElement({ - type: CLIENT_CERTIFICATE_CREDENTIAL_TYPE, -}); const SNMP_CREDENTIAL = Credential.fromElement({type: SNMP_CREDENTIAL_TYPE}); const PGP_CREDENTIAL = Credential.fromElement({type: PGP_CREDENTIAL_TYPE}); const SMIME_CREDENTIAL = Credential.fromElement({type: SMIME_CREDENTIAL_TYPE}); const createAllCredentials = () => [ - CLIENT_CERTIFICATE_CREDENTIAL, USERNAME_PASSWORD_CREDENTIAL, USERNAME_SSH_KEY_CREDENTIAL, SNMP_CREDENTIAL, @@ -151,7 +146,6 @@ describe('Credential Model tests', () => { describe('Credential model function tests', () => { test('ssh_credential_filter should return filter with correct true/false', () => { - expect(ssh_credential_filter(CLIENT_CERTIFICATE_CREDENTIAL)).toEqual(false); expect(ssh_credential_filter(USERNAME_SSH_KEY_CREDENTIAL)).toEqual(true); expect(ssh_credential_filter(USERNAME_PASSWORD_CREDENTIAL)).toEqual(true); }); @@ -167,9 +161,6 @@ describe('Credential model function tests', () => { }); test('snmp_credential_filter should return filter with correct true/false', () => { - expect(snmp_credential_filter(CLIENT_CERTIFICATE_CREDENTIAL)).toEqual( - false, - ); expect(snmp_credential_filter(SNMP_CREDENTIAL)).toEqual(true); }); @@ -231,9 +222,6 @@ describe('getCredentialTypeName tests', () => { expect(getCredentialTypeName(USERNAME_SSH_KEY_CREDENTIAL_TYPE)).toEqual( 'Username + SSH Key', ); - expect(getCredentialTypeName(CLIENT_CERTIFICATE_CREDENTIAL_TYPE)).toEqual( - 'Client Certificate', - ); expect(getCredentialTypeName(SNMP_CREDENTIAL_TYPE)).toEqual('SNMP'); expect(getCredentialTypeName(SMIME_CREDENTIAL_TYPE)).toEqual( 'S/MIME Certificate', diff --git a/src/web/pages/credentials/__tests__/dialog.js b/src/web/pages/credentials/__tests__/dialog.js index fbda04fabb..4f5adc5b94 100644 --- a/src/web/pages/credentials/__tests__/dialog.js +++ b/src/web/pages/credentials/__tests__/dialog.js @@ -42,14 +42,14 @@ const credential = Credential.fromElement({ creation_time: '2020-12-16T15:23:59Z', comment: 'blah', formats: {format: 'pem'}, - full_type: 'client certificate', + full_type: 'username + password', in_use: 0, login: '', modification_time: '2021-03-02T10:28:15Z', name: 'credential 1', owner: {name: 'admin'}, permissions: {permission: {name: 'Everything'}}, - type: 'cc', + type: 'up', writable: 1, }); @@ -134,7 +134,6 @@ describe('CredentialsDialog component tests', () => { expect(commentInput).toHaveAttribute('value', 'blah'); expect(formGroups[2]).toHaveTextContent('Type'); - expect(selectedValue).toHaveTextContent('Client Certificate'); const allowInsecure = getAllByName('allow_insecure'); expect(formGroups[3]).toHaveTextContent('Allow insecure use'); @@ -217,8 +216,8 @@ describe('CredentialsDialog component tests', () => { const selectItems = getAllByTestId('select-item'); - expect(selectItems.length).toBe(7); - fireEvent.click(selectItems[6]); + expect(selectItems.length).toBe(6); + fireEvent.click(selectItems[5]); expect(selectedValues[0]).toHaveTextContent('Password only'); @@ -298,40 +297,6 @@ describe('CredentialsDialog component tests', () => { expect(privateKey).toHaveAttribute('type', 'file'); }); - test('should render form fields for Client Certificate', () => { - const {render} = rendererWith({ - capabilities: true, - }); - - const {getAllByTestId, getByName} = render( - , - ); - - const selectedValues = getAllByTestId('select-selected-value'); - - expect(selectedValues[0]).toHaveTextContent('Client Certificate'); - - const formGroups = getAllByTestId('formgroup-title'); - - const password = getByName('passphrase'); - expect(formGroups[4]).toHaveTextContent('Passphrase'); - expect(password).toHaveAttribute('value', ''); - - const certificate = getByName('certificate'); - expect(formGroups[5]).toHaveTextContent('Certificate'); - expect(certificate).toHaveAttribute('type', 'file'); - - const privateKey = getByName('private_key'); - expect(formGroups[6]).toHaveTextContent('Private Key'); - expect(privateKey).toHaveAttribute('type', 'file'); - }); - test('should render form fields for SNMP', () => { const {render} = rendererWith({ capabilities: true, diff --git a/src/web/pages/credentials/__tests__/listpage.js b/src/web/pages/credentials/__tests__/listpage.js index 4236051da1..f81f04b311 100644 --- a/src/web/pages/credentials/__tests__/listpage.js +++ b/src/web/pages/credentials/__tests__/listpage.js @@ -166,7 +166,6 @@ describe('CredentialPage tests', () => { expect(row[1]).toHaveTextContent('credential 1'); expect(row[1]).toHaveTextContent('(blah)'); - expect(row[1]).toHaveTextContent('Client Certificate(cc)'); expect(row[1]).toHaveTextContent('Yes'); expect( @@ -175,9 +174,6 @@ describe('CredentialPage tests', () => { expect(screen.getAllByTitle('Edit Credential')[0]).toBeInTheDocument(); expect(screen.getAllByTitle('Clone Credential')[0]).toBeInTheDocument(); expect(screen.getAllByTitle('Export Credential')[0]).toBeInTheDocument(); - expect( - screen.getAllByTitle('Download Certificate (.pem)')[0], - ).toBeInTheDocument(); }); test('should allow to bulk action on page contents', async () => { From 96807beeb7274807dd8ea6d2c1707f82ca0fd353 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 20 Oct 2023 14:24:39 +0200 Subject: [PATCH 4/8] Small amendment for the tests. --- src/web/pages/credentials/__tests__/dialog.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/web/pages/credentials/__tests__/dialog.js b/src/web/pages/credentials/__tests__/dialog.js index 4f5adc5b94..840c861595 100644 --- a/src/web/pages/credentials/__tests__/dialog.js +++ b/src/web/pages/credentials/__tests__/dialog.js @@ -108,7 +108,7 @@ describe('CredentialsDialog component tests', () => { capabilities: true, }); - const {getAllByTestId, getByTestId, getByName, getAllByName} = render( + const {getAllByTestId, getByName, getAllByName} = render( { ); const formGroups = getAllByTestId('formgroup-title'); - const selectedValue = getByTestId('select-selected-value'); const nameInput = getByName('name'); expect(formGroups[0]).toHaveTextContent('Name'); From 5a2831394371a2936dac2594175b2f97ec54f22b Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 20 Oct 2023 17:01:30 +0200 Subject: [PATCH 5/8] Some more changes for the tests. --- .../credentials/__tests__/detailspage.js | 59 +++---------------- 1 file changed, 7 insertions(+), 52 deletions(-) diff --git a/src/web/pages/credentials/__tests__/detailspage.js b/src/web/pages/credentials/__tests__/detailspage.js index c2501a1f53..dcb5977865 100644 --- a/src/web/pages/credentials/__tests__/detailspage.js +++ b/src/web/pages/credentials/__tests__/detailspage.js @@ -76,22 +76,15 @@ const credential = Credential.fromElement({ allow_insecure: 1, creation_time: '2020-12-16T15:23:59Z', comment: 'blah', - formats: {format: 'pem'}, - full_type: 'client certificate', + full_type: 'username + password', in_use: 0, login: '', modification_time: '2021-03-02T10:28:15Z', name: 'credential 1', owner: {name: 'admin'}, permissions: {permission: {name: 'Everything'}}, - type: 'cc', + type: 'up', writable: 1, - certificate_info: { - activation_time: '2018-10-10T11:41:23.022Z', - expiration_time: '2019-10-10T11:41:23.022Z', - md5_fingerprint: 'asdf', - issuer: 'dn', - }, }); const noPermCredential = Credential.fromElement({ @@ -99,22 +92,15 @@ const noPermCredential = Credential.fromElement({ allow_insecure: 1, creation_time: '2020-12-16T15:23:59Z', comment: 'blah', - formats: {format: 'pem'}, - full_type: 'client certificate', + full_type: 'username + password', in_use: 0, login: '', modification_time: '2021-03-02T10:28:15Z', name: 'credential 1', owner: {name: 'admin'}, permissions: {permission: {name: 'get_credentials'}}, - type: 'cc', + type: 'up', writable: 1, - certificate_info: { - activation_time: '2018-10-10T11:41:23.022Z', - expiration_time: '2019-10-10T11:41:23.022Z', - md5_fingerprint: 'asdf', - issuer: 'dn', - }, }); const credentialInUse = Credential.fromElement({ @@ -122,22 +108,15 @@ const credentialInUse = Credential.fromElement({ allow_insecure: 1, creation_time: '2020-12-16T15:23:59Z', comment: 'blah', - formats: {format: 'pem'}, - full_type: 'client certificate', + full_type: 'username + password', in_use: 1, login: '', modification_time: '2021-03-02T10:28:15Z', name: 'credential 1', owner: {name: 'admin'}, permissions: {permission: {name: 'Everything'}}, - type: 'cc', + type: 'up', writable: 1, - certificate_info: { - activation_time: '2018-10-10T11:41:23.022Z', - expiration_time: '2019-10-10T11:41:23.022Z', - md5_fingerprint: 'asdf', - issuer: 'dn', - }, }); describe('Credential Detailspage tests', () => { @@ -193,24 +172,10 @@ describe('Credential Detailspage tests', () => { expect(element).toHaveTextContent('blah'); expect(element).toHaveTextContent('Type'); - expect(element).toHaveTextContent('Client Certificate(cc)'); + expect(element).toHaveTextContent('Username + Password'); expect(element).toHaveTextContent('Allow Insecure Use'); expect(element).toHaveTextContent('Yes'); - - expect(element).toHaveTextContent('Certificate'); - - expect(element).toHaveTextContent('Activation'); - expect(element).toHaveTextContent('Wed, Oct 10, 2018 1:41 PM CEST'); - - expect(element).toHaveTextContent('Expiration'); - expect(element).toHaveTextContent('Thu, Oct 10, 2019 1:41 PM CEST'); - - expect(element).toHaveTextContent('MD5 Fingerprint'); - expect(element).toHaveTextContent('asdf'); - - expect(element).toHaveTextContent('Issued By'); - expect(element).toHaveTextContent('dn'); }); test('should render user tags tab', () => { @@ -428,9 +393,6 @@ describe('Credential ToolBarIcons tests', () => { const editIcon = screen.getAllByTitle('Edit Credential'); const deleteIcon = screen.getAllByTitle('Move Credential to trashcan'); const exportIcon = screen.getAllByTitle('Export Credential as XML'); - const exportCredentialInstallerIcon = screen.getAllByTitle( - 'Download Certificate (.pem)', - ); expect(cloneIcon[0]).toBeInTheDocument(); fireEvent.click(cloneIcon[0]); @@ -447,13 +409,6 @@ describe('Credential ToolBarIcons tests', () => { expect(exportIcon[0]).toBeInTheDocument(); fireEvent.click(exportIcon[0]); expect(handleCredentialDownloadClick).toHaveBeenCalledWith(credential); - - expect(exportCredentialInstallerIcon[0]).toBeInTheDocument(); - fireEvent.click(exportCredentialInstallerIcon[0]); - expect(handleCredentialInstallerDownloadClick).toHaveBeenCalledWith( - credential, - 'pem', - ); }); test('should not call click handlers without permission', () => { From 2744f1225b244c21341d5742039f094dfc9173e8 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 27 Oct 2023 13:48:41 +0200 Subject: [PATCH 6/8] Some test improvements. --- .../credentials/__tests__/detailspage.js | 36 ++++++++++++------- src/web/pages/credentials/__tests__/dialog.js | 4 +-- .../pages/credentials/__tests__/listpage.js | 5 +-- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/web/pages/credentials/__tests__/detailspage.js b/src/web/pages/credentials/__tests__/detailspage.js index dcb5977865..2abfcd9714 100644 --- a/src/web/pages/credentials/__tests__/detailspage.js +++ b/src/web/pages/credentials/__tests__/detailspage.js @@ -76,14 +76,14 @@ const credential = Credential.fromElement({ allow_insecure: 1, creation_time: '2020-12-16T15:23:59Z', comment: 'blah', - full_type: 'username + password', + full_type: 'Username + SSH Key', in_use: 0, login: '', modification_time: '2021-03-02T10:28:15Z', name: 'credential 1', owner: {name: 'admin'}, permissions: {permission: {name: 'Everything'}}, - type: 'up', + type: 'usk', writable: 1, }); @@ -92,14 +92,14 @@ const noPermCredential = Credential.fromElement({ allow_insecure: 1, creation_time: '2020-12-16T15:23:59Z', comment: 'blah', - full_type: 'username + password', + full_type: 'Username + SSH Key', in_use: 0, login: '', modification_time: '2021-03-02T10:28:15Z', name: 'credential 1', owner: {name: 'admin'}, permissions: {permission: {name: 'get_credentials'}}, - type: 'up', + type: 'usk', writable: 1, }); @@ -108,14 +108,14 @@ const credentialInUse = Credential.fromElement({ allow_insecure: 1, creation_time: '2020-12-16T15:23:59Z', comment: 'blah', - full_type: 'username + password', + full_type: 'Username + SSH Key', in_use: 1, login: '', modification_time: '2021-03-02T10:28:15Z', name: 'credential 1', owner: {name: 'admin'}, permissions: {permission: {name: 'Everything'}}, - type: 'up', + type: 'usk', writable: 1, }); @@ -165,17 +165,19 @@ describe('Credential Detailspage tests', () => { expect(element).toHaveTextContent('Owner:admin'); const spans = baseElement.querySelectorAll('span'); - expect(spans[10]).toHaveTextContent('User Tags'); - expect(spans[12]).toHaveTextContent('Permissions'); + expect(spans[12]).toHaveTextContent('User Tags'); + expect(spans[14]).toHaveTextContent('Permissions'); expect(element).toHaveTextContent('Comment'); expect(element).toHaveTextContent('blah'); expect(element).toHaveTextContent('Type'); - expect(element).toHaveTextContent('Username + Password'); + expect(element).toHaveTextContent('Username + SSH Key'); expect(element).toHaveTextContent('Allow Insecure Use'); expect(element).toHaveTextContent('Yes'); + + expect(element).toHaveTextContent('Login'); }); test('should render user tags tab', () => { @@ -208,9 +210,9 @@ describe('Credential Detailspage tests', () => { const {baseElement} = render(); const spans = baseElement.querySelectorAll('span'); - expect(spans[10]).toHaveTextContent('User Tags'); + expect(spans[12]).toHaveTextContent('User Tags'); - fireEvent.click(spans[10]); + fireEvent.click(spans[12]); expect(baseElement).toHaveTextContent('No user tags available'); }); @@ -245,9 +247,9 @@ describe('Credential Detailspage tests', () => { const {baseElement} = render(); const spans = baseElement.querySelectorAll('span'); - expect(spans[12]).toHaveTextContent('Permissions'); + expect(spans[14]).toHaveTextContent('Permissions'); - fireEvent.click(spans[12]); + fireEvent.click(spans[14]); expect(baseElement).toHaveTextContent('No permissions available'); }); @@ -393,6 +395,7 @@ describe('Credential ToolBarIcons tests', () => { const editIcon = screen.getAllByTitle('Edit Credential'); const deleteIcon = screen.getAllByTitle('Move Credential to trashcan'); const exportIcon = screen.getAllByTitle('Export Credential as XML'); + const downloadPublicKeyIcon = screen.getAllByTitle('Download Public Key'); expect(cloneIcon[0]).toBeInTheDocument(); fireEvent.click(cloneIcon[0]); @@ -409,6 +412,13 @@ describe('Credential ToolBarIcons tests', () => { expect(exportIcon[0]).toBeInTheDocument(); fireEvent.click(exportIcon[0]); expect(handleCredentialDownloadClick).toHaveBeenCalledWith(credential); + + expect(downloadPublicKeyIcon[0]).toBeInTheDocument(); + fireEvent.click(downloadPublicKeyIcon[0]); + expect(handleCredentialInstallerDownloadClick).toHaveBeenCalledWith( + credential, + 'key', + ); }); test('should not call click handlers without permission', () => { diff --git a/src/web/pages/credentials/__tests__/dialog.js b/src/web/pages/credentials/__tests__/dialog.js index 840c861595..ce0a1d5337 100644 --- a/src/web/pages/credentials/__tests__/dialog.js +++ b/src/web/pages/credentials/__tests__/dialog.js @@ -42,14 +42,14 @@ const credential = Credential.fromElement({ creation_time: '2020-12-16T15:23:59Z', comment: 'blah', formats: {format: 'pem'}, - full_type: 'username + password', + full_type: 'Username + SSH Key', in_use: 0, login: '', modification_time: '2021-03-02T10:28:15Z', name: 'credential 1', owner: {name: 'admin'}, permissions: {permission: {name: 'Everything'}}, - type: 'up', + type: 'usk', writable: 1, }); diff --git a/src/web/pages/credentials/__tests__/listpage.js b/src/web/pages/credentials/__tests__/listpage.js index f81f04b311..f89cc93b2e 100644 --- a/src/web/pages/credentials/__tests__/listpage.js +++ b/src/web/pages/credentials/__tests__/listpage.js @@ -43,14 +43,14 @@ const credential = Credential.fromElement({ creation_time: '2020-12-16T15:23:59Z', comment: 'blah', formats: {format: 'pem'}, - full_type: 'client certificate', + full_type: 'Username + SSH Key', in_use: 0, login: '', modification_time: '2021-03-02T10:28:15Z', name: 'credential 1', owner: {name: 'admin'}, permissions: {permission: {name: 'Everything'}}, - type: 'cc', + type: 'usk', writable: 1, certificate_info: { activation_time: '2018-10-10T11:41:23.022Z', @@ -174,6 +174,7 @@ describe('CredentialPage tests', () => { expect(screen.getAllByTitle('Edit Credential')[0]).toBeInTheDocument(); expect(screen.getAllByTitle('Clone Credential')[0]).toBeInTheDocument(); expect(screen.getAllByTitle('Export Credential')[0]).toBeInTheDocument(); + expect(screen.getAllByTitle('Download Public Key')[0]).toBeInTheDocument(); }); test('should allow to bulk action on page contents', async () => { From b9fa0afd6a0415735cca0c415b576c3040f0d423 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 3 Nov 2023 13:15:59 +0100 Subject: [PATCH 7/8] Some further amendments. --- src/web/pages/credentials/__tests__/dialog.js | 4 +++- .../pages/credentials/__tests__/listpage.js | 1 + src/web/pages/credentials/details.js | 3 ++- src/web/pages/scanners/dialog.js | 24 ------------------- 4 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/web/pages/credentials/__tests__/dialog.js b/src/web/pages/credentials/__tests__/dialog.js index ce0a1d5337..5a86c3566d 100644 --- a/src/web/pages/credentials/__tests__/dialog.js +++ b/src/web/pages/credentials/__tests__/dialog.js @@ -108,7 +108,7 @@ describe('CredentialsDialog component tests', () => { capabilities: true, }); - const {getAllByTestId, getByName, getAllByName} = render( + const {getAllByTestId, getByTestId, getByName, getAllByName} = render( { ); const formGroups = getAllByTestId('formgroup-title'); + const selectedValue = getByTestId('select-selected-value'); const nameInput = getByName('name'); expect(formGroups[0]).toHaveTextContent('Name'); @@ -133,6 +134,7 @@ describe('CredentialsDialog component tests', () => { expect(commentInput).toHaveAttribute('value', 'blah'); expect(formGroups[2]).toHaveTextContent('Type'); + expect(selectedValue).toHaveTextContent('Username + SSH Key'); const allowInsecure = getAllByName('allow_insecure'); expect(formGroups[3]).toHaveTextContent('Allow insecure use'); diff --git a/src/web/pages/credentials/__tests__/listpage.js b/src/web/pages/credentials/__tests__/listpage.js index f89cc93b2e..6e3a732a27 100644 --- a/src/web/pages/credentials/__tests__/listpage.js +++ b/src/web/pages/credentials/__tests__/listpage.js @@ -166,6 +166,7 @@ describe('CredentialPage tests', () => { expect(row[1]).toHaveTextContent('credential 1'); expect(row[1]).toHaveTextContent('(blah)'); + expect(row[1]).toHaveTextContent('Username + SSH Key'); expect(row[1]).toHaveTextContent('Yes'); expect( diff --git a/src/web/pages/credentials/details.js b/src/web/pages/credentials/details.js index 118015d4fc..37fcd82fe5 100644 --- a/src/web/pages/credentials/details.js +++ b/src/web/pages/credentials/details.js @@ -86,7 +86,8 @@ const CredentialDetails = ({entity}) => { - {_('Login')}- {login}-{' '} + {_('Login')} + {login} {credential_type === SNMP_CREDENTIAL_TYPE && ( diff --git a/src/web/pages/scanners/dialog.js b/src/web/pages/scanners/dialog.js index f8664898df..e45066b7ea 100644 --- a/src/web/pages/scanners/dialog.js +++ b/src/web/pages/scanners/dialog.js @@ -81,21 +81,6 @@ const mapStateToProps = rootState => ({ timezone: getTimezone(rootState), }); -const CertStatus = connect(mapStateToProps)(({info, timezone}) => { - return ( - - - - - {render_certificate_info(info, timezone)} - - ); -}); - -CertStatus.propTypes = { - info: PropTypes.object.isRequired, -}; - const ScannerDialog = ({ ca_pub, comment = '', @@ -119,13 +104,8 @@ const ScannerDialog = ({ const handleTypeChange = (value, name) => { if (onScannerTypeChange) { value = parseInt(value); - const scan_credentials = filter(credentials); onScannerTypeChange(value, name); - onScannerTypeChange( - selectSaveId(scan_credentials, credential_id), - 'credential_id', - ); } }; @@ -160,7 +140,6 @@ const ScannerDialog = ({ const scanner_credentials = filter(credentials); const isInUse = isDefined(scanner) && scanner.isInUse(); - const show_cred_info = isDefined(scanner) && isDefined(scanner.credential); const isGreenboneSensorType = type === GREENBONE_SENSOR_SCANNER_TYPE; @@ -235,9 +214,6 @@ const ScannerDialog = ({ /> - {show_cred_info && ( - - )} )} From bc6d7463785915aa1cf0b182955d32749cafd2b9 Mon Sep 17 00:00:00 2001 From: Johannes Helmold Date: Fri, 3 Nov 2023 16:03:13 +0100 Subject: [PATCH 8/8] Fixed some linter errors. --- src/web/pages/scanners/dialog.js | 33 -------------------------------- 1 file changed, 33 deletions(-) diff --git a/src/web/pages/scanners/dialog.js b/src/web/pages/scanners/dialog.js index e45066b7ea..d66809be21 100644 --- a/src/web/pages/scanners/dialog.js +++ b/src/web/pages/scanners/dialog.js @@ -18,14 +18,10 @@ import React from 'react'; -import {connect} from 'react-redux'; - import _ from 'gmp/locale'; -import {longDate} from 'gmp/locale/date'; import {filter, map} from 'gmp/utils/array'; import {hasValue, isDefined} from 'gmp/utils/identity'; -import {selectSaveId} from 'gmp/utils/id'; import {parseInt} from 'gmp/parser'; @@ -36,20 +32,15 @@ import withGmp from 'web/utils/withGmp'; import SaveDialog from 'web/components/dialog/savedialog'; -import FootNote from 'web/components/footnote/footnote'; - import FormGroup from 'web/components/form/formgroup'; import Select from 'web/components/form/select'; import TextField from 'web/components/form/textfield'; -import KeyIcon from 'web/components/icon/keyicon'; import NewIcon from 'web/components/icon/newicon'; import Divider from 'web/components/layout/divider'; import Layout from 'web/components/layout/layout'; -import {getTimezone} from 'web/store/usersettings/selectors'; - import { GREENBONE_SENSOR_SCANNER_TYPE, scannerTypeName, @@ -57,30 +48,6 @@ import { const AVAILABLE_SCANNER_TYPES = [GREENBONE_SENSOR_SCANNER_TYPE]; -const render_certificate_info = (info, tz) => { - if (!isDefined(info)) { - return null; - } - - if (info.time_status === 'expired') { - return _('Certificate currently in use expired at {{date}}', { - date: longDate(info.expirationTime, tz), - }); - } - if (info.time_status === 'inactive') { - return _('Certificate currently not valid until {{date}}', { - date: longDate(info.activationTime, tz), - }); - } - return _('Certificate in use will expire at {{date}}', { - date: longDate(info.expirationTime, tz), - }); -}; - -const mapStateToProps = rootState => ({ - timezone: getTimezone(rootState), -}); - const ScannerDialog = ({ ca_pub, comment = '',