generate-reader, generate-example: introduce new uc-portrange format

The `uc-portrange` string format will match single ports and ranges
in `minport-maxport` notation.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich
2022-04-06 23:30:43 +02:00
committed by John Crispin
parent af9e861ec1
commit b5531dd0a0
2 changed files with 17 additions and 0 deletions

View File

@@ -211,6 +211,14 @@ function random_value(kind, minLength, maxLength) {
case 'uc-base64':
return b64enc(random_phrase(50, 100));
case 'uc-portrange':
switch (math.rand() % 2) {
case 0: return sprintf('%d', math.rand() % 65536);
case 1: return join('-', sort([ math.rand() % 65536, math.rand() % 65536 ]));
}
break;
default:
if (minLength <= 15 && maxLength >= 20)
return random_phrase(minLength, maxLength);

View File

@@ -95,6 +95,15 @@ let GeneratorProto = {
'return b64dec(value) != null;'
]
},
"uc-portrange": {
desc: 'network port range',
code: [
'let ports = match(value, /^([0-9]|[1-9][0-9]*)(-([0-9]|[1-9][0-9]*))?$/);',
'if (!ports) return false;',
'let min = +ports[1], max = ports[2] ? +ports[3] : min;',
'return (min <= 65535 && max <= 65535 && max >= min);'
]
},
"hostname": {
desc: 'hostname',
code: [