diff --git a/packages/kbn-mock-idp-plugin/server/index.ts b/packages/kbn-mock-idp-plugin/server/index.ts index 4fc152eaeaf31..04525e09ee310 100644 --- a/packages/kbn-mock-idp-plugin/server/index.ts +++ b/packages/kbn-mock-idp-plugin/server/index.ts @@ -17,6 +17,7 @@ export const config = { // The plugin should only be enabled in Serverless. enabled: offeringBasedSchema({ serverless: schema.boolean({ defaultValue: true }), + traditional: schema.boolean({ defaultValue: false }), options: { defaultValue: false }, }), }), diff --git a/packages/kbn-mock-idp-plugin/server/plugin.ts b/packages/kbn-mock-idp-plugin/server/plugin.ts index 82a416e390122..27d5b96a4cbfc 100644 --- a/packages/kbn-mock-idp-plugin/server/plugin.ts +++ b/packages/kbn-mock-idp-plugin/server/plugin.ts @@ -11,7 +11,11 @@ import type { PluginInitializer, Plugin } from '@kbn/core-plugins-server'; import { schema } from '@kbn/config-schema'; import type { TypeOf } from '@kbn/config-schema'; import { MOCK_IDP_LOGIN_PATH, MOCK_IDP_LOGOUT_PATH, createSAMLResponse } from '@kbn/mock-idp-utils'; -import { SERVERLESS_ROLES_ROOT_PATH, readRolesFromResource } from '@kbn/es'; +import { + SERVERLESS_ROLES_ROOT_PATH, + STATEFUL_ROLES_ROOT_PATH, + readRolesFromResource, +} from '@kbn/es'; import { resolve } from 'path'; import { CloudSetup } from '@kbn/cloud-plugin/server'; @@ -42,6 +46,11 @@ const readServerlessRoles = (projectType: string) => { } }; +const readStatefulRoles = () => { + const rolesResourcePath = resolve(STATEFUL_ROLES_ROOT_PATH, 'roles.yml'); + return readRolesFromResource(rolesResourcePath); +}; + export type CreateSAMLResponseParams = TypeOf; export const plugin: PluginInitializer< @@ -73,22 +82,18 @@ export const plugin: PluginInitializer< options: { authRequired: false }, }, (context, request, response) => { - const projectType = plugins.cloud.serverless?.projectType; - if (!projectType) { - return response.customError({ statusCode: 500, body: 'projectType is not defined' }); - } else { - try { - if (roles.length === 0) { - roles.push(...readServerlessRoles(projectType)); - } - return response.ok({ - body: { - roles, - }, - }); - } catch (err) { - return response.customError({ statusCode: 500, body: err.message }); + try { + if (roles.length === 0) { + const projectType = plugins.cloud?.serverless?.projectType; + roles.push(...(projectType ? readServerlessRoles(projectType) : readStatefulRoles())); } + return response.ok({ + body: { + roles, + }, + }); + } catch (err) { + return response.customError({ statusCode: 500, body: err.message }); } } ); diff --git a/x-pack/test/api_integration/deployment_agnostic/default_configs/stateful.config.base.ts b/x-pack/test/api_integration/deployment_agnostic/default_configs/stateful.config.base.ts index 964627effe28b..66a23b2e15bf8 100644 --- a/x-pack/test/api_integration/deployment_agnostic/default_configs/stateful.config.base.ts +++ b/x-pack/test/api_integration/deployment_agnostic/default_configs/stateful.config.base.ts @@ -43,12 +43,19 @@ export function createStatefulTestConfig