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; } >; } > = [ { "name": "minimum_length:pass", "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:fail", "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:pass", "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_length:fail", "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 } } ] }, { "name": "must_contain_letter:pass", "input": { "conf": { "settings": { "password_policy": { "minimum_length": null, "maximum_length": null, "must_contain_letter": true, "must_contain_number": false, "must_contain_special_character": false, } } }, "password": "01x34" }, "output": [ ] }, { "name": "must_contain_letter:fail", "input": { "conf": { "settings": { "password_policy": { "minimum_length": null, "maximum_length": null, "must_contain_letter": true, "must_contain_number": false, "must_contain_special_character": false, } } }, "password": "01234" }, "output": [ { "incident": "lacks_letter", "details": { } } ] }, { "name": "must_contain_number:pass", "input": { "conf": { "settings": { "password_policy": { "minimum_length": null, "maximum_length": null, "must_contain_letter": false, "must_contain_number": true, "must_contain_special_character": false, } } }, "password": "ab0de" }, "output": [ ] }, { "name": "must_contain_number:fail", "input": { "conf": { "settings": { "password_policy": { "minimum_length": null, "maximum_length": null, "must_contain_letter": false, "must_contain_number": true, "must_contain_special_character": false, } } }, "password": "abcde" }, "output": [ { "incident": "lacks_number", "details": { } } ] }, { "name": "must_contain_special_character:pass", "input": { "conf": { "settings": { "password_policy": { "minimum_length": null, "maximum_length": null, "must_contain_letter": false, "must_contain_number": false, "must_contain_special_character": true, } } }, "password": "01.34" }, "output": [ ] }, { "name": "must_contain_special_character:fail", "input": { "conf": { "settings": { "password_policy": { "minimum_length": null, "maximum_length": null, "must_contain_letter": false, "must_contain_number": false, "must_contain_special_character": true, } } }, "password": "01234" }, "output": [ { "incident": "lacks_special_character", "details": { } } ] }, { "name": "oblique:pass", "input": { "conf": { "settings": { "password_policy": { "minimum_length": 8, "maximum_length": 12, "must_contain_letter": true, "must_contain_number": true, "must_contain_special_character": true, } } }, "password": "eiB@oo7tuu" }, "output": [ ] }, ]; cases.forEach( case_ => { it( case_.name, () => { _espe.conf.inject(case_.input.conf); const result : Array< { incident : string; details : Record; } > = _espe.service.member.validate_password(case_.input.password); nm_assert.deepEqual(result, case_.output); } ); } ); } );