Skip to content

Commit

Permalink
add mock for getSecurityLicenseMock
Browse files Browse the repository at this point in the history
  • Loading branch information
eokoneyo committed Oct 8, 2024
1 parent 31610e2 commit e7cee74
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import { spacesManagerMock } from '../../../spaces_manager/spaces_manager.mock';
import { getPrivilegeAPIClientMock } from '../../privilege_api_client.mock';
import { getRolesAPIClientMock } from '../../roles_api_client.mock';
import { getSecurityLicenseMock } from '../../security_license.mock';

const http = httpServiceMock.createStartContract();
const notifications = notificationServiceMock.createStartContract();
Expand Down Expand Up @@ -62,6 +63,7 @@ const SUTProvider = ({
getUrlForApp: (_) => _,
getRolesAPIClient: getRolesAPIClientMock,
getPrivilegesAPIClient: getPrivilegeAPIClientMock,
getSecurityLicense: getSecurityLicenseMock,
navigateToUrl: jest.fn(),
capabilities,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { managementPluginMock } from '@kbn/management-plugin/public/mocks';

import { ManagementService } from './management_service';
import { getRolesAPIClientMock } from './roles_api_client.mock';
import { getSecurityLicenseMock } from './security_license.mock';
import { EventTracker } from '../analytics';
import type { ConfigType } from '../config';
import type { PluginsStart } from '../plugin';
Expand Down Expand Up @@ -49,6 +50,7 @@ describe('ManagementService', () => {
logger,
getRolesAPIClient: getRolesAPIClientMock,
getPrivilegesAPIClient: jest.fn(),
getSecurityLicense: getSecurityLicenseMock,
eventTracker,
isServerless: false,
});
Expand All @@ -73,6 +75,7 @@ describe('ManagementService', () => {
logger,
getRolesAPIClient: getRolesAPIClientMock,
getPrivilegesAPIClient: jest.fn(),
getSecurityLicense: getSecurityLicenseMock,
eventTracker,
isServerless: false,
});
Expand All @@ -98,6 +101,7 @@ describe('ManagementService', () => {
logger,
getRolesAPIClient: jest.fn(),
getPrivilegesAPIClient: jest.fn(),
getSecurityLicense: getSecurityLicenseMock,
eventTracker,
isServerless: false,
});
Expand Down
49 changes: 49 additions & 0 deletions x-pack/plugins/spaces/public/management/security_license.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { BehaviorSubject, type Observable } from 'rxjs';

import type { SecurityLicense } from '@kbn/security-plugin-types-public';

type SecurityLicenseFeatures = SecurityLicense['features$'] extends Observable<infer P> ? P : never;

export const createSecurityLicenseMock = ({
securityFeaturesConfig,
}: {
securityFeaturesConfig: SecurityLicenseFeatures;
}): SecurityLicense => {
return {
isLicenseAvailable: jest.fn(),
isEnabled: jest.fn(),
getFeatures: jest.fn(),
getUnavailableReason: jest.fn(),
hasAtLeast: jest.fn(),
getLicenseType: jest.fn(),
features$: new BehaviorSubject<SecurityLicenseFeatures>(securityFeaturesConfig),
};
};

export const getSecurityLicenseMock = jest.fn().mockResolvedValue(
createSecurityLicenseMock({
securityFeaturesConfig: {
showLinks: true,
showLogin: true,
allowLogin: true,
allowRbac: true,
allowFips: true,
showRoleMappingsManagement: true,
allowAccessAgreement: true,
allowAuditLogging: true,
allowSubFeaturePrivileges: true,
allowRoleFieldLevelSecurity: true,
allowRoleDocumentLevelSecurity: true,
allowRoleRemoteIndexPrivileges: true,
allowRemoteClusterPrivileges: true,
allowUserProfileCollaboration: true,
},
})
);

0 comments on commit e7cee74

Please sign in to comment.