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

fix: GEO-1209 e2e replace invalid file with text buffer #860

Merged
merged 3 commits into from
Nov 29, 2024
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
1 change: 0 additions & 1 deletion admin-frontend/e2e/assets/announcements/invalid.com

This file was deleted.

29 changes: 21 additions & 8 deletions admin-frontend/e2e/pages/announcements/form-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path';
import { expect, Locator } from 'playwright/test';
import { AnnouncementStatus } from '../../types';
import { AdminPortalPage } from '../admin-portal-page';
declare const Buffer;

export enum FormMode {
ADD,
Expand All @@ -24,6 +25,7 @@ export class FormPage extends AdminPortalPage {
linkTextInput: Locator;
chooseFileButton: Locator;
fileDisplayNameInput: Locator;
fileInput: Locator;

async setup() {
await super.setup();
Expand All @@ -45,6 +47,7 @@ export class FormPage extends AdminPortalPage {
this.fileDisplayNameInput = await this.page.getByLabel(
'Display File Link As',
);
this.fileInput = await this.page.getByLabel('Attachment', { exact: true });

await expect(this.titleInput).toBeVisible();
await expect(this.descriptionInput).toBeVisible();
Expand Down Expand Up @@ -153,16 +156,26 @@ export class FormPage extends AdminPortalPage {
async chooseFile(valid: boolean = true) {
await this.fillFileDisplayName(faker.lorem.words(1));
await expect(this.chooseFileButton).toBeVisible();
const scanResponse = this.waitForClamavScan();

const fileChooserPromise = this.page.waitForEvent('filechooser');
if (valid) {
const fileChooserPromise = this.page.waitForEvent('filechooser');

await this.chooseFileButton.click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(
path.resolve('e2e', 'assets', 'announcements', 'valid.pdf'),
);
} else {
await this.fileInput.setInputFiles({
name: 'invalid.pdf',
mimeType: 'application/pdf',
buffer: Buffer.from(
String.raw`X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*`,
),
});
}

const scanResponse = this.waitForClamavScan();
await this.chooseFileButton.click();
const fileChooser = await fileChooserPromise;
const fileName = valid ? 'valid.pdf' : 'invalid.com';
await fileChooser.setFiles(
path.resolve('e2e', 'assets', 'announcements', fileName),
);
const response = await scanResponse;
await response.json();
}
Expand Down
Loading