130 lines
2.5 KiB
TypeScript
130 lines
2.5 KiB
TypeScript
const nm_assert = require("assert");
|
|
|
|
describe(
|
|
"member.validate_password",
|
|
() => {
|
|
const cases : Array<
|
|
{
|
|
name : string;
|
|
input : {
|
|
conf : any;
|
|
password : string;
|
|
};
|
|
output : Array<
|
|
{
|
|
incident : string;
|
|
details : Record<string, any>;
|
|
}
|
|
>;
|
|
}
|
|
> = [
|
|
{
|
|
"name": "minimum_length:negative",
|
|
"input": {
|
|
"conf": {
|
|
"settings": {
|
|
"password_policy": {
|
|
"minimum_length": 5,
|
|
"maximum_length": null,
|
|
"must_contain_letter": false,
|
|
"must_contain_number": false,
|
|
"must_contain_special_character": false,
|
|
}
|
|
}
|
|
},
|
|
"password": "abcde"
|
|
},
|
|
"output": [
|
|
]
|
|
},
|
|
{
|
|
"name": "minimum_lengt:positive",
|
|
"input": {
|
|
"conf": {
|
|
"settings": {
|
|
"password_policy": {
|
|
"minimum_length": 5,
|
|
"maximum_length": null,
|
|
"must_contain_letter": false,
|
|
"must_contain_number": false,
|
|
"must_contain_special_character": false,
|
|
}
|
|
}
|
|
},
|
|
"password": "abcd"
|
|
},
|
|
"output": [
|
|
{
|
|
"incident": "too_short",
|
|
"details": {
|
|
"minimum_length": 5,
|
|
"actual_length": 4
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "maximum_length:negative",
|
|
"input": {
|
|
"conf": {
|
|
"settings": {
|
|
"password_policy": {
|
|
"minimum_length": null,
|
|
"maximum_length": 5,
|
|
"must_contain_letter": false,
|
|
"must_contain_number": false,
|
|
"must_contain_special_character": false,
|
|
}
|
|
}
|
|
},
|
|
"password": "abcde"
|
|
},
|
|
"output": [
|
|
]
|
|
},
|
|
{
|
|
"name": "maximum_lengt:positive",
|
|
"input": {
|
|
"conf": {
|
|
"settings": {
|
|
"password_policy": {
|
|
"minimum_length": null,
|
|
"maximum_length": 5,
|
|
"must_contain_letter": false,
|
|
"must_contain_number": false,
|
|
"must_contain_special_character": false,
|
|
}
|
|
}
|
|
},
|
|
"password": "abcdef"
|
|
},
|
|
"output": [
|
|
{
|
|
"incident": "too_long",
|
|
"details": {
|
|
"maximum_length": 5,
|
|
"actual_length": 6
|
|
}
|
|
}
|
|
]
|
|
},
|
|
];
|
|
cases.forEach(
|
|
case_ => {
|
|
it(
|
|
case_.name,
|
|
() => {
|
|
_espe.conf.inject(case_.input.conf);
|
|
const result : Array<
|
|
{
|
|
incident : string;
|
|
details : Record<string, any>;
|
|
}
|
|
> = _espe.service.member.validate_password(case_.input.password);
|
|
nm_assert.deepEqual(result, case_.output);
|
|
}
|
|
);
|
|
}
|
|
);
|
|
}
|
|
);
|