mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 17:52:32 +00:00
UI: Fix LDAP Mirage Handler (#28432)
* update ldap mirage scenario to allow check-in/check-out action * update libraries test to mount engine * update mirage, fix tests * update lease renew CLI command * fix test * update tests
This commit is contained in:
@@ -35,17 +35,6 @@ export default function (server) {
|
||||
};
|
||||
};
|
||||
|
||||
// mount
|
||||
server.post('/sys/mounts/:path', () => new Response(204));
|
||||
server.get('/sys/internal/ui/mounts/:path', () => ({
|
||||
data: {
|
||||
accessor: 'ldap_ade94329',
|
||||
type: 'ldap',
|
||||
path: 'ldap-test/',
|
||||
uuid: '35e9119d-5708-4b6b-58d2-f913e27f242d',
|
||||
config: {},
|
||||
},
|
||||
}));
|
||||
// config
|
||||
server.post('/:backend/config', (schema, req) => createOrUpdateRecord(schema, req, 'ldapConfigs'));
|
||||
server.get('/:backend/config', (schema, req) => getRecord(schema, req, 'ldapConfigs'));
|
||||
@@ -67,8 +56,60 @@ export default function (server) {
|
||||
server.post('/:backend/library/:name', (schema, req) => createOrUpdateRecord(schema, req, 'ldapLibraries'));
|
||||
server.get('/:backend/library/:name', (schema, req) => getRecord(schema, req, 'ldapLibraries'));
|
||||
server.get('/:backend/library', (schema) => listRecords(schema, 'ldapLibraries'));
|
||||
server.get('/:backend/library/:name/status', () => ({
|
||||
'bob.johnson': { available: false, borrower_client_token: '8b80c305eb3a7dbd161ef98f10ea60a116ce0910' },
|
||||
'mary.smith': { available: true },
|
||||
}));
|
||||
server.get('/:backend/library/:name/status', (schema) => {
|
||||
const data = schema.db['ldapAccountStatuses'].reduce((prev, curr) => {
|
||||
prev[curr.account] = {
|
||||
available: curr.available,
|
||||
borrower_client_token: curr.borrower_client_token,
|
||||
};
|
||||
return prev;
|
||||
}, {});
|
||||
return { data };
|
||||
});
|
||||
// check-out / check-in
|
||||
server.post('/:backend/library/:set_name/check-in', (schema, req) => {
|
||||
// Check-in makes an unavailable account available again
|
||||
const { service_account_names } = JSON.parse(req.requestBody);
|
||||
const dbCollection = schema.db['ldapAccountStatuses'];
|
||||
const updated = dbCollection.find(service_account_names).map((f) => ({
|
||||
...f,
|
||||
available: true,
|
||||
borrower_client_token: undefined,
|
||||
}));
|
||||
updated.forEach((u) => {
|
||||
dbCollection.update(u.id, u);
|
||||
});
|
||||
return {
|
||||
data: {
|
||||
check_ins: service_account_names,
|
||||
},
|
||||
};
|
||||
});
|
||||
server.post('/:backend/library/:set_name/check-out', (schema, req) => {
|
||||
const { set_name, backend } = req.params;
|
||||
const dbCollection = schema.db['ldapAccountStatuses'];
|
||||
const available = dbCollection.where({ available: true });
|
||||
if (available) {
|
||||
return Response(404, {}, { errors: ['no accounts available to check out'] });
|
||||
}
|
||||
const checkOut = {
|
||||
...available[0],
|
||||
available: false,
|
||||
borrower_client_token: crypto.randomUUID(),
|
||||
};
|
||||
dbCollection.update(checkOut.id, checkOut);
|
||||
return {
|
||||
request_id: '364a17d4-e5ab-998b-ceee-b49929229e0c',
|
||||
lease_id: `${backend}/library/${set_name}/check-out/aoBsaBEI4PK96VnukubvYDlZ`,
|
||||
renewable: true,
|
||||
lease_duration: 36000,
|
||||
data: {
|
||||
password: crypto.randomUUID(),
|
||||
service_account_name: checkOut.account,
|
||||
},
|
||||
wrap_info: null,
|
||||
warnings: null,
|
||||
auth: null,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
13
ui/mirage/models/ldap-account-status.js
Normal file
13
ui/mirage/models/ldap-account-status.js
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import { Model } from 'miragejs';
|
||||
|
||||
export default Model.extend({
|
||||
account: '', // should match ID
|
||||
library: '',
|
||||
available: false,
|
||||
borrower_client_token: undefined,
|
||||
});
|
||||
@@ -4,8 +4,19 @@
|
||||
*/
|
||||
|
||||
export default function (server) {
|
||||
server.create('ldap-config', { path: 'kubernetes' });
|
||||
server.create('ldap-config', { path: 'kubernetes', backend: 'ldap-test' });
|
||||
server.create('ldap-role', 'static', { name: 'static-role' });
|
||||
server.create('ldap-role', 'dynamic', { name: 'dynamic-role' });
|
||||
server.create('ldap-library', { name: 'test-library' });
|
||||
server.create('ldap-account-status', {
|
||||
id: 'bob.johnson',
|
||||
account: 'bob.johnson',
|
||||
available: false,
|
||||
borrower_client_token: '8b80c305eb3a7dbd161ef98f10ea60a116ce0910',
|
||||
});
|
||||
server.create('ldap-account-status', {
|
||||
id: 'mary.smith',
|
||||
account: 'mary.smith',
|
||||
available: true,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user