Skip to content

Commit

Permalink
added e2e test for new ESO update
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Jul 30, 2020
1 parent 031e0d8 commit e4280f2
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export const plugin: PluginInitializer<void, void, PluginsSetup, PluginsStart> =
publicPropertyExcludedFromAAD: { type: 'keyword' },
publicPropertyStoredEncrypted: { type: 'binary' },
privateProperty: { type: 'binary' },
publicDeepProperty: {
enabled: false,
type: 'object',
},
},
}),
});
Expand Down Expand Up @@ -112,6 +116,31 @@ export const plugin: PluginInitializer<void, void, PluginsSetup, PluginsStart> =
}
);

for (const route of ['saved_objects', 'hidden_saved_objects']) {
router.put(
{
path: `/api/${route}/update-with-partial/{type}/{id}`,
validate: { params: (value) => ({ value }), body: (value) => ({ value }) },
},
async (context, request, response) => {
const [{ savedObjects }] = await core.getStartServices();
const { type, id } = request.params;
const { attributes } = request.body as { attributes: any };

return response.ok({
body: await savedObjects
.getScopedClient(request, {
includedHiddenTypes: [HIDDEN_SAVED_OBJECT_WITH_SECRET_TYPE],
excludedWrappers: ['encryptedSavedObjects'],
})
.update(type, id, attributes, {
refresh: true,
}),
});
}
);
}

registerHiddenSORoutes(router, core, deps, [HIDDEN_SAVED_OBJECT_WITH_SECRET_TYPE]);
},
start() {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function ({ getService }: FtrProviderContext) {
publicPropertyStoredEncrypted: string;
privateProperty: string;
publicPropertyExcludedFromAAD: string;
publicDeepProperty: Record<string, string>;
};

let savedObject: SavedObject;
Expand All @@ -50,6 +51,7 @@ export default function ({ getService }: FtrProviderContext) {
publicPropertyStoredEncrypted: randomness.string(),
privateProperty: randomness.string(),
publicPropertyExcludedFromAAD: randomness.string(),
publicDeepProperty: { [randomness.string()]: randomness.string() },
};

const { body } = await supertest
Expand All @@ -66,13 +68,17 @@ export default function ({ getService }: FtrProviderContext) {
publicProperty: savedObjectOriginalAttributes.publicProperty,
publicPropertyExcludedFromAAD: savedObjectOriginalAttributes.publicPropertyExcludedFromAAD,
publicPropertyStoredEncrypted: savedObjectOriginalAttributes.publicPropertyStoredEncrypted,
publicDeepProperty: savedObjectOriginalAttributes.publicDeepProperty,
});

const rawAttributes = await getRawSavedObjectAttributes(savedObject);
expect(rawAttributes.publicProperty).to.be(savedObjectOriginalAttributes.publicProperty);
expect(rawAttributes.publicPropertyExcludedFromAAD).to.be(
savedObjectOriginalAttributes.publicPropertyExcludedFromAAD
);
expect(rawAttributes.publicDeepProperty).to.eql(
savedObjectOriginalAttributes.publicDeepProperty
);

expect(rawAttributes.publicPropertyStoredEncrypted).to.not.be.empty();
expect(rawAttributes.publicPropertyStoredEncrypted).to.not.be(
Expand Down Expand Up @@ -208,6 +214,7 @@ export default function ({ getService }: FtrProviderContext) {
publicProperty: savedObjectOriginalAttributes.publicProperty,
publicPropertyExcludedFromAAD: savedObjectOriginalAttributes.publicPropertyExcludedFromAAD,
publicPropertyStoredEncrypted: savedObjectOriginalAttributes.publicPropertyStoredEncrypted,
publicDeepProperty: savedObjectOriginalAttributes.publicDeepProperty,
});
expect(response.error).to.be(undefined);
});
Expand All @@ -217,9 +224,13 @@ export default function ({ getService }: FtrProviderContext) {
// encrypted attributes.
const updatedPublicProperty = randomness.string();
await supertest
.put(`${getURLAPIBaseURL()}${encryptedSavedObjectType}/${savedObject.id}`)
.put(
`${getURLAPIBaseURL()}update-with-partial/${encryptedSavedObjectType}/${savedObject.id}`
)
.set('kbn-xsrf', 'xxx')
.send({ attributes: { publicProperty: updatedPublicProperty } })
.send({
attributes: { publicProperty: updatedPublicProperty },
})
.expect(200);

const { body: response } = await supertest
Expand All @@ -229,6 +240,7 @@ export default function ({ getService }: FtrProviderContext) {
expect(response.attributes).to.eql({
publicProperty: updatedPublicProperty,
publicPropertyExcludedFromAAD: savedObjectOriginalAttributes.publicPropertyExcludedFromAAD,
publicDeepProperty: savedObjectOriginalAttributes.publicDeepProperty,
});
expect(response.error).to.eql({
message: 'Unable to decrypt attribute "publicPropertyStoredEncrypted"',
Expand All @@ -248,6 +260,7 @@ export default function ({ getService }: FtrProviderContext) {
publicProperty: savedObjectOriginalAttributes.publicProperty,
publicPropertyExcludedFromAAD: savedObjectOriginalAttributes.publicPropertyExcludedFromAAD,
publicPropertyStoredEncrypted: savedObjectOriginalAttributes.publicPropertyStoredEncrypted,
publicDeepProperty: savedObjectOriginalAttributes.publicDeepProperty,
});
expect(savedObjects[0].error).to.be(undefined);
});
Expand All @@ -257,7 +270,9 @@ export default function ({ getService }: FtrProviderContext) {
// encrypted attributes.
const updatedPublicProperty = randomness.string();
await supertest
.put(`${getURLAPIBaseURL()}${encryptedSavedObjectType}/${savedObject.id}`)
.put(
`${getURLAPIBaseURL()}update-with-partial/${encryptedSavedObjectType}/${savedObject.id}`
)
.set('kbn-xsrf', 'xxx')
.send({ attributes: { publicProperty: updatedPublicProperty } })
.expect(200);
Expand All @@ -273,6 +288,7 @@ export default function ({ getService }: FtrProviderContext) {
expect(savedObjects[0].attributes).to.eql({
publicProperty: updatedPublicProperty,
publicPropertyExcludedFromAAD: savedObjectOriginalAttributes.publicPropertyExcludedFromAAD,
publicDeepProperty: savedObjectOriginalAttributes.publicDeepProperty,
});
expect(savedObjects[0].error).to.eql({
message: 'Unable to decrypt attribute "publicPropertyStoredEncrypted"',
Expand All @@ -294,6 +310,7 @@ export default function ({ getService }: FtrProviderContext) {
publicProperty: savedObjectOriginalAttributes.publicProperty,
publicPropertyExcludedFromAAD: savedObjectOriginalAttributes.publicPropertyExcludedFromAAD,
publicPropertyStoredEncrypted: savedObjectOriginalAttributes.publicPropertyStoredEncrypted,
publicDeepProperty: savedObjectOriginalAttributes.publicDeepProperty,
});
expect(savedObjects[0].error).to.be(undefined);
});
Expand All @@ -303,9 +320,13 @@ export default function ({ getService }: FtrProviderContext) {
// encrypted attributes.
const updatedPublicProperty = randomness.string();
await supertest
.put(`${getURLAPIBaseURL()}${encryptedSavedObjectType}/${savedObject.id}`)
.put(
`${getURLAPIBaseURL()}update-with-partial/${encryptedSavedObjectType}/${savedObject.id}`
)
.set('kbn-xsrf', 'xxx')
.send({ attributes: { publicProperty: updatedPublicProperty } })
.send({
attributes: { publicProperty: updatedPublicProperty },
})
.expect(200);

const {
Expand All @@ -321,6 +342,7 @@ export default function ({ getService }: FtrProviderContext) {
expect(savedObjects[0].attributes).to.eql({
publicProperty: updatedPublicProperty,
publicPropertyExcludedFromAAD: savedObjectOriginalAttributes.publicPropertyExcludedFromAAD,
publicDeepProperty: savedObjectOriginalAttributes.publicDeepProperty,
});
expect(savedObjects[0].error).to.eql({
message: 'Unable to decrypt attribute "publicPropertyStoredEncrypted"',
Expand All @@ -333,6 +355,7 @@ export default function ({ getService }: FtrProviderContext) {
publicPropertyExcludedFromAAD: randomness.string(),
publicPropertyStoredEncrypted: randomness.string(),
privateProperty: randomness.string(),
publicDeepProperty: { [randomness.string()]: randomness.string() },
};

const { body: response } = await supertest
Expand All @@ -345,6 +368,7 @@ export default function ({ getService }: FtrProviderContext) {
publicProperty: updatedAttributes.publicProperty,
publicPropertyExcludedFromAAD: updatedAttributes.publicPropertyExcludedFromAAD,
publicPropertyStoredEncrypted: updatedAttributes.publicPropertyStoredEncrypted,
publicDeepProperty: updatedAttributes.publicDeepProperty,
});

const rawAttributes = await getRawSavedObjectAttributes(savedObject);
Expand All @@ -361,6 +385,32 @@ export default function ({ getService }: FtrProviderContext) {
expect(rawAttributes.privateProperty).to.not.be(updatedAttributes.privateProperty);
});

it('#update overwrites objects in their entirety', async () => {
const updatedAttributes = {
publicProperty: randomness.string(),
publicPropertyExcludedFromAAD: randomness.string(),
publicPropertyStoredEncrypted: randomness.string(),
privateProperty: randomness.string(),
publicDeepProperty: { [randomness.string()]: randomness.string() },
};

await supertest
.put(`${getURLAPIBaseURL()}${encryptedSavedObjectType}/${savedObject.id}`)
.set('kbn-xsrf', 'xxx')
.send({ attributes: updatedAttributes })
.expect(200);

const { body: decryptedResponse } = await supertest
.get(
`${getURLAPIBaseURL()}get-decrypted-as-internal-user/${encryptedSavedObjectType}/${
savedObject.id
}`
)
.expect(200);

expect(decryptedResponse.attributes).to.eql(updatedAttributes);
});

it('#getDecryptedAsInternalUser decrypts and returns all attributes', async () => {
const { body: decryptedResponse } = await supertest
.get(
Expand All @@ -377,7 +427,9 @@ export default function ({ getService }: FtrProviderContext) {
const updatedAttributes = { publicPropertyExcludedFromAAD: randomness.string() };

const { body: response } = await supertest
.put(`${getURLAPIBaseURL()}${encryptedSavedObjectType}/${savedObject.id}`)
.put(
`${getURLAPIBaseURL()}update-with-partial/${encryptedSavedObjectType}/${savedObject.id}`
)
.set('kbn-xsrf', 'xxx')
.send({ attributes: updatedAttributes })
.expect(200);
Expand All @@ -404,7 +456,9 @@ export default function ({ getService }: FtrProviderContext) {
const updatedAttributes = { publicProperty: randomness.string() };

const { body: response } = await supertest
.put(`${getURLAPIBaseURL()}${encryptedSavedObjectType}/${savedObject.id}`)
.put(
`${getURLAPIBaseURL()}update-with-partial/${encryptedSavedObjectType}/${savedObject.id}`
)
.set('kbn-xsrf', 'xxx')
.send({ attributes: updatedAttributes })
.expect(200);
Expand Down

0 comments on commit e4280f2

Please sign in to comment.