ui: make unsafeItemSelected() a pure function

This commit is contained in:
Mike Salvatore 2021-02-25 19:47:21 -05:00
parent ff28509d0d
commit 8f32c48964
1 changed files with 16 additions and 16 deletions

View File

@ -18,6 +18,19 @@ const CONFIG_URL = '/api/configuration/island';
export const API_PBA_LINUX = '/api/fileUpload/PBAlinux'; export const API_PBA_LINUX = '/api/fileUpload/PBAlinux';
export const API_PBA_WINDOWS = '/api/fileUpload/PBAwindows'; export const API_PBA_WINDOWS = '/api/fileUpload/PBAwindows';
function unsafeItemSelected(options, selectedOptions) {
let item_safety = new Map();
options.forEach(i => item_safety[i.enum[0]] = i.safe);
for (let selected of selectedOptions) {
if (!item_safety[selected]) {
return true;
}
}
return false;
}
class ConfigurePageComponent extends AuthComponent { class ConfigurePageComponent extends AuthComponent {
constructor(props) { constructor(props) {
@ -122,39 +135,26 @@ class ConfigurePageComponent extends AuthComponent {
} }
unsafeExploiterSelected(config) { unsafeExploiterSelected(config) {
return this.unsafeItemSelected( return unsafeItemSelected(
this.state.schema.definitions.exploiter_classes.anyOf, this.state.schema.definitions.exploiter_classes.anyOf,
config.basic.exploiters.exploiter_classes config.basic.exploiters.exploiter_classes
); );
} }
unsafePostBreachActionSelected(config) { unsafePostBreachActionSelected(config) {
return this.unsafeItemSelected( return unsafeItemSelected(
this.state.schema.definitions.post_breach_actions.anyOf, this.state.schema.definitions.post_breach_actions.anyOf,
config.monkey.post_breach.post_breach_actions config.monkey.post_breach.post_breach_actions
); );
} }
unsafeSystemInfoCollectorSelected(config) { unsafeSystemInfoCollectorSelected(config) {
return this.unsafeItemSelected( return unsafeItemSelected(
this.state.schema.definitions.system_info_collector_classes.anyOf, this.state.schema.definitions.system_info_collector_classes.anyOf,
config.monkey.system_info.system_info_collector_classes config.monkey.system_info.system_info_collector_classes
); );
} }
unsafeItemSelected(options, selectedOptions) {
let item_safety = new Map();
options.forEach(i => item_safety[i.enum[0]] = i.safe);
for (let selected of selectedOptions) {
if (!item_safety[selected]) {
return true;
}
}
return false;
}
matrixSubmit = () => { matrixSubmit = () => {
// Submit attack matrix // Submit attack matrix
this.authFetch(ATTACK_URL, this.authFetch(ATTACK_URL,