Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Oct 31, 2024
1 parent e36f1f8 commit f08fcd0
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 92 deletions.
173 changes: 87 additions & 86 deletions x-pack/plugins/fleet/server/routes/epm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,37 +287,6 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
getFileHandler
);

router.versioned
.get({
path: EPM_API_ROUTES.INFO_WITHOUT_VERSION_PATTERN,
fleetAuthz: (fleetAuthz: FleetAuthz): boolean =>
calculateRouteAuthz(
fleetAuthz,
getRouteRequiredAuthz('get', EPM_API_ROUTES.INFO_WITHOUT_VERSION_PATTERN)
).granted,
description: `Get package`,
options: {
tags: ['oas-tag:Elastic Package Manager (EPM)'],
},
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: {
request: GetInfoRequestSchema,
response: {
200: {
body: () => GetInfoResponseSchema,
},
400: {
body: genericErrorResponse,
},
},
},
},
getInfoHandler
);

router.versioned
.get({
path: EPM_API_ROUTES.INFO_PATTERN,
Expand Down Expand Up @@ -375,32 +344,6 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
},
updatePackageHandler
);
router.versioned
.post({
path: EPM_API_ROUTES.INSTALL_FROM_REGISTRY_WITHOUT_VERSION_PATTERN,
fleetAuthz: INSTALL_PACKAGES_AUTHZ,
description: `Install package from registry`,
options: {
tags: ['oas-tag:Elastic Package Manager (EPM)'],
},
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: {
request: InstallPackageFromRegistryRequestSchema,
response: {
200: {
body: () => InstallPackageResponseSchema,
},
400: {
body: genericErrorResponse,
},
},
},
},
installPackageFromRegistryHandler
);

router.versioned
.post({
Expand Down Expand Up @@ -582,7 +525,7 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType

router.versioned
.delete({
path: EPM_API_ROUTES.DELETE_PATTERN_WITHOUT_VERSION_PATTERN,
path: EPM_API_ROUTES.DELETE_PATTERN,
fleetAuthz: {
integrations: { removePackages: true },
},
Expand Down Expand Up @@ -611,12 +554,10 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
);

router.versioned
.delete({
path: EPM_API_ROUTES.DELETE_PATTERN,
fleetAuthz: {
integrations: { removePackages: true },
},
description: `Delete package`,
.get({
path: EPM_API_ROUTES.VERIFICATION_KEY_ID,
fleetAuthz: READ_PACKAGE_INFO_AUTHZ,
description: `Get a package signature verification key ID`,
options: {
tags: ['oas-tag:Elastic Package Manager (EPM)'],
},
Expand All @@ -625,26 +566,52 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
{
version: API_VERSIONS.public.v1,
validate: {
request: DeletePackageRequestSchema,
request: {},
response: {
200: {
body: () => DeletePackageResponseSchema,
body: () => GetVerificationKeyIdResponseSchema,
},
400: {
body: genericErrorResponse,
},
},
},
},

deletePackageHandler
getVerificationKeyIdHandler
);

router.versioned
.get({
path: EPM_API_ROUTES.VERIFICATION_KEY_ID,
path: EPM_API_ROUTES.DATA_STREAMS_PATTERN,
fleetAuthz: READ_PACKAGE_INFO_AUTHZ,
description: `Get a package signature verification key ID`,
description: `List data streams`,
options: {
tags: ['oas-tag:Data streams'],
},
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: {
request: GetDataStreamsRequestSchema,
response: {
200: {
body: () => GetDataStreamsResponseSchema,
},
400: {
body: genericErrorResponse,
},
},
},
},
getDataStreamsHandler
);

router.versioned
.post({
path: EPM_API_ROUTES.BULK_ASSETS_PATTERN,
fleetAuthz: READ_PACKAGE_INFO_AUTHZ,
description: `Bulk get assets`,
options: {
tags: ['oas-tag:Elastic Package Manager (EPM)'],
},
Expand All @@ -653,52 +620,56 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
{
version: API_VERSIONS.public.v1,
validate: {
request: {},
request: GetBulkAssetsRequestSchema,
response: {
200: {
body: () => GetVerificationKeyIdResponseSchema,
body: () => GetBulkAssetsResponseSchema,
},
400: {
body: genericErrorResponse,
},
},
},
},
getVerificationKeyIdHandler
getBulkAssetsHandler
);

router.versioned
.get({
path: EPM_API_ROUTES.DATA_STREAMS_PATTERN,
fleetAuthz: READ_PACKAGE_INFO_AUTHZ,
description: `List data streams`,
path: EPM_API_ROUTES.INFO_WITHOUT_VERSION_PATTERN,
fleetAuthz: (fleetAuthz: FleetAuthz): boolean =>
calculateRouteAuthz(
fleetAuthz,
getRouteRequiredAuthz('get', EPM_API_ROUTES.INFO_WITHOUT_VERSION_PATTERN)
).granted,
description: `Get package`,
options: {
tags: ['oas-tag:Data streams'],
tags: ['oas-tag:Elastic Package Manager (EPM)'],
},
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: {
request: GetDataStreamsRequestSchema,
request: GetInfoRequestSchema,
response: {
200: {
body: () => GetDataStreamsResponseSchema,
body: () => GetInfoResponseSchema,
},
400: {
body: genericErrorResponse,
},
},
},
},
getDataStreamsHandler
getInfoHandler
);

router.versioned
.post({
path: EPM_API_ROUTES.BULK_ASSETS_PATTERN,
fleetAuthz: READ_PACKAGE_INFO_AUTHZ,
description: `Bulk get assets`,
path: EPM_API_ROUTES.INSTALL_FROM_REGISTRY_WITHOUT_VERSION_PATTERN,
fleetAuthz: INSTALL_PACKAGES_AUTHZ,
description: `Install package from registry`,
options: {
tags: ['oas-tag:Elastic Package Manager (EPM)'],
},
Expand All @@ -707,18 +678,48 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
{
version: API_VERSIONS.public.v1,
validate: {
request: GetBulkAssetsRequestSchema,
request: InstallPackageFromRegistryRequestSchema,
response: {
200: {
body: () => GetBulkAssetsResponseSchema,
body: () => InstallPackageResponseSchema,
},
400: {
body: genericErrorResponse,
},
},
},
},
getBulkAssetsHandler
installPackageFromRegistryHandler
);

router.versioned
.delete({
path: EPM_API_ROUTES.DELETE_PATTERN_WITHOUT_VERSION_PATTERN,
fleetAuthz: {
integrations: { removePackages: true },
},
description: `Delete package`,
options: {
tags: ['oas-tag:Elastic Package Manager (EPM)'],
},
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: {
request: DeletePackageRequestSchema,
response: {
200: {
body: () => DeletePackageResponseSchema,
},
400: {
body: genericErrorResponse,
},
},
},
},

deletePackageHandler
);

// Update transforms with es-secondary-authorization headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export async function deleteEndpointFleetPackage(supertest: SuperTest.Agent) {
.set('elastic-api-version', '2023-10-31')
.send();

if (resp.status === 200 && resp.body.response.status === 'installed') {
if (resp.status === 200 && resp.body.item.status === 'installed') {
await supertest
.delete(epmRouteService.getRemovePath(ENDPOINT_PACKAGE_NAME, resp.body.response.version))
.delete(epmRouteService.getRemovePath(ENDPOINT_PACKAGE_NAME, resp.body.item.version))
.set('kbn-xsrf', 'true')
.send({ force: true });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ export async function deletePrebuiltRulesFleetPackage(supertest: SuperTest.Agent
.set('elastic-api-version', '2023-10-31')
.send();

if (resp.status === 200 && resp.body.response.status === 'installed') {
if (resp.status === 200 && resp.body.item.status === 'installed') {
await supertest
.delete(
epmRouteService.getRemovePath(PREBUILT_RULES_PACKAGE_NAME, resp.body.response.version)
)
.delete(epmRouteService.getRemovePath(PREBUILT_RULES_PACKAGE_NAME, resp.body.item.version))
.set('kbn-xsrf', 'true')
.send({ force: true });
}
Expand Down

0 comments on commit f08fcd0

Please sign in to comment.