Skip to content

Commit

Permalink
[MHV-62502] VA.gov Secure Messaging | Silent failure: No send on bad …
Browse files Browse the repository at this point in the history
…attachments (#33155)

* [MHV-62502] Update attachment scan failure alert content

* cleanup

* update alert text

* [MHV-62502] Fix, only allow one malicious alert to display on reply form screen

* add reply with virus attachment scenarios

* [MHV-62502] Improved code, handled alert display in action sendReply

---------

Co-authored-by: fazilqa <[email protected]>
  • Loading branch information
vsaleem and fazilqa authored Nov 27, 2024
1 parent e116994 commit 3ea0421
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/applications/mhv-secure-messaging/actions/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export const sendReply = (
dispatch(
addAlert(
Constants.ALERT_TYPE_ERROR,
'',
Constants.Alerts.Headers.HIDE_ALERT,
Constants.Alerts.Message.ATTACHMENT_SCAN_FAIL,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const AttachmentsList = props => {
);
}
},
[attachmentScanError],
[attachmentScanError, attachments.length],
);

const getSize = num => {
Expand Down Expand Up @@ -209,7 +209,7 @@ const AttachmentsList = props => {
(attachments.length > 1 ? (
<VaAlert
data-testid="attachment-virus-alert"
aria-label={Alerts.Message.ATTACHMENT_SCAN_FAIL}
aria-label={Alerts.Message.MULTIPLE_ATTACHMENTS_SCAN_FAIL}
background-only
className="file-attached-success vads-u-margin-top--2"
disable-analytics
Expand All @@ -221,8 +221,7 @@ const AttachmentsList = props => {
aria-live="assertive"
className="vads-u-margin--0 vads-u-margin-bottom--1"
>
Your message failed to send. One or more of your files failed our
scan. Try sending your message without any attachments.
{Alerts.Message.MULTIPLE_ATTACHMENTS_SCAN_FAIL}
</p>
<va-button
text="Remove all attachments"
Expand Down Expand Up @@ -388,6 +387,7 @@ const AttachmentsList = props => {

AttachmentsList.propTypes = {
attachFileSuccess: PropTypes.bool,
attachmentScanError: PropTypes.bool,
attachments: PropTypes.array,
compose: PropTypes.bool,
draftSequence: PropTypes.number,
Expand All @@ -398,7 +398,6 @@ AttachmentsList.propTypes = {
setAttachments: PropTypes.func,
setIsModalVisible: PropTypes.func,
setNavigationError: PropTypes.func,
attachmentScanError: PropTypes.bool,
};

export default AttachmentsList;
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ const FileInput = props => {
};

FileInput.propTypes = {
attachmentScanError: PropTypes.bool,
attachments: PropTypes.array,
draftSequence: PropTypes.number,
setAttachFileSuccess: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,8 @@ describe('Attachments List component', () => {
);

expect(screen.findByTestId('attachment-virus-alert')).to.exist;
expect(
screen.getByText(
'Your message failed to send. One or more of your files failed our scan. Try sending your message without any attachments.',
),
).to.exist;
expect(screen.getByText(Alerts.Message.MULTIPLE_ATTACHMENTS_SCAN_FAIL)).to
.exist;

const removeAllAttachments = await screen.findByTestId(
'remove-all-attachments-button',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import SecureMessagingSite from './sm_site/SecureMessagingSite';
import PatientInboxPage from './pages/PatientInboxPage';
import PatientReplyPage from './pages/PatientReplyPage';
import GeneralFunctionsPage from './pages/GeneralFunctionsPage';
import PatientMessageDetailsPage from './pages/PatientMessageDetailsPage';
import { Alerts, AXE_CONTEXT, Data, Locators, Paths } from './utils/constants';
import singleThreadResponse from './fixtures/thread-response-new-api.json';
import PatientInterstitialPage from './pages/PatientInterstitialPage';
import PatientComposePage from './pages/PatientComposePage';

describe('SM ATTACHMENT WITH VIRUS ON REPLY', () => {
const updatedSingleThreadResponse = GeneralFunctionsPage.updatedThreadDates(
singleThreadResponse,
);
beforeEach(() => {
SecureMessagingSite.login();
PatientInboxPage.loadInboxMessages();
PatientMessageDetailsPage.loadSingleThread(updatedSingleThreadResponse);
PatientReplyPage.clickReplyButton(updatedSingleThreadResponse);
PatientInterstitialPage.getContinueButton().click();
PatientReplyPage.getMessageBodyField()
.focus()
.clear()
.type(`Test body`);
});

describe('Verify single attachment with virus alert', () => {
beforeEach(() => {
PatientComposePage.attachMessageFromFile(Data.SAMPLE_IMG);
cy.intercept(
'POST',
`${Paths.SM_API_EXTENDED}/${
updatedSingleThreadResponse.data[0].attributes.messageId
}/reply`,
{
statusCode: 400,
body: { errors: [{ code: 'SM172' }] },
},
).as('failed');
cy.get(Locators.BUTTONS.SEND)
.contains('Send')
.click({ force: true });
});

it('verify alert exist and attach button disappears', () => {
cy.get(Locators.ALERTS.ATTCH_VIRUS)
.should(`be.visible`)
.and(`have.text`, Alerts.VIRUS_ATTCH);

cy.get(Locators.ATTACH_FILE_INPUT).should(`not.exist`);
cy.get(Locators.BUTTONS.REMOVE_ATTACHMENT).should('be.focused');

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});

it(`verify attach button back`, () => {
cy.get(Locators.BUTTONS.REMOVE_ATTACHMENT).click({ force: true });
cy.get(Locators.BUTTONS.CONFIRM_REMOVE_ATTACHMENT)
.should(`be.visible`)
.then(btn => {
return new Cypress.Promise(resolve => {
setTimeout(resolve, 2000);
cy.wrap(btn).click();
});
});

cy.get(Locators.BUTTONS.ATTACH_FILE).should(`exist`);
cy.get(Locators.BUTTONS.ATTACH_FILE).should(`be.focused`);

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});
});

describe('Verify multiple attachment with virus alert', () => {
beforeEach(() => {
PatientComposePage.attachMessageFromFile(Data.SAMPLE_IMG);
PatientComposePage.attachMessageFromFile(Data.SAMPLE_XLS);
PatientComposePage.attachMessageFromFile(Data.SAMPLE_PDF);
cy.intercept(
'POST',
`${Paths.SM_API_EXTENDED}/${
updatedSingleThreadResponse.data[0].attributes.messageId
}/reply`,
{
statusCode: 400,
body: { errors: [{ code: 'SM172' }] },
},
).as('failed');
cy.get(Locators.BUTTONS.SEND)
.contains('Send')
.click({ force: true });
});

it('verify alert exist and attach button disappears', () => {
cy.get(Locators.ALERTS.ATTCH_VIRUS)
.should(`be.visible`)
.and(`have.text`, Alerts.VIRUS_MULTI_ATTCH);
cy.get(Locators.ATTACH_FILE_INPUT).should(`not.exist`);
cy.get(Locators.BUTTONS.REMOVE_ALL_ATTCH).should('be.focused');

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});

it(`verify attach button back`, () => {
cy.get(Locators.BUTTONS.REMOVE_ALL_ATTCH)
.should(`be.visible`)
.then(btn => {
return new Cypress.Promise(resolve => {
setTimeout(resolve, 2000);
cy.wrap(btn).click();
});
});

cy.get(Locators.BUTTONS.ATTACH_FILE).should(`exist`);
cy.get(Locators.BUTTONS.ATTACH_FILE).should(`be.focused`);

cy.injectAxe();
cy.axeCheck(AXE_CONTEXT);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe('SM DELETE REPLY DRAFT', () => {
const updatedSingleThreadResponse = GeneralFunctionsPage.updatedThreadDates(
singleThreadResponse,
);
// const singleMessage = { data: updatedSingleThreadResponse.data[0] };
it('verify user can delete draft on reply', () => {
SecureMessagingSite.login();
PatientInboxPage.loadInboxMessages();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ export const Alerts = {
EL_SIGN_CHECK: `You must certify by checking the box.`,
SAVE_SIGN: `We can't save your signature in a draft message`,
SAVE_SIGN_ATTCH: `We can't save your signature or attachments in a draft message`,
VIRUS_ATTCH: `Your message failed to send. Your file failed our scan. Try sending your message without any attachments.`,
VIRUS_MULTI_ATTCH: `Your message failed to send. One or more of your files failed our scan. Try sending your message without any attachments.`,
VIRUS_ATTCH: `Our file scanner found a problem with your attachment. To send your message, remove this attachment.`,
VIRUS_MULTI_ATTCH: `Our file scanner found a problem with your attachments. To send your message, remove the attachments.`,
SAVE_DRAFT: `Do you want to save your draft message?`,
SAVE_CHANGES: `Do you want to save your changes to this draft?`,
};
Expand Down
4 changes: 3 additions & 1 deletion src/applications/mhv-secure-messaging/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ export const Alerts = {
'We’re sorry. We couldn’t load this page. Try again later.',
SAVE_CONTACT_LIST_SUCCESS: 'Contact list changes saved',
ATTACHMENT_SCAN_FAIL:
'Your message failed to send. Your file failed our scan. Try sending your message without any attachments.',
'Our file scanner found a problem with your attachment. To send your message, remove this attachment.',
MULTIPLE_ATTACHMENTS_SCAN_FAIL:
'Our file scanner found a problem with your attachments. To send your message, remove the attachments.',
},

Folder: {
Expand Down

0 comments on commit 3ea0421

Please sign in to comment.