2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-12-13 18:37:10 +00:00
|
|
|
export function capabilitiesStub(requestPath, capabilitiesArray) {
|
|
|
|
// sample of capabilitiesArray: ['read', 'update']
|
|
|
|
return {
|
2022-12-16 21:26:43 +00:00
|
|
|
[requestPath]: capabilitiesArray,
|
|
|
|
capabilities: capabilitiesArray,
|
2022-12-13 18:37:10 +00:00
|
|
|
request_id: '40f7e44d-af5c-9b60-bd20-df72eb17e294',
|
|
|
|
lease_id: '',
|
|
|
|
renewable: false,
|
|
|
|
lease_duration: 0,
|
|
|
|
data: {
|
|
|
|
[requestPath]: capabilitiesArray,
|
2022-12-16 21:26:43 +00:00
|
|
|
capabilities: capabilitiesArray,
|
2022-12-13 18:37:10 +00:00
|
|
|
},
|
|
|
|
wrap_info: null,
|
|
|
|
warnings: null,
|
|
|
|
auth: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-16 21:26:43 +00:00
|
|
|
export const noopStub = (response) => {
|
|
|
|
return function () {
|
|
|
|
return [response, { 'Content-Type': 'application/json' }, JSON.stringify({})];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-12-13 18:37:10 +00:00
|
|
|
/**
|
|
|
|
* allowAllCapabilitiesStub mocks the response from capabilities-self
|
|
|
|
* that allows the user to do any action (root user)
|
2022-12-16 21:26:43 +00:00
|
|
|
* Example usage assuming setupMirage(hooks) was called:
|
|
|
|
* this.server.post('/sys/capabilities-self', allowAllCapabilitiesStub(['read']));
|
2022-12-13 18:37:10 +00:00
|
|
|
*/
|
2022-12-16 21:26:43 +00:00
|
|
|
export function allowAllCapabilitiesStub(capabilitiesList = ['root']) {
|
|
|
|
return function (_, { requestBody }) {
|
|
|
|
const { paths } = JSON.parse(requestBody);
|
|
|
|
const specificCapabilities = paths.reduce((obj, path) => {
|
|
|
|
return {
|
|
|
|
...obj,
|
|
|
|
[path]: capabilitiesList,
|
|
|
|
};
|
|
|
|
}, {});
|
|
|
|
return {
|
|
|
|
...specificCapabilities,
|
|
|
|
capabilities: capabilitiesList,
|
|
|
|
request_id: 'mirage-795dc9e1-0321-9ac6-71fc',
|
|
|
|
lease_id: '',
|
|
|
|
renewable: false,
|
|
|
|
lease_duration: 0,
|
|
|
|
data: { ...specificCapabilities, capabilities: capabilitiesList },
|
|
|
|
wrap_info: null,
|
|
|
|
warnings: null,
|
|
|
|
auth: null,
|
|
|
|
};
|
2022-12-13 18:37:10 +00:00
|
|
|
};
|
|
|
|
}
|