Update supertest and superagent to latest version (#183587)

## Summary

Related to https://github.com/elastic/kibana/issues/7104

Update supertest, superagent, and the corresponding type package, to
their latest version.

(of course, types had some signature changes and we're massively using
supertest in all our FTR suites so the whole Kibana multiverse has to
review it)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Pierre Gayvallet 2024-05-17 13:23:21 +02:00 committed by GitHub
parent 4b7d014582
commit 148eeec0fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
153 changed files with 439 additions and 431 deletions

View file

@ -1523,7 +1523,7 @@
"@types/source-map-support": "^0.5.3",
"@types/stats-lite": "^2.2.0",
"@types/styled-components": "^5.1.0",
"@types/supertest": "^2.0.12",
"@types/supertest": "^6.0.2",
"@types/tapable": "^1.0.6",
"@types/tar": "^6.1.11",
"@types/testing-library__jest-dom": "^5.14.7",
@ -1697,8 +1697,8 @@
"style-loader": "^1.1.3",
"stylelint": "^14.9.1",
"stylelint-scss": "^4.3.0",
"superagent": "^8.1.2",
"supertest": "^6.3.3",
"superagent": "^9.0.2",
"supertest": "^7.0.0",
"svgo": "^2.8.0",
"table": "^6.8.1",
"tape": "^5.0.1",

View file

@ -1622,7 +1622,7 @@ describe('setup contract', () => {
.get('/static/some_json.json')
.expect(200);
const etag = response.get('etag');
const etag = response.get('etag')!;
expect(etag).not.toBeUndefined();
await supertest(innerServer.listener)

View file

@ -28,7 +28,7 @@ describe('BasePathProxyServer', () => {
let logger: TestLog;
let config: IHttpConfig;
let basePath: string;
let proxySupertest: supertest.SuperTest<supertest.Test>;
let proxySupertest: supertest.Agent;
beforeEach(async () => {
logger = new TestLog();
@ -330,7 +330,7 @@ describe('BasePathProxyServer', () => {
describe('shouldRedirect', () => {
let proxyServerWithoutShouldRedirect: BasePathProxyServer;
let proxyWithoutShouldRedirectSupertest: supertest.SuperTest<supertest.Test>;
let proxyWithoutShouldRedirectSupertest: supertest.Agent;
beforeEach(async () => {
// setup and start a proxy server which does not use "shouldRedirectFromOldBasePath"
@ -373,7 +373,7 @@ describe('BasePathProxyServer', () => {
describe('constructor option for sending in a custom basePath', () => {
let proxyServerWithFooBasePath: BasePathProxyServer;
let proxyWithFooBasePath: supertest.SuperTest<supertest.Test>;
let proxyWithFooBasePath: supertest.Agent;
beforeEach(async () => {
// setup and start a proxy server which uses a basePath of "foo"

View file

@ -134,7 +134,7 @@ describe('Cookie based SessionStorage', () => {
const response = await supertest(innerServer.listener).get('/').expect(200);
const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
expect(cookies).toBeDefined();
expect(cookies).toHaveLength(1);
@ -172,7 +172,7 @@ describe('Cookie based SessionStorage', () => {
const response = await supertest(innerServer.listener).get('/').expect(200);
const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
expect(cookies).toBeDefined();
expect(cookies).toHaveLength(1);
@ -204,7 +204,7 @@ describe('Cookie based SessionStorage', () => {
const response = await supertest(innerServer.listener).get('/').expect(200, { value: null });
const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
expect(cookies).not.toBeDefined();
});
@ -237,7 +237,7 @@ describe('Cookie based SessionStorage', () => {
.get('/')
.expect(200, { value: userData });
const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
expect(cookies).toBeDefined();
await delay(sessionDurationMs);
@ -283,7 +283,7 @@ describe('Cookie based SessionStorage', () => {
.get('/')
.expect(200, { value: userData });
const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
expect(cookies).toBeDefined();
const sessionCookie = retrieveSessionCookie(cookies[0]);
@ -418,7 +418,7 @@ describe('Cookie based SessionStorage', () => {
const response = await supertest(innerServer.listener).get('/').expect(200);
const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
const sessionCookie = retrieveSessionCookie(cookies[0]);
const response2 = await supertest(innerServer.listener)
@ -475,7 +475,7 @@ describe('Cookie based SessionStorage', () => {
const response = await supertest(innerServer.listener).get('/').expect(200);
const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
expect(cookies).toBeDefined();
expect(cookies).toHaveLength(1);

View file

@ -29,7 +29,7 @@ interface AdditionalOptions {
describe('Routing versioned requests', () => {
let router: IRouter;
let supertest: Supertest.SuperTest<Supertest.Test>;
let supertest: Supertest.Agent;
async function setupServer(cliArgs: Partial<CliArgs> = {}, options: AdditionalOptions = {}) {
logger = loggingSystemMock.create();

View file

@ -116,7 +116,7 @@ describe('ServerMetricsCollector', () => {
// Subscribe to the aborted$ event
const waitFor1stAbort = disconnectAborted$.pipe(take(1)).toPromise();
discoReq1.abort();
void discoReq1.abort();
// Wait for the aborted$ event
await waitFor1stAbort;
@ -132,7 +132,7 @@ describe('ServerMetricsCollector', () => {
// Subscribe to the aborted$ event
const waitFor2ndAbort = disconnectAborted$.pipe(take(1)).toPromise();
discoReq2.abort();
void discoReq2.abort();
// Wait for the aborted$ event
await waitFor2ndAbort;

View file

@ -70,7 +70,7 @@ export default function ({ getService }: FtrProviderContext) {
await supertest
.get(FIELDS_PATH)
.set('If-None-Match', response.get('etag'))
.set('If-None-Match', response.get('etag')!)
.query({
pattern: '*',
include_unmapped: true,

View file

@ -6,7 +6,6 @@
* Side Public License, v 1.
*/
import { SuperTest, Test } from 'supertest';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
@ -14,7 +13,7 @@ const apiUrl = '/api/kibana/management/saved_objects/scroll/counts';
const defaultTypes = ['visualization', 'index-pattern', 'search', 'dashboard'];
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest') as SuperTest<Test>;
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');
const esArchiver = getService('esArchiver');

View file

@ -87,7 +87,7 @@ export default function optInTest({ getService }: FtrProviderContext) {
}
async function postTelemetryV2OptIn(
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
value: unknown,
statusCode: number
): Promise<any> {

View file

@ -13,13 +13,15 @@ import { format as formatUrl } from 'url';
import supertest from 'supertest';
import { FtrProviderContext } from '../../functional/ftr_provider_context';
export function KibanaSupertestProvider({ getService }: FtrProviderContext) {
export function KibanaSupertestProvider({ getService }: FtrProviderContext): supertest.Agent {
const config = getService('config');
const kibanaServerUrl = formatUrl(config.get('servers.kibana'));
return supertest(kibanaServerUrl);
}
export function ElasticsearchSupertestProvider({ getService }: FtrProviderContext) {
export function ElasticsearchSupertestProvider({
getService,
}: FtrProviderContext): supertest.Agent {
const config = getService('config');
const esServerConfig = config.get('servers.elasticsearch');

View file

@ -40,7 +40,7 @@ const getSpaceUrlPrefix = (spaceId?: string): string => {
* Options for the send method
*/
interface SendOptions {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
options: object;
strategy: string;
space?: string;

View file

@ -74,7 +74,7 @@ describe('APMEventClient', () => {
resolve(undefined);
}, 100);
});
incomingRequest.abort();
void incomingRequest.abort();
}, 100);
});

View file

@ -13,7 +13,7 @@ async function delay(millis: number): Promise<void> {
}
export function createWaitForExecutionCount(
st: supertest.SuperTest<supertest.Test>,
st: supertest.Agent,
spaceId?: string,
delayMs: number = 3000
) {

View file

@ -6,7 +6,7 @@
*/
import type { Client } from '@elastic/elasticsearch';
import type { SuperTest, Test } from 'supertest';
import type { Agent as SuperTestAgent } from 'supertest';
import { ToolingLog } from '@kbn/tooling-log';
import { ThresholdParams } from '@kbn/observability-plugin/common/custom_threshold_rule/types';
import { refreshSavedObjectIndices } from './refresh_index';
@ -17,7 +17,7 @@ export async function createIndexConnector({
indexName,
logger,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
name: string;
indexName: string;
logger: ToolingLog;
@ -51,7 +51,7 @@ export async function createRule<Params = ThresholdParams>({
logger,
esClient,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
ruleTypeId: string;
name: string;
params: Params;

View file

@ -29,7 +29,7 @@ export async function waitForRuleStatus({
}: {
id: string;
expectedStatus: string;
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
retryService: RetryService;
logger: ToolingLog;
}): Promise<Record<string, any>> {

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { ToolingLog } from '@kbn/tooling-log';
export const createDataView = async ({
@ -15,7 +15,7 @@ export const createDataView = async ({
title,
logger,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
id: string;
name: string;
title: string;
@ -50,7 +50,7 @@ export const deleteDataView = async ({
id,
logger,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
id: string;
logger: ToolingLog;
}) => {

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { chunk, omit } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import { SuperuserAtSpace1, UserAtSpaceScenarios } from '../../../scenarios';
@ -16,7 +16,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
const findTestUtils = (
describeType: 'internal' | 'public',
objectRemover: ObjectRemover,
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
supertestWithoutAuth: any
) => {
describe.skip(describeType, () => {

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { chunk, omit } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import { UserAtSpaceScenarios } from '../../../scenarios';
@ -16,7 +16,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
const findTestUtils = (
describeType: 'internal' | 'public',
objectRemover: ObjectRemover,
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
supertestWithoutAuth: any
) => {
// FLAKY: https://github.com/elastic/kibana/issues/182314

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { SuperuserAtSpace1, UserAtSpaceScenarios } from '../../../scenarios';
import {
getUrlPrefix,
@ -19,7 +19,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
const getTestUtils = (
describeType: 'internal' | 'public',
objectRemover: ObjectRemover,
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
supertestWithoutAuth: any
) => {
describe(describeType, () => {

View file

@ -131,7 +131,7 @@ export default function createCrowdstrikeTests({ getService }: FtrProviderContex
password = 'changeme',
errorLogger = logErrorDetails,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
subAction: string;
subActionParams: Record<string, unknown>;
expectedHttpCode?: number;

View file

@ -140,7 +140,7 @@ export default function createSentinelOneTests({ getService }: FtrProviderContex
password = 'changeme',
errorLogger = logErrorDetails,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
subAction: string;
subActionParams: Record<string, unknown>;
expectedHttpCode?: number;

View file

@ -22,7 +22,7 @@ const createSubActionConnector = async ({
connectorTypeId = 'test.sub-action-connector',
expectedHttpCode = 200,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
config?: Record<string, unknown>;
secrets?: Record<string, unknown>;
connectorTypeId?: string;
@ -56,7 +56,7 @@ const executeSubAction = async ({
subActionParams,
expectedHttpCode = 200,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
connectorId: string;
subAction: string;
subActionParams: Record<string, unknown>;

View file

@ -8,7 +8,7 @@
import http from 'http';
import https from 'https';
import getPort from 'get-port';
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import expect from '@kbn/expect';
import { URL, format as formatUrl } from 'url';
import {
@ -177,7 +177,7 @@ export default function webhookTest({ getService }: FtrProviderContext) {
}
export async function createWebhookAction(
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
webhookSimulatorURL: string,
config: Record<string, string | Record<string, string>> = {}
): Promise<string> {

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { fromKueryExpression } from '@kbn/es-query';
import { Spaces } from '../../../scenarios';
import { getUrlPrefix, getTestRuleData, ObjectRemover } from '../../../../common/lib';
@ -14,7 +14,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
async function createAlert(
objectRemover: ObjectRemover,
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
overwrites = {}
) {
const { body: createdAlert } = await supertest
@ -28,7 +28,7 @@ async function createAlert(
const findTestUtils = (
describeType: 'internal' | 'public',
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
objectRemover: ObjectRemover
) => {
describe(describeType, () => {

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { Spaces } from '../../../scenarios';
import { getUrlPrefix, getTestRuleData, ObjectRemover } from '../../../../common/lib';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';
@ -14,7 +14,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
const getTestUtils = (
describeType: 'internal' | 'public',
objectRemover: ObjectRemover,
supertest: SuperTest<Test>
supertest: SuperTestAgent
) => {
describe(describeType, () => {
afterEach(() => objectRemover.removeAll());

View file

@ -8,7 +8,7 @@
import moment from 'moment';
import type { RetryService } from '@kbn/ftr-common-functional-services';
import type { IValidatedEvent } from '@kbn/event-log-plugin/server';
import type { SuperTest, Test } from 'supertest';
import type { Agent as SuperTestAgent } from 'supertest';
import expect from '@kbn/expect';
import type { FtrProviderContext } from '../../../../common/ftr_provider_context';
import { getUrlPrefix, getTestRuleData, ObjectRemover, getEventLog } from '../../../../common/lib';
@ -23,7 +23,7 @@ export const createRule = async ({
}: {
actionId: string;
pattern: { instance: boolean[] };
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
objectRemover: ObjectRemover;
overwrites?: any;
}) => {
@ -65,7 +65,7 @@ export const createAction = async ({
supertest,
objectRemover,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
objectRemover: ObjectRemover;
}) => {
const { body: createdAction } = await supertest
@ -89,7 +89,7 @@ export const createMaintenanceWindow = async ({
objectRemover,
}: {
overwrites?: any;
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
objectRemover: ObjectRemover;
}) => {
const { body: window } = await supertest
@ -112,11 +112,7 @@ export const createMaintenanceWindow = async ({
return window;
};
export const getActiveMaintenanceWindows = async ({
supertest,
}: {
supertest: SuperTest<Test>;
}) => {
export const getActiveMaintenanceWindows = async ({ supertest }: { supertest: SuperTestAgent }) => {
const { body: activeMaintenanceWindows } = await supertest
.get(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/maintenance_window/_active`)
.set('kbn-xsrf', 'foo')
@ -130,7 +126,7 @@ export const finishMaintenanceWindow = async ({
supertest,
}: {
id: string;
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
}) => {
return supertest
.post(
@ -188,7 +184,7 @@ export const expectNoActionsFired = async ({
retry,
}: {
id: string;
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
retry: RetryService;
}) => {
const events = await retry.try(async () => {
@ -215,7 +211,7 @@ export const runSoon = async ({
retry,
}: {
id: string;
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
retry: RetryService;
}) => {
return retry.try(async () => {

View file

@ -9,11 +9,11 @@ import type { AssetWithoutTimestamp } from '@kbn/assetManager-plugin/common/type
import type { WriteSamplesPostBody } from '@kbn/assetManager-plugin/server';
import { apm, infra, timerange } from '@kbn/apm-synthtrace-client';
import expect from '@kbn/expect';
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
const SAMPLE_ASSETS_ENDPOINT = '/api/asset-manager/assets/sample';
export type KibanaSupertest = SuperTest<Test>;
export type KibanaSupertest = SuperTestAgent;
// NOTE: In almost every case in tests, you want { refresh: true }
// in the options of this function, so it is defaulted to that value.

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import type { SuperTest, Test } from 'supertest';
import type { Agent as SuperTestAgent } from 'supertest';
import { Client } from '@elastic/elasticsearch';
import expect from '@kbn/expect';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
@ -43,7 +43,7 @@ export const addIndex = async <T>(es: Client, findingsMock: T[], indexName: stri
};
export async function createPackagePolicy(
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
agentPolicyId: string,
policyTemplate: string,
input: string,

View file

@ -36,7 +36,9 @@ export function templatesApi(getService: FtrProviderContext['getService']) {
.send(payload);
// Delete all templates created during tests
const cleanUpTemplates = async (additionalRequestHeaders: object = {}) => {
const cleanUpTemplates = async (
additionalRequestHeaders: Record<string, string | string[]> = {}
) => {
try {
await deleteTemplates(templatesCreated).set(additionalRequestHeaders);
templatesCreated = [];

View file

@ -6,9 +6,6 @@
*/
import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { SuperTest, Test } from 'supertest';
export type KibanaSupertest = SuperTest<Test>;
// generates traces, metrics for services
export function generateServicesData({

View file

@ -50,7 +50,7 @@ function getCacheDetails(body: UnencryptedTelemetryPayload): CacheDetails[] {
* @param timestamp The new timestamp to be set
*/
function updateMonitoringDates(
esSupertest: SuperTest.SuperTest<SuperTest.Test>,
esSupertest: SuperTest.Agent,
fromTimestamp: string,
toTimestamp: string,
timestamp: string

View file

@ -15,7 +15,7 @@ import type {
import type { APIEndpoint } from '@kbn/apm-plugin/server';
import { formatRequest } from '@kbn/server-route-repository';
export function createApmApiClient(st: supertest.SuperTest<supertest.Test>) {
export function createApmApiClient(st: supertest.Agent) {
return async <TEndpoint extends APIEndpoint>(
options: {
type?: 'form-data';

View file

@ -30,7 +30,7 @@ export interface BetterTestResponse<T> {
* This is useful for tests that expect a 200 response
* It also makes it easier to debug tests that fail because of a 500 response.
*/
export function getBettertest(st: supertest.SuperTest<supertest.Test>) {
export function getBettertest(st: supertest.Agent) {
return async <T>({
pathname,
method = 'get',

View file

@ -8,7 +8,7 @@
import { Client, errors } from '@elastic/elasticsearch';
import { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common';
import pRetry from 'p-retry';
import type { SuperTest, Test } from 'supertest';
import type { Agent as SuperTestAgent } from 'supertest';
import { ApmRuleType } from '@kbn/rule-data-utils';
import { ApmRuleParamsType } from '@kbn/apm-plugin/common/rules/schema';
import { ApmDocumentType } from '@kbn/apm-plugin/common/document_type';
@ -26,7 +26,7 @@ export async function createApmRule<T extends ApmRuleType>({
params,
actions = [],
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
ruleTypeId: T;
name: string;
params: ApmRuleParamsType[T];
@ -111,7 +111,7 @@ export async function runRuleSoon({
supertest,
}: {
ruleId: string;
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
}): Promise<Record<string, any>> {
return pRetry(
async () => {
@ -143,13 +143,13 @@ export async function deleteRuleById({
supertest,
ruleId,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
ruleId: string;
}) {
await supertest.delete(`/api/alerting/rule/${ruleId}`).set('kbn-xsrf', 'foo');
}
export async function deleteApmRules(supertest: SuperTest<Test>) {
export async function deleteApmRules(supertest: SuperTestAgent) {
const res = await supertest.get(
`/api/alerting/rules/_find?filter=alert.attributes.consumer:apm&per_page=10000`
);
@ -180,7 +180,7 @@ export async function createIndexConnector({
supertest,
name,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
name: string;
}) {
const { body } = await supertest
@ -228,7 +228,7 @@ export async function deleteAllActionConnectors({
supertest,
es,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
es: Client;
}): Promise<any> {
const res = await supertest.get(`/api/actions/connectors`);
@ -245,7 +245,7 @@ async function deleteActionConnector({
supertest,
actionId,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
actionId: string;
}) {
return supertest.delete(`/api/actions/connector/${actionId}`).set('kbn-xsrf', 'foo');

View file

@ -7,7 +7,7 @@
import { Client } from '@elastic/elasticsearch';
import { ToolingLog } from '@kbn/tooling-log';
import type { SuperTest, Test } from 'supertest';
import type { Agent as SuperTestAgent } from 'supertest';
import {
clearKibanaApmEventLog,
deleteApmRules,
@ -22,7 +22,7 @@ export async function cleanupRuleAndAlertState({
logger,
}: {
es: Client;
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
logger: ToolingLog;
}) {
try {

View file

@ -17,7 +17,7 @@ export async function waitForActiveRule({
logger,
}: {
ruleId: string;
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
logger?: ToolingLog;
}): Promise<Record<string, any>> {
return pRetry(

View file

@ -30,7 +30,7 @@ import { createComment, deleteAllComments } from './api';
import { postCaseReq } from './mock';
export const createSecuritySolutionAlerts = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog,
numberOfSignals: number = 1
): Promise<estypes.SearchResponse<DetectionAlert & RiskEnrichmentFields>> => {
@ -47,7 +47,7 @@ export const createSecuritySolutionAlerts = async (
};
export const getSecuritySolutionAlerts = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
alertIds: string[]
): Promise<estypes.SearchResponse<DetectionAlert & RiskEnrichmentFields>> => {
const { body: updatedAlert } = await supertest
@ -70,7 +70,7 @@ export const getAlertById = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
id: string;
index: string;
expectedHttpCode?: number;
@ -97,7 +97,7 @@ export const createCaseAttachAlertAndDeleteAlert = async ({
alerts,
getAlerts,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
totalCases: number;
indexOfCaseToDelete: number;
owner: string;
@ -145,7 +145,7 @@ export const createCaseAttachAlertAndDeleteCase = async ({
alerts,
getAlerts,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
totalCases: number;
indicesOfCaseToDelete: number[];
owner: string;
@ -194,7 +194,7 @@ export const createCaseAndAttachAlert = async ({
alerts,
getAlerts,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
totalCases: number;
owner: string;
alerts: Alerts;

View file

@ -33,7 +33,7 @@ export const bulkGetAttachments = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
attachmentIds: string[];
caseId: string;
auth?: { user: User; space: string | null };
@ -57,12 +57,12 @@ export const createComment = async ({
expectedHttpCode = 200,
headers = {},
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
params: AttachmentRequest;
auth?: { user: User; space: string | null } | null;
expectedHttpCode?: number;
headers?: Record<string, unknown>;
headers?: Record<string, string | string[]>;
}): Promise<Case> => {
const apiCall = supertest.post(
`${getSpaceUrlPrefix(auth?.space)}${CASES_URL}/${caseId}/comments`
@ -86,7 +86,7 @@ export const bulkCreateAttachments = async ({
auth = { user: superUser, space: null },
expectedHttpCode = 200,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
params: BulkCreateAttachmentsRequest;
auth?: { user: User; space: string | null };
@ -110,7 +110,7 @@ export const createCaseAndBulkCreateAttachments = async ({
auth = { user: superUser, space: null },
expectedHttpCode = 200,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
numberOfAttachments?: number;
auth?: { user: User; space: string | null };
expectedHttpCode?: number;
@ -156,7 +156,7 @@ export const deleteComment = async ({
expectedHttpCode = 204,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
commentId: string;
expectedHttpCode?: number;
@ -178,7 +178,7 @@ export const deleteAllComments = async ({
expectedHttpCode = 204,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -199,7 +199,7 @@ export const getAllComments = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
auth?: { user: User; space: string | null };
expectedHttpCode?: number;
@ -219,7 +219,7 @@ export const getComment = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
commentId: string;
expectedHttpCode?: number;
@ -241,12 +241,12 @@ export const updateComment = async ({
auth = { user: superUser, space: null },
headers = {},
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
req: AttachmentPatchRequest;
expectedHttpCode?: number;
auth?: { user: User; space: string | null } | null;
headers?: Record<string, unknown>;
headers?: Record<string, string | string[]>;
}): Promise<Case> => {
const apiCall = supertest.patch(
`${getSpaceUrlPrefix(auth?.space)}${CASES_URL}/${caseId}/comments`
@ -269,7 +269,7 @@ export const bulkDeleteFileAttachments = async ({
expectedHttpCode = 204,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
fileIds: string[];
expectedHttpCode?: number;
@ -290,7 +290,7 @@ export const findAttachments = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
query?: Record<string, unknown>;
expectedHttpCode?: number;

View file

@ -15,11 +15,11 @@ import { superUser } from '../authentication/users';
import { getSpaceUrlPrefix, setupAuth } from './helpers';
export const createCase = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
params: CasePostRequest,
expectedHttpCode: number = 200,
auth: { user: User; space: string | null } | null = { user: superUser, space: null },
headers: Record<string, unknown> = {}
headers: Record<string, string | string[]> = {}
): Promise<Case> => {
const apiCall = supertest.post(`${getSpaceUrlPrefix(auth?.space)}${CASES_URL}`);
@ -44,7 +44,7 @@ export const deleteCases = async ({
expectedHttpCode = 204,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseIDs: string[];
expectedHttpCode?: number;
auth?: { user: User; space: string | null };

View file

@ -60,11 +60,11 @@ export const getConfigurationOutput = (update = false, overwrite = {}): Partial<
};
export const createConfiguration = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
req: ConfigurationRequest = getConfigurationRequest(),
expectedHttpCode: number = 200,
auth: { user: User; space: string | null } | null = { user: superUser, space: null },
headers: Record<string, unknown> = {}
headers: Record<string, string | string[]> = {}
): Promise<Configuration> => {
const apiCall = supertest.post(`${getSpaceUrlPrefix(auth?.space)}${CASE_CONFIGURE_URL}`);
@ -86,7 +86,7 @@ export const getConfiguration = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
query?: Record<string, unknown>;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -102,12 +102,12 @@ export const getConfiguration = async ({
};
export const updateConfiguration = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
id: string,
req: ConfigurationPatchRequest,
expectedHttpCode: number = 200,
auth: { user: User; space: string | null } | null = { user: superUser, space: null },
headers: Record<string, unknown> = {}
headers: Record<string, string | string[]> = {}
): Promise<Configuration> => {
const apiCall = supertest.patch(`${getSpaceUrlPrefix(auth?.space)}${CASE_CONFIGURE_URL}/${id}`);

View file

@ -194,7 +194,7 @@ export const getCaseConnectors = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
}): Promise<FindActionResult[]> => {
@ -215,13 +215,13 @@ export const createCaseWithConnector = async ({
createCaseReq = getPostCaseRequest(),
headers = {},
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
serviceNowSimulatorURL: string;
actionsRemover: ActionsRemover;
configureReq?: Record<string, unknown>;
auth?: { user: User; space: string | null } | null;
createCaseReq?: CasePostRequest;
headers?: Record<string, unknown>;
headers?: Record<string, string | string[]>;
}): Promise<{
postedCase: Case;
connector: CreateConnectorResponse;
@ -288,7 +288,7 @@ export const createConnector = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
req: Record<string, unknown>;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -309,7 +309,7 @@ export const getConnectors = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -329,7 +329,7 @@ export const executeConnector = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
connectorId: string;
req: Record<string, unknown>;
expectedHttpCode?: number;
@ -352,7 +352,7 @@ export const executeSystemConnector = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
connectorId: string;
req: Record<string, unknown>;
expectedHttpCode?: number;

View file

@ -23,7 +23,7 @@ export const downloadFile = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
fileId: string;
kind: string;
mimeType: string;
@ -49,7 +49,7 @@ export const deleteFileForFileKind = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
fileKind: string;
id: string;
expectedHttpCode?: number;
@ -72,7 +72,7 @@ export const deleteFiles = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
files: string[];
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -91,7 +91,7 @@ export const deleteAllFilesForKind = async ({
auth = { user: superUser, space: null },
expectedHttpCode = 200,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
kind: string;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -124,7 +124,7 @@ export const deleteAllFiles = async ({
expectedHttpCode = 200,
ignoreErrors = true,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
ignoreErrors?: boolean;
@ -165,7 +165,7 @@ export const getFileById = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
id: string;
kind: string;
expectedHttpCode?: number;
@ -185,7 +185,7 @@ export const listFiles = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
params: Parameters<BaseFilesClient['list']>[0];
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -213,7 +213,7 @@ export const createFile = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
params: CreateFileSchema;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -238,7 +238,7 @@ export const uploadFile = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
data: string | object;
kind: string;
fileId: string;
@ -264,7 +264,7 @@ export const createAndUploadFile = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
data: string | object;
createFileParams: CreateFileSchema;
expectedHttpCode?: number;

View file

@ -129,7 +129,7 @@ export const setStatus = async ({
supertest,
cases,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
cases: SetStatusCasesParams[];
}): Promise<Cases> => {
const { body }: { body: Cases } = await supertest
@ -143,7 +143,7 @@ export const setStatus = async ({
/**
* Add case as a connector
*/
export const createCaseAction = async (supertest: SuperTest.SuperTest<SuperTest.Test>) => {
export const createCaseAction = async (supertest: SuperTest.Agent) => {
const { body: createdAction } = await supertest
.post('/api/actions/connector')
.set('kbn-xsrf', 'foo')
@ -159,10 +159,7 @@ export const createCaseAction = async (supertest: SuperTest.SuperTest<SuperTest.
/**
* Remove a connector
*/
export const deleteCaseAction = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
id: string
) => {
export const deleteCaseAction = async (supertest: SuperTest.Agent, id: string) => {
await supertest.delete(`/api/actions/connector/${id}`).set('kbn-xsrf', 'foo');
};
@ -418,11 +415,11 @@ export const updateCase = async ({
auth = { user: superUser, space: null },
headers = {},
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
params: CasesPatchRequest;
expectedHttpCode?: number;
auth?: { user: User; space: string | null } | null;
headers?: Record<string, unknown>;
headers?: Record<string, string | string[]>;
}): Promise<Case[]> => {
const apiCall = supertest.patch(`${getSpaceUrlPrefix(auth?.space)}${CASES_URL}`);
@ -444,7 +441,7 @@ export const getAllCasesStatuses = async ({
auth = { user: superUser, space: null },
query = {},
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
query?: Record<string, unknown>;
@ -465,7 +462,7 @@ export const getCase = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
includeComments?: boolean;
expectedHttpCode?: number;
@ -490,7 +487,7 @@ export const getCaseMetrics = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
features: CaseMetricsFeature[] | CaseMetricsFeature;
expectedHttpCode?: number;
@ -512,7 +509,7 @@ export const resolveCase = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
includeComments?: boolean;
expectedHttpCode?: number;
@ -537,7 +534,7 @@ export const findCases = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
query?: Record<string, unknown>;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -560,7 +557,7 @@ export const getCasesByAlert = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
alertID: string;
query?: Record<string, unknown>;
expectedHttpCode?: number;
@ -581,7 +578,7 @@ export const getTags = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
query?: Record<string, unknown>;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -602,7 +599,7 @@ export const getReporters = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
query?: Record<string, unknown>;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -623,7 +620,7 @@ export const getCategories = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
query?: Record<string, unknown>;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -646,12 +643,12 @@ export const pushCase = async ({
auth = { user: superUser, space: null },
headers = {},
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
connectorId: string;
expectedHttpCode?: number;
auth?: { user: User; space: string | null } | null;
headers?: Record<string, unknown>;
headers?: Record<string, string | string[]>;
}): Promise<Case> => {
const apiCall = supertest.post(
`${getSpaceUrlPrefix(auth?.space)}${CASES_URL}/${caseId}/connector/${connectorId}/_push`
@ -674,7 +671,7 @@ export const getAlertsAttachedToCase = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -727,7 +724,7 @@ export const getCasesMetrics = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
features: string[] | string;
query?: Record<string, unknown>;
expectedHttpCode?: number;
@ -774,7 +771,7 @@ export const bulkGetCases = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
ids: string[];
fields?: string[];
expectedHttpCode?: number;
@ -796,7 +793,7 @@ export const searchCases = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
body?: Record<string, unknown>;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -820,13 +817,13 @@ export const replaceCustomField = async ({
auth = { user: superUser, space: null },
headers = {},
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
customFieldId: string;
params: CustomFieldPutRequest;
expectedHttpCode?: number;
auth?: { user: User; space: string | null } | null;
headers?: Record<string, unknown>;
headers?: Record<string, string | string[]>;
}): Promise<CaseCustomField> => {
const apiCall = supertest.put(
`${getSpaceUrlPrefix(

View file

@ -42,7 +42,7 @@ export const getCaseUserActions = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseID: string;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -61,7 +61,7 @@ export const findCaseUserActions = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseID: string;
options?: UserActionFindRequest;
expectedHttpCode?: number;
@ -82,7 +82,7 @@ export const getCaseUserActionStats = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseID: string;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -101,7 +101,7 @@ export const getCaseUsers = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
caseId: string;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };

View file

@ -38,7 +38,7 @@ export const bulkGetUserProfiles = async <T extends string>({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
req: BulkGetUserProfilesParams<T>;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -62,7 +62,7 @@ export const suggestUserProfiles = async ({
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
req: SuggestUserProfilesRequest;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };
@ -89,10 +89,10 @@ export const updateUserProfileAvatar = async ({
expectedHttpCode = 200,
headers = {},
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
req: UserProfileAvatarData;
expectedHttpCode?: number;
headers?: Record<string, unknown>;
headers?: Record<string, string | string[]>;
}): Promise<void> => {
await supertest
.post('/internal/security/user_profile/_data')
@ -106,7 +106,7 @@ export const loginUsers = async ({
supertest,
users = [superUser],
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
users?: User[];
}) => {
const cookies: Cookie[] = [];

View file

@ -52,7 +52,7 @@ export default ({ getService }: FtrProviderContext): void => {
expectedHttpCode = 200,
auth = { user: superUser, space: null },
}: {
superTestService?: SuperTest.SuperTest<SuperTest.Test>;
superTestService?: SuperTest.Agent;
data: object;
expectedHttpCode?: number;
auth?: { user: User; space: string | null };

View file

@ -700,7 +700,7 @@ const createCaseWithFiles = async ({
owner,
auth = { user: superUser, space: null },
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
fileKind: string;
owner: string;
auth?: { user: User; space: string | null };

View file

@ -161,7 +161,7 @@ export default ({ getService }: FtrProviderContext): void => {
});
};
const expectImportToHaveOneCase = async (supertestService: supertest.SuperTest<supertest.Test>) => {
const expectImportToHaveOneCase = async (supertestService: supertest.Agent) => {
const findResponse = await findCases({ supertest: supertestService, query: {} });
expect(findResponse.total).to.eql(1);
expect(findResponse.cases[0].title).to.eql('A case with a connector');

View file

@ -1352,7 +1352,7 @@ const executeConnectorAndVerifyCorrectness = async ({
connectorId,
req,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
connectorId: string;
req: Record<string, unknown>;
}) => {

View file

@ -28,7 +28,7 @@ const getSpaceUrlPrefix = (spaceId?: string): string => {
};
interface SendOptions {
supertestWithoutAuth: SuperTest.SuperTest<SuperTest.Test>;
supertestWithoutAuth: SuperTest.Agent;
auth: { username: string; password: string };
referer?: string;
kibanaVersion?: string;

View file

@ -17,7 +17,7 @@ import { countDownTest } from '../count_down_test';
* @param supertest The supertest client library
*/
export const createAlertsIndex = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog
): Promise<void> => {
await countDownTest(

View file

@ -16,7 +16,7 @@ import { countDownTest } from '../count_down_test';
* For use inside of afterEach blocks of tests
*/
export const deleteAllAlerts = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog,
es: Client,
index: Array<'.alerts-security.alerts-*' | '.preview.alerts-security.alerts-*'> = [

View file

@ -20,7 +20,7 @@ import { getQueryAlertsId } from './get_query_alerts_ids';
* @param ids Rule id
*/
export const getAlertsById = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog,
id: string
): Promise<SearchResponse<DetectionAlert>> => {

View file

@ -23,7 +23,7 @@ import { routeWithNamespace } from '../route_with_namespace';
* @param ids Array of the rule ids
*/
export const getAlertsByIds = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog,
ids: string[],
size?: number,

View file

@ -18,7 +18,7 @@ import { waitFor } from '../wait_for';
* @param numberOfAlerts The number of alerts to wait for, default is 1
*/
export const waitForAlertsToBePresent = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog,
numberOfAlerts = 1,
alertIds: string[],

View file

@ -27,7 +27,7 @@ import { routeWithNamespace } from '../route_with_namespace';
* @param rule The rule to create
*/
export const createRule = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog,
rule: RuleCreateProps,
namespace?: string

View file

@ -19,7 +19,7 @@ import { countDownTest } from '../count_down_test';
* @param supertest The supertest agent.
*/
export const deleteAllRules = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog
): Promise<void> => {
await countDownTest(

View file

@ -17,7 +17,7 @@ import { DETECTION_ENGINE_RULES_URL } from '@kbn/security-solution-plugin/common
* @param ruleId The rule id to delete
*/
export const deleteRule = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
ruleId: string
): Promise<RuleResponse> => {
const response = await supertest

View file

@ -16,7 +16,7 @@ import { waitFor } from '../wait_for';
import { routeWithNamespace } from '../route_with_namespace';
interface WaitForRuleStatusBaseParams {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
log: ToolingLog;
afterDate?: Date;
namespace?: string;

View file

@ -12,7 +12,7 @@ import type { APIEndpoint } from '@kbn/dataset-quality-plugin/server/routes';
import { formatRequest } from '@kbn/server-route-repository';
import type { APIClientRequestParamsOf, APIReturnType } from '@kbn/dataset-quality-plugin/common';
export function createDatasetQualityApiClient(st: supertest.SuperTest<supertest.Test>) {
export function createDatasetQualityApiClient(st: supertest.Agent) {
return async <TEndpoint extends APIEndpoint>(
options: {
type?: 'form-data';

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
export interface IntegrationPackage {
name: string;
@ -26,7 +26,7 @@ export async function installCustomIntegration({
supertest,
customIntegration,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
customIntegration: CustomIntegration;
}) {
const { integrationName, datasets } = customIntegration;
@ -41,7 +41,7 @@ export async function installPackage({
supertest,
pkg,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
pkg: IntegrationPackage;
}) {
const { name, version } = pkg;
@ -56,7 +56,7 @@ export async function uninstallPackage({
supertest,
pkg,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
pkg: IntegrationPackage;
}) {
const { name, version } = pkg;

View file

@ -9,6 +9,7 @@ import fs from 'fs';
import path from 'path';
import expect from '@kbn/expect';
import { INGEST_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server';
import { HTTPError } from 'superagent';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';
@ -167,7 +168,7 @@ export default function (providerContext: FtrProviderContext) {
.type('application/gzip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
expect((res.error as HTTPError).text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Archive seems empty. Assumed content type was application/gzip, check if this matches the archive type."}'
);
});
@ -180,7 +181,7 @@ export default function (providerContext: FtrProviderContext) {
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
expect((res.error as HTTPError).text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Error during extraction of package: Error: end of central directory record signature not found. Assumed content type was application/zip, check if this matches the archive type."}'
);
});
@ -193,7 +194,7 @@ export default function (providerContext: FtrProviderContext) {
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
expect((res.error as HTTPError).text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Package contains more than one top-level directory; top-level directory found: apache-0.1.4; filePath: apache-0.1.3/manifest.yml"}'
);
});
@ -206,7 +207,7 @@ export default function (providerContext: FtrProviderContext) {
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
expect((res.error as HTTPError).text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Manifest file apache-0.1.4/manifest.yml not found in paths."}'
);
});
@ -219,7 +220,7 @@ export default function (providerContext: FtrProviderContext) {
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
expect((res.error as HTTPError).text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Could not parse top-level package manifest at top-level directory apache-0.1.4: YAMLException: bad indentation of a mapping entry at line 2, column 7:\\n name: apache\\n ^."}'
);
});
@ -232,7 +233,7 @@ export default function (providerContext: FtrProviderContext) {
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
expect((res.error as HTTPError).text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Invalid top-level package manifest at top-level directory apache-0.1.4 (package name: apache): one or more fields missing of name, version, description, title, format_version, owner."}'
);
});
@ -245,7 +246,7 @@ export default function (providerContext: FtrProviderContext) {
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
expect((res.error as HTTPError).text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Name thisIsATypo and version 0.1.4 do not match top-level directory apache-0.1.4"}'
);
});

View file

@ -15,7 +15,7 @@ import {
} from '@kbn/fleet-plugin/common';
import { KbnClient } from '@kbn/test';
import { UNINSTALL_TOKENS_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common';
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { FtrProviderContext } from '../api_integration/ftr_provider_context';
export function warnAndSkipTest(mochaContext: Mocha.Context, log: ToolingLog) {
@ -109,7 +109,7 @@ export async function generateAgent(
});
}
export function setPrereleaseSetting(supertest: SuperTest<Test>) {
export function setPrereleaseSetting(supertest: SuperTestAgent) {
before(async () => {
await supertest
.put('/api/fleet/settings')
@ -126,7 +126,7 @@ export function setPrereleaseSetting(supertest: SuperTest<Test>) {
}
export const generateNAgentPolicies = async (
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
number: number,
overwrite?: Partial<CreateAgentPolicyRequest['body']>
): Promise<AgentPolicy[]> => {
@ -142,7 +142,7 @@ export const generateNAgentPolicies = async (
};
export const generateAgentPolicy = async (
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
overwrite?: Partial<CreateAgentPolicyRequest['body']>
): Promise<AgentPolicy> => {
const response = await supertest

View file

@ -237,7 +237,7 @@ export function TransformAPIProvider({ getService }: FtrProviderContext) {
);
const { body, status } = await esSupertest
.put(`/_transform/${transformId}${deferValidation ? '?defer_validation=true' : ''}`)
.set(headers)
.set(headers as Record<string, string>)
.send(transformConfig);
this.assertResponseStatusCode(200, status, body);
} else {

View file

@ -24,7 +24,7 @@ import {
import { FtrProviderContext } from '../../../ftr_provider_context';
const createLogStashDataView = async (
supertest: SuperTest.SuperTest<SuperTest.Test>
supertest: SuperTest.Agent
): Promise<{ data_view: { id: string } }> => {
const { body } = await supertest
.post(`/api/data_views/data_view`)
@ -36,7 +36,7 @@ const createLogStashDataView = async (
};
const deleteLogStashDataView = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
dataViewId: string
): Promise<void> => {
await supertest

View file

@ -48,10 +48,7 @@ export const createSlackConnector = async ({
return connector;
};
export const getConnectorByName = async (
name: string,
supertest: SuperTest.SuperTest<SuperTest.Test>
) => {
export const getConnectorByName = async (name: string, supertest: SuperTest.Agent) => {
const { body } = await supertest
.get(`/api/actions/connectors`)
.set('kbn-xsrf', 'foo')
@ -65,7 +62,7 @@ export async function createRuleWithActionsAndParams(
testRunUuid: string,
params: Record<string, any> = {},
overwrites: Record<string, any> = {},
supertest: SuperTest.SuperTest<SuperTest.Test>
supertest: SuperTest.Agent
) {
return await createAlwaysFiringRule(
{
@ -94,7 +91,7 @@ export async function createRuleWithActionsAndParams(
async function createAlwaysFiringRule(
overwrites: Record<string, any> = {},
supertest: SuperTest.SuperTest<SuperTest.Test>
supertest: SuperTest.Agent
) {
const { body: createdRule } = await supertest
.post(`/api/alerting/rule`)
@ -109,10 +106,7 @@ async function createAlwaysFiringRule(
return createdRule;
}
export async function getAlertSummary(
ruleId: string,
supertest: SuperTest.SuperTest<SuperTest.Test>
) {
export async function getAlertSummary(ruleId: string, supertest: SuperTest.Agent) {
const { body: summary } = await supertest
.get(`/internal/alerting/rule/${encodeURIComponent(ruleId)}/_alert_summary`)
.expect(200);

View file

@ -30,10 +30,7 @@ export const getPackagesArgs = (): string[] => {
export const bundledPackagesLocation = path.join(path.dirname(__filename), '/fixtures/packages');
export function installPackage(
supertest: SuperTest.SuperTest<SuperTest.Test>,
packageName: SupportedPackage
) {
export function installPackage(supertest: SuperTest.Agent, packageName: SupportedPackage) {
const pkg = PACKAGES.find(({ name }) => name === packageName);
const request = supertest
.post('/api/fleet/epm/packages')

View file

@ -15,7 +15,7 @@ import supertest from 'supertest';
import { format } from 'url';
import { Subtract } from 'utility-types';
export function createObservabilityAIAssistantApiClient(st: supertest.SuperTest<supertest.Test>) {
export function createObservabilityAIAssistantApiClient(st: supertest.Agent) {
return <TEndpoint extends ObservabilityAIAssistantAPIEndpoint>(
options: {
type?: 'form-data';
@ -70,17 +70,62 @@ type WithoutPromise<T extends Promise<any>> = Subtract<T, Promise<any>>;
// end(one:string)
// end(one:string, two:string)
// }
// would lose the first signature. This keeps up to four signatures.
// would lose the first signature. This keeps up to eight signatures.
type OverloadedParameters<T> = T extends {
(...args: infer A1): any;
(...args: infer A2): any;
(...args: infer A3): any;
(...args: infer A4): any;
(...args: infer A5): any;
(...args: infer A6): any;
(...args: infer A7): any;
(...args: infer A8): any;
}
? A1 | A2 | A3 | A4 | A5 | A6 | A7 | A8
: T extends {
(...args: infer A1): any;
(...args: infer A2): any;
(...args: infer A3): any;
(...args: infer A4): any;
(...args: infer A5): any;
(...args: infer A6): any;
(...args: infer A7): any;
}
? A1 | A2 | A3 | A4 | A5 | A6 | A7
: T extends {
(...args: infer A1): any;
(...args: infer A2): any;
(...args: infer A3): any;
(...args: infer A4): any;
(...args: infer A5): any;
(...args: infer A6): any;
}
? A1 | A2 | A3 | A4 | A5 | A6
: T extends {
(...args: infer A1): any;
(...args: infer A2): any;
(...args: infer A3): any;
(...args: infer A4): any;
(...args: infer A5): any;
}
? A1 | A2 | A3 | A4 | A5
: T extends {
(...args: infer A1): any;
(...args: infer A2): any;
(...args: infer A3): any;
(...args: infer A4): any;
}
? A1 | A2 | A3 | A4
: T extends { (...args: infer A1): any; (...args: infer A2): any; (...args: infer A3): any }
: T extends {
(...args: infer A1): any;
(...args: infer A2): any;
(...args: infer A3): any;
}
? A1 | A2 | A3
: T extends { (...args: infer A1): any; (...args: infer A2): any }
: T extends {
(...args: infer A1): any;
(...args: infer A2): any;
}
? A1 | A2
: T extends (...args: infer A) => any
? A

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import type { SuperTest, Test } from 'supertest';
import type { Agent as SuperTestAgent } from 'supertest';
import { FtrProviderContext } from '../../common/ftr_provider_context';
export default function ApiTest({ getService }: FtrProviderContext) {
@ -71,7 +71,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});
}
export async function deleteAllActionConnectors(supertest: SuperTest<Test>): Promise<any> {
export async function deleteAllActionConnectors(supertest: SuperTestAgent): Promise<any> {
const res = await supertest.get(`/api/actions/connectors`);
const body = res.body as Array<{ id: string; connector_type_id: string; name: string }>;

View file

@ -24,7 +24,7 @@ export type APIClientRequestParamsOf<TEndpoint extends APIEndpoint> = ClientRequ
TEndpoint
>;
export function createObsApiClient(st: supertest.SuperTest<supertest.Test>) {
export function createObsApiClient(st: supertest.Agent) {
return async <TEndpoint extends APIEndpoint>(
options: {
type?: 'form-data';

View file

@ -15,7 +15,7 @@ import type {
import type { APIEndpoint } from '@kbn/observability-onboarding-plugin/server/routes';
import { formatRequest } from '@kbn/server-route-repository';
export function createObservabilityOnboardingApiClient(st: supertest.SuperTest<supertest.Test>) {
export function createObservabilityOnboardingApiClient(st: supertest.Agent) {
return async <TEndpoint extends APIEndpoint>(
options: {
type?: 'form-data';

View file

@ -10,7 +10,7 @@ import request from 'superagent';
import supertest from 'supertest';
import { format } from 'url';
export function createProfilingApiClient(st: supertest.SuperTest<supertest.Test>) {
export function createProfilingApiClient(st: supertest.Agent) {
return async (options: {
endpoint: string;
params?: {

View file

@ -23,7 +23,7 @@ export type BetterTest = <T extends any>(options: {
* This is useful for tests that expect a 200 response
* It also makes it easier to debug tests that fail because of a 500 response.
*/
export function getBettertest(st: supertest.SuperTest<supertest.Test>): BetterTest {
export function getBettertest(st: supertest.Agent): BetterTest {
return async ({ pathname, method = 'get', query, body }) => {
const url = format({ pathname, query });
@ -60,7 +60,7 @@ export class BetterTestError extends Error {
const req = res.req as any;
super(
`Unhandled BetterTestError:
Status: "${res.status}"
Status: "${res.status}"
Path: "${req.method} ${req.path}"
Body: ${JSON.stringify(res.body)}`
);

View file

@ -5,11 +5,11 @@
* 2.0.
*/
import type { SuperTest } from 'supertest';
import type { Agent as SuperTestAgent } from 'supertest';
import type { Client } from '@elastic/elasticsearch';
import { AUTHENTICATION } from './authentication';
export const createUsersAndRoles = async (es: Client, supertest: SuperTest<any>) => {
export const createUsersAndRoles = async (es: Client, supertest: SuperTestAgent) => {
await supertest
.put('/api/security/role/kibana_legacy_user')
.send({

View file

@ -258,7 +258,7 @@ export function bulkCreateTestSuiteFactory(context: FtrProviderContext) {
const query = test.overwrite ? '?overwrite=true' : '';
await supertest
.post(`${getUrlPrefix(spaceId)}/api/saved_objects/_bulk_create${query}`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.send(requestBody)
.expect(test.responseStatusCode)
.then(test.responseBody);

View file

@ -138,7 +138,7 @@ export function bulkDeleteTestSuiteFactory(context: FtrProviderContext) {
const query = testForce && testForce === true ? '?force=true' : '';
await supertest
.post(`${getUrlPrefix(spaceId)}/api/saved_objects/_bulk_delete${query}`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.send(requestBody)
.expect(test.responseStatusCode)
.then(test.responseBody);

View file

@ -125,7 +125,7 @@ export function bulkGetTestSuiteFactory(context: FtrProviderContext) {
it(`should return ${test.responseStatusCode} ${test.title}`, async () => {
await supertest
.post(`${getUrlPrefix(spaceId)}/api/saved_objects/_bulk_get`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.send(test.request)
.expect(test.responseStatusCode)
.then(test.responseBody);

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { TEST_CASES } from './resolve';
import { SPACES } from '../lib/spaces';
import {
@ -29,7 +29,7 @@ export interface BulkResolveTestCase extends TestCase {
export { TEST_CASES }; // re-export the (non-bulk) resolve test cases
export function bulkResolveTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>) {
export function bulkResolveTestSuiteFactory(esArchiver: any, supertest: SuperTestAgent) {
const expectSavedObjectForbidden = expectResponses.forbiddenTypes('bulk_get');
const expectResponseBody =
(
@ -119,7 +119,7 @@ export function bulkResolveTestSuiteFactory(esArchiver: any, supertest: SuperTes
it(`should return ${test.responseStatusCode} ${test.title}`, async () => {
await supertest
.post(`${getUrlPrefix(spaceId)}/api/saved_objects/_bulk_resolve`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.send(test.request)
.expect(test.responseStatusCode)
.then(test.responseBody);

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases';
import { SPACES } from '../lib/spaces';
import { expectResponses, getUrlPrefix, getTestTitle } from '../lib/saved_object_test_utils';
@ -36,7 +36,7 @@ const createRequest = ({ type, id, namespace }: BulkUpdateTestCase) => ({
...(namespace && { namespace }), // individual "object namespace" string
});
export function bulkUpdateTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>) {
export function bulkUpdateTestSuiteFactory(esArchiver: any, supertest: SuperTestAgent) {
const expectSavedObjectForbidden = expectResponses.forbiddenTypes('bulk_update');
const expectResponseBody =
(
@ -118,7 +118,7 @@ export function bulkUpdateTestSuiteFactory(esArchiver: any, supertest: SuperTest
const requestBody = test.request.map((x) => ({ ...x, ...attrs }));
await supertest
.put(`${getUrlPrefix(spaceId)}/api/saved_objects/_bulk_update`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.send(requestBody)
.expect(test.responseStatusCode)
.then(test.responseBody);

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases';
import { SPACES, ALL_SPACES_ID } from '../lib/spaces';
import {
@ -85,7 +85,7 @@ const createRequest = ({ type, id, initialNamespaces }: CreateTestCase) => ({
initialNamespaces,
});
export function createTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>) {
export function createTestSuiteFactory(esArchiver: any, supertest: SuperTestAgent) {
const expectSavedObjectForbidden = expectResponses.forbiddenTypes('create');
const expectResponseBody =
(testCase: CreateTestCase, user?: TestUser): ExpectResponseBody =>
@ -155,7 +155,7 @@ export function createTestSuiteFactory(esArchiver: any, supertest: SuperTest<any
const query = test.overwrite ? '?overwrite=true' : '';
await supertest
.post(`${getUrlPrefix(spaceId)}/api/saved_objects/${path}${query}`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.send(requestBody)
.expect(test.responseStatusCode)
.then(test.responseBody);

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { SuperTest } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import type { Client } from '@elastic/elasticsearch';
import expect from '@kbn/expect';
import type { SearchTotalHits } from '@elastic/elasticsearch/lib/api/types';
@ -38,7 +38,7 @@ export const TEST_CASES: Record<string, DeleteTestCase> = Object.freeze({
*/
const createRequest = ({ type, id, force }: DeleteTestCase) => ({ type, id, force });
export function deleteTestSuiteFactory(es: Client, esArchiver: any, supertest: SuperTest<any>) {
export function deleteTestSuiteFactory(es: Client, esArchiver: any, supertest: SuperTestAgent) {
const expectSavedObjectForbidden = expectResponses.forbiddenTypes('delete');
const expectResponseBody =
(testCase: DeleteTestCase): ExpectResponseBody =>
@ -118,7 +118,7 @@ export function deleteTestSuiteFactory(es: Client, esArchiver: any, supertest: S
await supertest
.delete(`${getUrlPrefix(spaceId)}/api/saved_objects/${type}/${id}`)
.query({ ...(force && { force }) })
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.expect(test.responseStatusCode)
.then(test.responseBody);
});

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import {
SAVED_OBJECT_TEST_CASES,
CONFLICT_TEST_CASES,
@ -154,7 +154,7 @@ const EMPTY_RESULT = {
missingReferences: [],
};
export function exportTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>) {
export function exportTestSuiteFactory(esArchiver: any, supertest: SuperTestAgent) {
const expectSavedObjectForbiddenBulkGet = expectResponses.forbiddenTypes('bulk_get');
const expectResponseBody =
(testCase: ExportTestCase): ExpectResponseBody =>
@ -259,7 +259,7 @@ export function exportTestSuiteFactory(esArchiver: any, supertest: SuperTest<any
it(`should return ${test.responseStatusCode} ${test.title}`, async () => {
await supertest
.post(`${getUrlPrefix(spaceId)}/api/saved_objects/_export`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.send(test.request)
.expect(test.responseStatusCode)
.then(test.responseBody);

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import querystring from 'querystring';
import {
SAVED_OBJECT_TEST_CASES,
@ -187,7 +187,7 @@ export const createRequest = ({ query }: FindTestCase) => ({ query });
const getTestTitle = ({ failure, title }: FindTestCase) =>
`${failure?.reason || 'success'} ["${title}"]`;
export function findTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>) {
export function findTestSuiteFactory(esArchiver: any, supertest: SuperTestAgent) {
const expectResponseBody =
(testCase: FindTestCase, user?: TestUser): ExpectResponseBody =>
async (response: Record<string, any>) => {
@ -298,7 +298,7 @@ export function findTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>)
await supertest
.get(`${getUrlPrefix(spaceId)}/api/saved_objects/_find${query}`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.expect(test.responseStatusCode)
.then(test.responseBody);
});

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { SuperTest } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases';
import { SPACES } from '../lib/spaces';
import {
@ -25,7 +25,7 @@ export type GetTestCase = TestCase;
const DOES_NOT_EXIST = Object.freeze({ type: 'dashboard', id: 'does-not-exist' });
export const TEST_CASES: Record<string, GetTestCase> = Object.freeze({ ...CASES, DOES_NOT_EXIST });
export function getTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>) {
export function getTestSuiteFactory(esArchiver: any, supertest: SuperTestAgent) {
const expectSavedObjectForbidden = expectResponses.forbiddenTypes('get');
const expectResponseBody =
(testCase: GetTestCase): ExpectResponseBody =>
@ -81,7 +81,7 @@ export function getTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>)
const { type, id } = test.request;
await supertest
.get(`${getUrlPrefix(spaceId)}/api/saved_objects/${type}/${id}`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.expect(test.responseStatusCode)
.then(test.responseBody);
});

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import type { Client } from '@elastic/elasticsearch';
import type { SavedObjectReference } from '@kbn/core/server';
import { SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases';
@ -121,7 +121,7 @@ export const importTestCaseFailures = {
condition !== false ? { failureType: 'missing_references' } : {},
};
export function importTestSuiteFactory(es: Client, esArchiver: any, supertest: SuperTest<any>) {
export function importTestSuiteFactory(es: Client, esArchiver: any, supertest: SuperTestAgent) {
const expectSavedObjectForbidden = (action: string, typeOrTypes: string | string[]) =>
expectResponses.forbiddenTypes(action)(typeOrTypes);
const expectResponseBody =
@ -310,7 +310,7 @@ export function importTestSuiteFactory(es: Client, esArchiver: any, supertest: S
: '';
await supertest
.post(`${getUrlPrefix(spaceId)}/api/saved_objects/_import${query}`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.attach('file', Buffer.from(requestBody, 'utf8'), 'export.ndjson')
.expect(test.responseStatusCode)
.then(test.responseBody);

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases';
import { SPACES } from '../lib/spaces';
import {
@ -70,7 +70,7 @@ export const TEST_CASES = Object.freeze({
HIDDEN: CASES.HIDDEN,
});
export function resolveTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>) {
export function resolveTestSuiteFactory(esArchiver: any, supertest: SuperTestAgent) {
const expectSavedObjectForbidden = expectResponses.forbiddenTypes('bulk_get');
const expectResponseBody =
(testCase: ResolveTestCase): ExpectResponseBody =>
@ -135,7 +135,7 @@ export function resolveTestSuiteFactory(esArchiver: any, supertest: SuperTest<an
const { type, id } = test.request;
await supertest
.get(`${getUrlPrefix(spaceId)}/api/saved_objects/resolve/${type}/${id}`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.expect(test.responseStatusCode)
.then(test.responseBody);
});

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import type { Client } from '@elastic/elasticsearch';
import type { SavedObjectReference, SavedObjectsImportRetry } from '@kbn/core/server';
import { SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases';
@ -197,7 +197,7 @@ export const resolveImportErrorsTestCaseFailures = {
export function resolveImportErrorsTestSuiteFactory(
es: Client,
esArchiver: any,
supertest: SuperTest<any>
supertest: SuperTestAgent
) {
const expectSavedObjectForbidden = (action: string, typeOrTypes: string | string[]) =>
expectResponses.forbiddenTypes(action)(typeOrTypes);
@ -373,7 +373,7 @@ export function resolveImportErrorsTestSuiteFactory(
const query = test.createNewCopies ? '?createNewCopies=true' : '';
await supertest
.post(`${getUrlPrefix(spaceId)}/api/saved_objects/_resolve_import_errors${query}`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.field('retries', JSON.stringify(test.request.retries))
.attach('file', Buffer.from(requestBody, 'utf8'), 'export.ndjson')
.expect(test.responseStatusCode)

View file

@ -6,7 +6,7 @@
*/
import expect from '@kbn/expect';
import { SuperTest } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases';
import { SPACES } from '../lib/spaces';
import { expectResponses, getUrlPrefix, getTestTitle } from '../lib/saved_object_test_utils';
@ -34,7 +34,7 @@ export const TEST_CASES: Record<string, UpdateTestCase> = Object.freeze({
const createRequest = ({ type, id, upsert }: UpdateTestCase) => ({ type, id, upsert });
export function updateTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>) {
export function updateTestSuiteFactory(esArchiver: any, supertest: SuperTestAgent) {
const expectSavedObjectForbidden = expectResponses.forbiddenTypes('update');
const expectResponseBody =
(testCase: UpdateTestCase): ExpectResponseBody =>
@ -94,7 +94,7 @@ export function updateTestSuiteFactory(esArchiver: any, supertest: SuperTest<any
const requestBody = { attributes, ...(upsert && { upsert: attributes }) };
await supertest
.put(`${getUrlPrefix(spaceId)}/api/saved_objects/${type}/${id}`)
.auth(user?.username, user?.password)
.auth(user?.username!, user?.password!)
.send(requestBody)
.expect(test.responseStatusCode)
.then(test.responseBody);

View file

@ -43,7 +43,7 @@ interface Host {
* @returns The array of hosts sorted
*/
export const getHostHits = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog,
id: string
): Promise<Host[]> => {

View file

@ -10,10 +10,7 @@ import supertest from 'supertest';
import { NodeMetrics } from '@kbn/task-manager-plugin/server/routes/metrics';
import { RetryService } from '@kbn/ftr-common-functional-services';
export const getMetricsRequest = (
request: supertest.SuperTest<supertest.Test>,
reset: boolean = false
) => {
export const getMetricsRequest = (request: supertest.Agent, reset: boolean = false) => {
return request
.get(`/api/task_manager/metrics${reset ? '' : '?reset=false'}`)
.set('kbn-xsrf', 'foo')
@ -22,7 +19,7 @@ export const getMetricsRequest = (
};
export const getMetricsWithRetry = (
request: supertest.SuperTest<supertest.Test>,
request: supertest.Agent,
retry: RetryService,
reset: boolean = false,
callback?: (metrics: NodeMetrics) => boolean

View file

@ -17,9 +17,7 @@ import { getWebHookAction } from './get_web_hook_action';
*
* @param supertest The supertest deps
*/
export const createWebHookRuleAction = async (
supertest: SuperTest.SuperTest<SuperTest.Test>
): Promise<RuleAction> => {
export const createWebHookRuleAction = async (supertest: SuperTest.Agent): Promise<RuleAction> => {
return (
await supertest
.post('/api/actions/action')

View file

@ -18,7 +18,7 @@ import { refreshIndex } from '..';
import { getAlertsByIds, waitForRuleStatus } from '../../../../../common/utils/security_solution';
export type GetAlerts = (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog,
es: Client,
rule: RuleResponse,

View file

@ -21,7 +21,7 @@ export const finalizeAlertsMigration = async ({
supertest,
log,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
log: ToolingLog;
migrationIds: string[];
}): Promise<FinalizeMigrationResponse[]> => {

View file

@ -21,7 +21,7 @@ export const startAlertsMigration = async ({
supertest,
log,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
log: ToolingLog;
indices: string[];
}): Promise<CreateMigrationResponse[]> => {

View file

@ -11,7 +11,7 @@ import type SuperTest from 'supertest';
import { waitFor } from '../../../../../common/utils/security_solution';
export const waitForAlertToComplete = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog,
id: string
): Promise<void> => {

View file

@ -15,7 +15,7 @@ export interface CreateConnectorBody {
}
export async function createConnector(
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
connector: CreateConnectorBody,
id = ''
): Promise<string> {

View file

@ -7,9 +7,6 @@
import type SuperTest from 'supertest';
export function deleteConnector(
supertest: SuperTest.SuperTest<SuperTest.Test>,
connectorId: string
): SuperTest.Test {
export function deleteConnector(supertest: SuperTest.Agent, connectorId: string): SuperTest.Test {
return supertest.delete(`/api/actions/connector/${connectorId}`).set('kbn-xsrf', 'foo');
}

View file

@ -9,7 +9,7 @@ import { Connector } from '@kbn/actions-plugin/server/application/connector/type
import type SuperTest from 'supertest';
export async function getConnector(
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
connectorId: string
): Promise<Connector> {
const response = await supertest

View file

@ -22,7 +22,7 @@ import { EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
* @param log The tooling logger
*/
export const createExceptionListItem = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog,
exceptionListItem: CreateExceptionListItemSchema
): Promise<ExceptionListItemSchema> => {

View file

@ -27,7 +27,7 @@ import { createExceptionList } from './create_exception_list';
* @param osTypes The os types to optionally add or not to add to the container
*/
export const createContainerWithEndpointEntries = async (
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
log: ToolingLog,
endpointEntries: Array<{
entries: NonEmptyEntriesArray;

Some files were not shown because too many files have changed in this diff Show more