cc, common: Split ransomware dir path validator regex expressions and rename related stuff to accurately describe it
This commit is contained in:
parent
54072b6632
commit
3496c717a9
|
@ -1,5 +1,5 @@
|
|||
# Defined in UI on ValidationFormats.js
|
||||
IP_RANGE = "ip-range"
|
||||
IP = "ip"
|
||||
VALID_DIR_LINUX = "valid-directory-linux"
|
||||
VALID_DIR_WINDOWS = "valid-directory-windows"
|
||||
VALID_RANSOMWARE_TARGET_PATH_LINUX = "valid-ransomware-target-path-linux"
|
||||
VALID_RANSOMWARE_TARGET_PATH_WINDOWS = "valid-ransomware-target-path-windows"
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
from common.common_consts.validation_formats import VALID_DIR_LINUX, VALID_DIR_WINDOWS
|
||||
from common.common_consts.validation_formats import (
|
||||
VALID_RANSOMWARE_TARGET_PATH_LINUX,
|
||||
VALID_RANSOMWARE_TARGET_PATH_WINDOWS,
|
||||
)
|
||||
|
||||
RANSOMWARE = {
|
||||
"title": "Ransomware",
|
||||
|
@ -22,7 +25,7 @@ RANSOMWARE = {
|
|||
"linux_target_dir": {
|
||||
"title": "Linux target directory",
|
||||
"type": "string",
|
||||
"format": VALID_DIR_LINUX,
|
||||
"format": VALID_RANSOMWARE_TARGET_PATH_LINUX,
|
||||
"default": "",
|
||||
"description": "A path to a directory on Linux systems that contains "
|
||||
"files that you will allow Infection Monkey to encrypt. If no "
|
||||
|
@ -31,7 +34,7 @@ RANSOMWARE = {
|
|||
"windows_target_dir": {
|
||||
"title": "Windows target directory",
|
||||
"type": "string",
|
||||
"format": VALID_DIR_WINDOWS,
|
||||
"format": VALID_RANSOMWARE_TARGET_PATH_WINDOWS,
|
||||
"default": "",
|
||||
"description": "A path to a directory on Windows systems that contains "
|
||||
"files that you will allow Infection Monkey to encrypt. If no "
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {IP, IP_RANGE, VALID_DIR_LINUX, VALID_DIR_WINDOWS} from './ValidationFormats';
|
||||
import {IP, IP_RANGE, VALID_RANSOMWARE_TARGET_PATH_LINUX, VALID_RANSOMWARE_TARGET_PATH_WINDOWS} from './ValidationFormats';
|
||||
|
||||
let invalidDirMessage = 'Invalid directory. Path should be absolute or begin with an environment variable.';
|
||||
|
||||
|
@ -10,9 +10,9 @@ export default function transformErrors(errors) {
|
|||
error.message = 'Invalid IP range, refer to description for valid examples.'
|
||||
} else if (error.name === 'format' && error.params.format === IP) {
|
||||
error.message = 'Invalid IP.'
|
||||
} else if (error.name === 'format' && error.params.format === VALID_DIR_LINUX) {
|
||||
} else if (error.name === 'format' && error.params.format === VALID_RANSOMWARE_TARGET_PATH_LINUX) {
|
||||
error.message = invalidDirMessage
|
||||
} else if (error.name === 'format' && error.params.format === VALID_DIR_WINDOWS) {
|
||||
} else if (error.name === 'format' && error.params.format === VALID_RANSOMWARE_TARGET_PATH_WINDOWS) {
|
||||
error.message = invalidDirMessage
|
||||
}
|
||||
return error;
|
||||
|
|
|
@ -1,22 +1,26 @@
|
|||
const ipRegex = '((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
|
||||
const cidrNotationRegex = '([0-9]|1[0-9]|2[0-9]|3[0-2])'
|
||||
const hostnameRegex = '^([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*.?)*([A-Za-z0-9]*[A-Za-z]+[A-Za-z0-9]*)$'
|
||||
// path is empty, or starts with `/` OR `$`
|
||||
const linuxDirRegex = '(^\\s*$)|^/|^\\$'
|
||||
// path is empty, or starts like `C:\` OR `C:/` OR `$` OR `%abc%`
|
||||
const windowsDirRegex = '(^\\s*$)|^([A-Za-z]:(\\\\|\\/))|^\\$|^(%\\w*\\d*\\s*%)'
|
||||
|
||||
const linuxAbsolutePathRegex = '^/' // path starts with `/`
|
||||
const linuxPathStartsWithEnvVariableRegex = '^\\$' // path starts with `$`
|
||||
|
||||
const windowsAbsolutePathRegex = '^([A-Za-z]:(\\\\|\\/))' // path starts like `C:\` OR `C:/`
|
||||
const windowsPathStartsWithEnvVariableRegex = '^\\$|^(%\\w*\\d*\\s*%)' // path starts like `$` OR `%abc%`
|
||||
|
||||
const whitespacesOnlyRegex = '^\\s*$'
|
||||
|
||||
|
||||
export const IP_RANGE = 'ip-range';
|
||||
export const IP = 'ip';
|
||||
export const VALID_DIR_LINUX = 'valid-directory-linux'
|
||||
export const VALID_DIR_WINDOWS = 'valid-directory-windows'
|
||||
export const VALID_RANSOMWARE_TARGET_PATH_LINUX = 'valid-ransomware-target-path-linux'
|
||||
export const VALID_RANSOMWARE_TARGET_PATH_WINDOWS = 'valid-ransomware-target-path-windows'
|
||||
|
||||
export const formValidationFormats = {
|
||||
[IP_RANGE]: buildIpRangeRegex(),
|
||||
[IP]: buildIpRegex(),
|
||||
[VALID_DIR_LINUX]: buildValidDirLinuxRegex(),
|
||||
[VALID_DIR_WINDOWS]: buildValidDirWindowsRegex()
|
||||
[VALID_RANSOMWARE_TARGET_PATH_LINUX]: buildValidRansomwarePathLinuxRegex(),
|
||||
[VALID_RANSOMWARE_TARGET_PATH_WINDOWS]: buildValidRansomwarePathWindowsRegex()
|
||||
};
|
||||
|
||||
function buildIpRangeRegex(){
|
||||
|
@ -32,10 +36,18 @@ function buildIpRegex(){
|
|||
return new RegExp('^'+ipRegex+'$')
|
||||
}
|
||||
|
||||
function buildValidDirLinuxRegex() {
|
||||
return new RegExp(linuxDirRegex)
|
||||
function buildValidRansomwarePathLinuxRegex() {
|
||||
return new RegExp([
|
||||
whitespacesOnlyRegex,
|
||||
linuxAbsolutePathRegex,
|
||||
linuxPathStartsWithEnvVariableRegex
|
||||
].join('|'))
|
||||
}
|
||||
|
||||
function buildValidDirWindowsRegex() {
|
||||
return new RegExp(windowsDirRegex)
|
||||
function buildValidRansomwarePathWindowsRegex() {
|
||||
return new RegExp([
|
||||
whitespacesOnlyRegex,
|
||||
windowsAbsolutePathRegex,
|
||||
windowsPathStartsWithEnvVariableRegex
|
||||
].join('|'))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue