Skip to content

Commit

Permalink
Resolves SO extension mock references.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeramysoucy committed Oct 12, 2022
1 parent 1bcbbdc commit 1f277e6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { collectMultiNamespaceReferences } from './collect_multi_namespace_references';
import type { CreatePointInTimeFinderFn } from './point_in_time_finder';
import { AuditAction, ISavedObjectsSecurityExtension } from '@kbn/core-saved-objects-server';
import { extensionsMock } from './extensions.test.mock';

import {
authMap,
enforceError,
Expand All @@ -39,6 +39,7 @@ import {
setupEnforceSuccess,
setupRedactPassthrough,
} from './repository.common.test';
import { savedObjectsExtensionsMock } from '@kbn/core-saved-objects-api-server-mocks';

const SPACES = ['default', 'another-space'];
const VERSION_PROPS = { _seq_no: 1, _primary_term: 1 };
Expand Down Expand Up @@ -465,7 +466,7 @@ describe('collectMultiNamespaceReferences', () => {
});

describe('with security enabled', () => {
const mockSecurityExt = extensionsMock.createSecurityExtension();
const mockSecurityExt = savedObjectsExtensionsMock.createSecurityExtension();
const obj1 = { type: MULTI_NAMESPACE_OBJ_TYPE_1, id: 'id-1' };
const obj2 = { type: MULTI_NAMESPACE_OBJ_TYPE_1, id: 'id-2' };
const obj3 = { type: MULTI_NAMESPACE_OBJ_TYPE_1, id: 'id-3' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
ISavedObjectsSecurityExtension,
ISavedObjectTypeRegistry,
} from '@kbn/core-saved-objects-server';
import { savedObjectsExtensionsMock } from '@kbn/core-saved-objects-api-server-mocks';
import {
authMap,
enforceError,
Expand All @@ -44,6 +43,7 @@ import {
setupEnforceSuccess,
setupRedactPassthrough,
} from './repository.common.test';
import { savedObjectsExtensionsMock } from '@kbn/core-saved-objects-api-server-mocks';

const VERSION_PROPS = { _seq_no: 1, _primary_term: 1 };
const OBJ_TYPE = 'obj-type';
Expand Down Expand Up @@ -398,7 +398,7 @@ describe('internalBulkResolve', () => {
{ type: OBJ_TYPE, id: '11' }, // non encryptable type
{ type: ENCRYPTED_TYPE, id: '12' }, // encryptable type
];
const mockEncryptionExt = extensionsMock.createEncryptionExtension();
const mockEncryptionExt = savedObjectsExtensionsMock.createEncryptionExtension();
const params = setup(objects, { namespace }, { encryptionExt: mockEncryptionExt });
mockBulkResults(
// No alias matches
Expand Down Expand Up @@ -448,7 +448,7 @@ describe('internalBulkResolve', () => {
} as SavedObject;
});

mockSecurityExt = extensionsMock.createSecurityExtension();
mockSecurityExt = savedObjectsExtensionsMock.createSecurityExtension();
params = setup(objects, { namespace }, { securityExt: mockSecurityExt });

mockBulkResults(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
TypeIdTuple,
updateSuccess,
} from './repository.common.test';
import { extensionsMock } from './extensions.test.mock';
import { savedObjectsExtensionsMock } from '@kbn/core-saved-objects-api-server-mocks';

// BEWARE: The SavedObjectClient depends on the implementation details of the SavedObjectsRepository
// so any breaking changes to this repository are considered breaking changes to the SavedObjectsClient.
Expand Down Expand Up @@ -117,7 +117,7 @@ describe('SavedObjectsRepository Encryption Extension', () => {
serializer = createSpySerializer(registry);

// create a mock saved objects encryption extension
mockEncryptionExt = extensionsMock.createEncryptionExtension();
mockEncryptionExt = savedObjectsExtensionsMock.createEncryptionExtension();

mockGetCurrentTime.mockReturnValue(mockTimestamp);
mockGetSearchDsl.mockClear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
SavedObjectsRawDocSource,
} from '@kbn/core-saved-objects-server';
import { kibanaMigratorMock } from '../mocks';
import { extensionsMock } from './extensions.test.mock';
import {
createRegistry,
createDocumentMigrator,
Expand Down Expand Up @@ -64,6 +63,7 @@ import {
bulkUpdateSuccess,
expectUpdateResult,
} from './repository.common.test';
import { savedObjectsExtensionsMock } from '@kbn/core-saved-objects-api-server-mocks';

// BEWARE: The SavedObjectClient depends on the implementation details of the SavedObjectsRepository
// so any breaking changes to this repository are considered breaking changes to the SavedObjectsClient.
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('SavedObjectsRepository Security Extension', () => {
serializer = createSpySerializer(registry);

// create a mock saved objects encryption extension
mockSecurityExt = extensionsMock.createSecurityExtension();
mockSecurityExt = savedObjectsExtensionsMock.createSecurityExtension();

mockGetCurrentTime.mockReturnValue(mockTimestamp);
mockGetSearchDsl.mockClear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
} from '@kbn/core-saved-objects-server';
import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server';
import { kibanaMigratorMock } from '../mocks';
import { extensionsMock } from './extensions.test.mock';
import {
createRegistry,
createDocumentMigrator,
Expand All @@ -56,6 +55,7 @@ import {
setupCheckUnauthorized,
generateIndexPatternSearchResults,
} from './repository.common.test';
import { savedObjectsExtensionsMock } from '@kbn/core-saved-objects-api-server-mocks';

// BEWARE: The SavedObjectClient depends on the implementation details of the SavedObjectsRepository
// so any breaking changes to this repository are considered breaking changes to the SavedObjectsClient.
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('SavedObjectsRepository Spaces Extension', () => {
serializer = createSpySerializer(registry);

// create a mock saved objects spaces extension
mockSpacesExt = extensionsMock.createSpacesExtension();
mockSpacesExt = savedObjectsExtensionsMock.createSpacesExtension();

mockGetCurrentTime.mockReturnValue(mockTimestamp);
mockGetSearchDsl.mockClear();
Expand Down Expand Up @@ -812,8 +812,8 @@ describe('SavedObjectsRepository Spaces Extension', () => {
// create a mock serializer "shim" so we can track function calls, but use the real serializer's implementation
serializer = createSpySerializer(registry);
// create a mock extensions
mockSpacesExt = extensionsMock.createSpacesExtension();
mockSecurityExt = extensionsMock.createSecurityExtension();
mockSpacesExt = savedObjectsExtensionsMock.createSpacesExtension();
mockSecurityExt = savedObjectsExtensionsMock.createSecurityExtension();
mockGetCurrentTime.mockReturnValue(mockTimestamp);
mockGetSearchDsl.mockClear();
repository = instantiateRepository();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
SECURITY_EXTENSION_ID,
SPACES_EXTENSION_ID,
} from '@kbn/core-saved-objects-server';
import { extensionsMock } from './extensions.test.mock';
import { KibanaRequest } from '@kbn/core-http-server';
import { savedObjectsExtensionsMock } from '@kbn/core-saved-objects-api-server-mocks';

/**
* @internal only used for unit tests
Expand Down Expand Up @@ -110,19 +110,19 @@ describe(`allows extensions to be excluded`, () => {
const typeRegistry = typeRegistryMock.create();
const defaultClientFactoryMock = jest.fn().mockReturnValue(defaultClient);

const mockEncryptionExt = extensionsMock.createEncryptionExtension();
const mockEncryptionExt = savedObjectsExtensionsMock.createEncryptionExtension();
const encryptionExtFactory: SavedObjectsEncryptionExtensionFactory = (params: {
typeRegistry: ISavedObjectTypeRegistry;
request: KibanaRequest;
}) => mockEncryptionExt;

const mockSpacesExt = extensionsMock.createSpacesExtension();
const mockSpacesExt = savedObjectsExtensionsMock.createSpacesExtension();
const spacesExtFactory: SavedObjectsSpacesExtensionFactory = (params: {
typeRegistry: ISavedObjectTypeRegistry;
request: KibanaRequest;
}) => mockSpacesExt;

const mockSecurityExt = extensionsMock.createSecurityExtension();
const mockSecurityExt = savedObjectsExtensionsMock.createSecurityExtension();
const securityExtFactory: SavedObjectsSecurityExtensionFactory = (params: {
typeRegistry: ISavedObjectTypeRegistry;
request: KibanaRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks';
import type { UpdateObjectsSpacesParams } from './update_objects_spaces';
import { updateObjectsSpaces } from './update_objects_spaces';
import { AuditAction, ISavedObjectsSecurityExtension } from '@kbn/core-saved-objects-server';
import { extensionsMock } from './extensions.test.mock';
import {
authMap,
checkAuthError,
Expand All @@ -39,6 +38,7 @@ import {
setupEnforceSuccess,
setupRedactPassthrough,
} from './repository.common.test';
import { savedObjectsExtensionsMock } from '@kbn/core-saved-objects-api-server-mocks';

type SetupParams = Partial<
Pick<UpdateObjectsSpacesParams, 'objects' | 'spacesToAdd' | 'spacesToRemove' | 'options'>
Expand Down Expand Up @@ -659,7 +659,7 @@ describe('#updateObjectsSpaces', () => {
const obj1 = { type: SHAREABLE_OBJ_TYPE, id: 'id-1' };
const objects = [obj1];
const spacesToAdd = ['foo-space'];
mockSecurityExt = extensionsMock.createSecurityExtension();
mockSecurityExt = savedObjectsExtensionsMock.createSecurityExtension();
params = setup({ objects, spacesToAdd }, mockSecurityExt);
mockMgetResults({ found: true, namespaces: [EXISTING_SPACE] }); // result for obj1
mockBulkResults({ error: false }); // result for obj1
Expand Down Expand Up @@ -752,7 +752,7 @@ describe('#updateObjectsSpaces', () => {
const spacesToRemove = [EXISTING_SPACE];

beforeEach(() => {
mockSecurityExt = extensionsMock.createSecurityExtension();
mockSecurityExt = savedObjectsExtensionsMock.createSecurityExtension();
params = setup({ objects, spacesToAdd, spacesToRemove }, mockSecurityExt);
mockMgetResults(
{ found: true, namespaces: [ALL_NAMESPACES_STRING, otherSpace] }, // result for obj1 -- will not be changed
Expand Down Expand Up @@ -835,7 +835,7 @@ describe('#updateObjectsSpaces', () => {
const objects = [obj1, obj2, obj3, obj4];

const setupForAllSpaces = (spacesToAdd: string[], spacesToRemove: string[]) => {
mockSecurityExt = extensionsMock.createSecurityExtension();
mockSecurityExt = savedObjectsExtensionsMock.createSecurityExtension();
params = setup({ objects, spacesToAdd, spacesToRemove }, mockSecurityExt);
mockMgetResults(
{ found: true, namespaces: [ALL_NAMESPACES_STRING, otherSpace] }, // result for obj1 -- will not be changed
Expand Down

0 comments on commit 1f277e6

Please sign in to comment.