Skip to content

Commit

Permalink
[Console] Only allow to send requests that have a valid method (elast…
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba authored Aug 1, 2024
1 parent bd5c273 commit cca1a3c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,20 @@ export class MonacoEditorActionsProvider {
} = context;
const { toasts } = notifications;
try {
const requests = await this.getRequests();
if (!requests.length) {
const allRequests = await this.getRequests();
// if any request doesnt have a method then we gonna treat it as a non-valid
// request
const requests = allRequests.filter((request) => request.method);

// If we do have requests but none have methods we are not sending the request
if (allRequests.length > 0 && !requests.length) {
toasts.addWarning(
i18n.translate('console.notification.monaco.error.nonSupportedRequest', {
defaultMessage: 'The selected request is not valid.',
})
);
return;
} else if (!requests.length) {
toasts.add(
i18n.translate('console.notification.monaco.error.noRequestSelectedTitle', {
defaultMessage:
Expand Down
10 changes: 3 additions & 7 deletions test/functional/apps/console/monaco/_console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const retry = getService('retry');
const log = getService('log');
const toasts = getService('toasts');
const browser = getService('browser');
const PageObjects = getPageObjects(['common', 'console', 'header']);
const security = getService('security');
Expand Down Expand Up @@ -57,17 +58,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(initialSize.width).to.be.greaterThan(afterSize.width);
});

it('should return statusCode 400 to unsupported HTTP verbs', async () => {
const expectedResponseContains = '"statusCode": 400';
it('should not send request with unsupported HTTP verbs', async () => {
await PageObjects.console.monaco.clearEditorText();
await PageObjects.console.monaco.enterText('OPTIONS /');
await PageObjects.console.clickPlay();
await retry.try(async () => {
const actualResponse = await PageObjects.console.monaco.getOutputText();
log.debug(actualResponse);
expect(actualResponse).to.contain(expectedResponseContains);

expect(await PageObjects.console.hasSuccessBadge()).to.be(false);
expect(await toasts.getCount()).to.equal(1);
});
});

Expand Down

0 comments on commit cca1a3c

Please sign in to comment.