Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug edit credentials dialog fields not disabled #4276

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gmp/models/credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const vFire_credential_filter = credential =>
export const SNMP_AUTH_ALGORITHM_MD5 = 'md5';
export const SNMP_AUTH_ALGORITHM_SHA1 = 'sha1';

export const SNMP_PRIVACY_ALOGRITHM_NONE = '';
export const SNMP_PRIVACY_ALGORITHM_NONE = '';
bjoernricks marked this conversation as resolved.
Show resolved Hide resolved
export const SNMP_PRIVACY_ALGORITHM_AES = 'aes';
export const SNMP_PRIVACY_ALGORITHM_DES = 'des';

Expand Down
106 changes: 60 additions & 46 deletions src/web/pages/credentials/__tests__/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
getSelectElement,
getSelectItemElementsForSelect,
} from 'web/components/testing';
import {rendererWith, fireEvent} from 'web/utils/testing';
import {rendererWith, fireEvent, screen, render} from 'web/utils/testing';

import CredentialsDialog from '../dialog';

Expand All @@ -30,7 +30,7 @@ beforeEach(() => {
handleErrorClose = testing.fn();
});

const credential = Credential.fromElement({
const credentialMock = Credential.fromElement({
_id: 'foo',
allow_insecure: 1,
creation_time: '2020-12-16T15:23:59Z',
Expand All @@ -49,10 +49,6 @@ const credential = Credential.fromElement({

describe('CredentialsDialog component tests', () => {
test('should render', () => {
const {render} = rendererWith({
capabilities: true,
});

const {getByName} = render(
<CredentialsDialog
types={ALL_CREDENTIAL_TYPES}
Expand Down Expand Up @@ -96,11 +92,11 @@ describe('CredentialsDialog component tests', () => {

const {getByName, getAllByName} = render(
<CredentialsDialog
allow_insecure={credential.allow_insecure}
comment={credential.comment}
credential={credential}
credential_type={credential.credential_type}
name={credential.name}
allow_insecure={credentialMock.allow_insecure}
comment={credentialMock.comment}
credential={credentialMock}
credential_type={credentialMock.credential_type}
name={credentialMock.name}
types={ALL_CREDENTIAL_TYPES}
onClose={handleClose}
onErrorClose={handleErrorClose}
Expand All @@ -125,10 +121,6 @@ describe('CredentialsDialog component tests', () => {
});

test('should allow to change text field', () => {
const {render} = rendererWith({
capabilities: true,
});

const {getByName} = render(
<CredentialsDialog
types={ALL_CREDENTIAL_TYPES}
Expand Down Expand Up @@ -156,8 +148,8 @@ describe('CredentialsDialog component tests', () => {
auth_algorithm: 'sha1',
autogenerate: 0,
change_community: undefined,
change_passphrase: undefined,
change_password: undefined,
change_passphrase: undefined,
change_privacy_password: undefined,
comment: 'bar',
community: '',
Expand All @@ -174,10 +166,6 @@ describe('CredentialsDialog component tests', () => {
});

test('should allow changing select values', async () => {
const {render} = rendererWith({
capabilities: true,
});

render(
<CredentialsDialog
types={ALL_CREDENTIAL_TYPES}
Expand Down Expand Up @@ -223,10 +211,6 @@ describe('CredentialsDialog component tests', () => {
});

test('should allow to close the dialog', () => {
const {render} = rendererWith({
capabilities: true,
});

render(
<CredentialsDialog
types={ALL_CREDENTIAL_TYPES}
Expand All @@ -241,10 +225,6 @@ describe('CredentialsDialog component tests', () => {
});

test('should render form fields for Username + SSH', () => {
const {render} = rendererWith({
capabilities: true,
});

const {getByName} = render(
<CredentialsDialog
credential_type={'usk'}
Expand All @@ -267,10 +247,6 @@ describe('CredentialsDialog component tests', () => {
});

test('should render form fields for SNMP', () => {
const {render} = rendererWith({
capabilities: true,
});

const {getByName, getAllByName} = render(
<CredentialsDialog
credential_type="snmp"
Expand Down Expand Up @@ -311,10 +287,6 @@ describe('CredentialsDialog component tests', () => {
});

test('should render form fields for S/MIME Certificate', () => {
const {render} = rendererWith({
capabilities: true,
});

const {getByName} = render(
<CredentialsDialog
credential_type="smime"
Expand All @@ -334,10 +306,6 @@ describe('CredentialsDialog component tests', () => {
});

test('should render form fields for PGP Encryption Key', () => {
const {render} = rendererWith({
capabilities: true,
});

const {getByName} = render(
<CredentialsDialog
credential_type={'pgp'}
Expand All @@ -356,11 +324,7 @@ describe('CredentialsDialog component tests', () => {
});

test('should render form fields for Password Only', () => {
const {render} = rendererWith({
capabilities: true,
});

const {getByName} = render(
render(
<CredentialsDialog
credential_type={'pw'}
types={ALL_CREDENTIAL_TYPES}
Expand All @@ -373,8 +337,58 @@ describe('CredentialsDialog component tests', () => {
const select = getSelectElement();
expect(select).toHaveValue('Password only');

const password = getByName('password');
const password = screen.getByTestId('password-input');
expect(password).toHaveValue('');
expect(password).toHaveAttribute('type', 'password');
});

test('should render CredentialsDialog and handle replace password interactions correctly', () => {
const credentialEntryMock = Credential.fromElement({
_id: '9b0',
allow_insecure: 1,
creation_time: '2025-01-08T15:50:23.000Z',
comment: 'MockComment',
formats: {format: 'exe'},
full_type: 'username + password',
in_use: 0,
login: 'user42',
modification_time: '2025-01-09T08:58:33.000Z',
name: 'Unnamed',
owner: {name: 'admin'},
permissions: {permission: {name: 'Everything'}},
type: 'up',
writable: 1,
});

render(
<CredentialsDialog
allow_insecure={credentialEntryMock.allow_insecure}
comment={credentialEntryMock.comment}
credential={credentialEntryMock}
credential_type={credentialEntryMock.credential_type}
name={credentialEntryMock.name}
title={'Edit Credential'}
types={ALL_CREDENTIAL_TYPES}
onClose={handleClose}
onErrorClose={handleErrorClose}
onSave={handleSave}
/>,
);

const title = screen.getByText('Edit Credential');
expect(title).toBeVisible();

const passwordField = screen.getByTestId('password-input');
expect(passwordField).toBeDisabled();

const checkbox = screen.getByLabelText('Replace existing password with');

expect(checkbox).not.toBeChecked();

fireEvent.click(checkbox);

expect(checkbox).toBeChecked();

expect(passwordField).not.toBeDisabled();
});
});
6 changes: 3 additions & 3 deletions src/web/pages/credentials/details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import _ from 'gmp/locale';
import {
SNMP_CREDENTIAL_TYPE,
SNMP_PRIVACY_ALOGRITHM_NONE,
SNMP_PRIVACY_ALGORITHM_NONE,
getCredentialTypeName,
} from 'gmp/models/credential';
import React from 'react';
Expand All @@ -29,7 +29,7 @@ const CredentialDetails = ({entity}) => {
login,
auth_algorithm,
privacy = {
algorithm: SNMP_PRIVACY_ALOGRITHM_NONE,
algorithm: SNMP_PRIVACY_ALGORITHM_NONE,
},
targets = [],
scanners = [],
Expand Down Expand Up @@ -78,7 +78,7 @@ const CredentialDetails = ({entity}) => {
<TableRow>
<TableData>{_('Privacy Algorithm')}</TableData>
<TableData>
{privacy.algorithm === SNMP_PRIVACY_ALOGRITHM_NONE
{privacy.algorithm === SNMP_PRIVACY_ALGORITHM_NONE
? _('None')
: privacy.algorithm}
</TableData>
Expand Down
Loading
Loading