Skip to content

Commit

Permalink
update encryption extension test
Browse files Browse the repository at this point in the history
  • Loading branch information
SiddharthMantri committed Oct 31, 2024
1 parent 67ca7d0 commit 58d2b2d
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,25 @@ describe('SavedObjectsRepository Encryption Extension', () => {
).resolves.not.toThrowError();
});

it('allows to opt-out of random ID enforcement', async () => {
mockEncryptionExt.isEncryptableType.mockReturnValue(true);
mockEncryptionExt.shouldEnforceRandomId.mockReturnValue(false);
mockEncryptionExt.decryptOrStripResponseAttributes.mockResolvedValue({
...encryptedSO,
...decryptedStrippedAttributes,
});

const result = await repository.create(encryptedSO.type, encryptedSO.attributes, {
id: encryptedSO.id,
version: mockVersion,
});

expect(client.create).toHaveBeenCalled();
expect(mockEncryptionExt.isEncryptableType).toHaveBeenCalledWith(encryptedSO.type);
expect(mockEncryptionExt.shouldEnforceRandomId).toHaveBeenCalledWith(encryptedSO.type);
expect(result.id).toBe(encryptedSO.id);
});

describe('namespace', () => {
const doTest = async (optNamespace: string, expectNamespaceInDescriptor: boolean) => {
const options = { overwrite: true, namespace: optNamespace };
Expand Down Expand Up @@ -531,6 +550,31 @@ describe('SavedObjectsRepository Encryption Extension', () => {
expect(result.saved_objects.length).toBe(1);
expect(result.saved_objects[0].error).toBeUndefined();
});

it('allows to opt-out of random ID enforcement', async () => {
mockEncryptionExt.isEncryptableType.mockReturnValue(true);
mockEncryptionExt.shouldEnforceRandomId.mockReturnValue(false);
mockEncryptionExt.decryptOrStripResponseAttributes.mockResolvedValue({
...encryptedSO,
...decryptedStrippedAttributes,
});

const result = await bulkCreateSuccess(
client,
repository,
[{ ...encryptedSO, version: mockVersion }],
{
overwrite: true,
// version: mockVersion, // this doesn't work in bulk...looks like it checks the object itself?
}
);

expect(client.bulk).toHaveBeenCalled();
expect(result.saved_objects).not.toBeUndefined();
expect(result.saved_objects.length).toBe(1);
expect(result.saved_objects[0].error).toBeUndefined();
expect(result.saved_objects[0].id).toBe(encryptedSO.id);
});
});

describe('#bulkUpdate', () => {
Expand Down

0 comments on commit 58d2b2d

Please sign in to comment.