[add] test:service.member.export_authelia_user_file
This commit is contained in:
parent
f36a48f2d3
commit
9910299675
5 changed files with 268 additions and 57 deletions
|
@ -30,6 +30,7 @@ namespace _espe.service.member
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @todo do not export
|
||||||
*/
|
*/
|
||||||
export function validate_password(
|
export function validate_password(
|
||||||
password : string
|
password : string
|
||||||
|
@ -110,7 +111,6 @@ namespace _espe.service.member
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo test
|
|
||||||
*/
|
*/
|
||||||
export function name_login(
|
export function name_login(
|
||||||
object : _espe.type.member_object
|
object : _espe.type.member_object
|
||||||
|
@ -475,12 +475,26 @@ namespace _espe.service.member
|
||||||
* @todo check validity (e.g. username characters)
|
* @todo check validity (e.g. username characters)
|
||||||
*/
|
*/
|
||||||
export async function export_authelia_user_file(
|
export async function export_authelia_user_file(
|
||||||
|
options : {
|
||||||
|
custom_data ?: (null | Array<_espe.type.member_object>);
|
||||||
|
} = {}
|
||||||
) : Promise<string>
|
) : Promise<string>
|
||||||
{
|
{
|
||||||
|
options = Object.assign(
|
||||||
|
{
|
||||||
|
"custom_data": null,
|
||||||
|
},
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
const nm_yaml = require("yaml");
|
const nm_yaml = require("yaml");
|
||||||
|
|
||||||
return lib_plankton.call.convey(
|
return lib_plankton.call.convey(
|
||||||
await dump(),
|
(
|
||||||
|
(options.custom_data !== null)
|
||||||
|
? (options.custom_data.map((member_object, index) => ({"id": index, "object": member_object})))
|
||||||
|
: await dump()
|
||||||
|
),
|
||||||
[
|
[
|
||||||
x => x.map(
|
x => x.map(
|
||||||
entry => Object.assign(
|
entry => Object.assign(
|
||||||
|
|
|
@ -1,23 +1,6 @@
|
||||||
const nm_assert = require("assert");
|
|
||||||
|
|
||||||
describe(
|
|
||||||
"member.validate_password",
|
|
||||||
() => {
|
|
||||||
const cases : Array<
|
|
||||||
{
|
{
|
||||||
name : string;
|
"service.member.validate_password": {
|
||||||
input : {
|
"cases": [
|
||||||
conf : any;
|
|
||||||
password : string;
|
|
||||||
};
|
|
||||||
output : Array<
|
|
||||||
{
|
|
||||||
incident : string;
|
|
||||||
details : Record<string, any>;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
}
|
|
||||||
> = [
|
|
||||||
{
|
{
|
||||||
"name": "minimum_length:pass",
|
"name": "minimum_length:pass",
|
||||||
"input": {
|
"input": {
|
||||||
|
@ -28,7 +11,7 @@ describe(
|
||||||
"maximum_length": null,
|
"maximum_length": null,
|
||||||
"must_contain_letter": false,
|
"must_contain_letter": false,
|
||||||
"must_contain_number": false,
|
"must_contain_number": false,
|
||||||
"must_contain_special_character": false,
|
"must_contain_special_character": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -38,7 +21,7 @@ describe(
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "minimum_lengt:fail",
|
"name": "minimum_length:fail",
|
||||||
"input": {
|
"input": {
|
||||||
"conf": {
|
"conf": {
|
||||||
"settings": {
|
"settings": {
|
||||||
|
@ -47,7 +30,7 @@ describe(
|
||||||
"maximum_length": null,
|
"maximum_length": null,
|
||||||
"must_contain_letter": false,
|
"must_contain_letter": false,
|
||||||
"must_contain_number": false,
|
"must_contain_number": false,
|
||||||
"must_contain_special_character": false,
|
"must_contain_special_character": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -73,7 +56,7 @@ describe(
|
||||||
"maximum_length": 5,
|
"maximum_length": 5,
|
||||||
"must_contain_letter": false,
|
"must_contain_letter": false,
|
||||||
"must_contain_number": false,
|
"must_contain_number": false,
|
||||||
"must_contain_special_character": false,
|
"must_contain_special_character": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -92,7 +75,7 @@ describe(
|
||||||
"maximum_length": 5,
|
"maximum_length": 5,
|
||||||
"must_contain_letter": false,
|
"must_contain_letter": false,
|
||||||
"must_contain_number": false,
|
"must_contain_number": false,
|
||||||
"must_contain_special_character": false,
|
"must_contain_special_character": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -118,7 +101,7 @@ describe(
|
||||||
"maximum_length": null,
|
"maximum_length": null,
|
||||||
"must_contain_letter": true,
|
"must_contain_letter": true,
|
||||||
"must_contain_number": false,
|
"must_contain_number": false,
|
||||||
"must_contain_special_character": false,
|
"must_contain_special_character": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -137,7 +120,7 @@ describe(
|
||||||
"maximum_length": null,
|
"maximum_length": null,
|
||||||
"must_contain_letter": true,
|
"must_contain_letter": true,
|
||||||
"must_contain_number": false,
|
"must_contain_number": false,
|
||||||
"must_contain_special_character": false,
|
"must_contain_special_character": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -161,7 +144,7 @@ describe(
|
||||||
"maximum_length": null,
|
"maximum_length": null,
|
||||||
"must_contain_letter": false,
|
"must_contain_letter": false,
|
||||||
"must_contain_number": true,
|
"must_contain_number": true,
|
||||||
"must_contain_special_character": false,
|
"must_contain_special_character": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -180,7 +163,7 @@ describe(
|
||||||
"maximum_length": null,
|
"maximum_length": null,
|
||||||
"must_contain_letter": false,
|
"must_contain_letter": false,
|
||||||
"must_contain_number": true,
|
"must_contain_number": true,
|
||||||
"must_contain_special_character": false,
|
"must_contain_special_character": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -204,7 +187,7 @@ describe(
|
||||||
"maximum_length": null,
|
"maximum_length": null,
|
||||||
"must_contain_letter": false,
|
"must_contain_letter": false,
|
||||||
"must_contain_number": false,
|
"must_contain_number": false,
|
||||||
"must_contain_special_character": true,
|
"must_contain_special_character": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -223,7 +206,7 @@ describe(
|
||||||
"maximum_length": null,
|
"maximum_length": null,
|
||||||
"must_contain_letter": false,
|
"must_contain_letter": false,
|
||||||
"must_contain_number": false,
|
"must_contain_number": false,
|
||||||
"must_contain_special_character": true,
|
"must_contain_special_character": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -247,7 +230,7 @@ describe(
|
||||||
"maximum_length": 12,
|
"maximum_length": 12,
|
||||||
"must_contain_letter": true,
|
"must_contain_letter": true,
|
||||||
"must_contain_number": true,
|
"must_contain_number": true,
|
||||||
"must_contain_special_character": true,
|
"must_contain_special_character": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -255,24 +238,66 @@ describe(
|
||||||
},
|
},
|
||||||
"output": [
|
"output": [
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
];
|
"service.member.name_login": {
|
||||||
cases.forEach(
|
"cases": [
|
||||||
case_ => {
|
|
||||||
it(
|
|
||||||
case_.name,
|
|
||||||
() => {
|
|
||||||
_espe.conf.inject(case_.input.conf);
|
|
||||||
const result : Array<
|
|
||||||
{
|
{
|
||||||
incident : string;
|
"name": "extension:first",
|
||||||
details : Record<string, any>;
|
"input": {
|
||||||
|
"name_real_value": "Hans Wurst",
|
||||||
|
"name_real_index": 1
|
||||||
|
},
|
||||||
|
"output": "hans.wurst"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "extension:other",
|
||||||
|
"input": {
|
||||||
|
"name_real_value": "Hans Wurst",
|
||||||
|
"name_real_index": 3
|
||||||
|
},
|
||||||
|
"output": "hans.wurst.3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "oblique",
|
||||||
|
"input": {
|
||||||
|
"name_real_value": "Käthĕ Gauß-Öhler",
|
||||||
|
"name_real_index": 2
|
||||||
|
},
|
||||||
|
"output": "kaeth_.gauss-oehler.2"
|
||||||
}
|
}
|
||||||
> = _espe.service.member.validate_password(case_.input.password);
|
]
|
||||||
nm_assert.deepEqual(result, case_.output);
|
},
|
||||||
|
"service.member.export_authelia_user_file": {
|
||||||
|
"cases": [
|
||||||
|
{
|
||||||
|
"name": "oblique",
|
||||||
|
"input": {
|
||||||
|
"conf": {
|
||||||
|
"settings": {
|
||||||
|
"target_domain": "testdomain.org",
|
||||||
|
"prefix_for_numberbased_email_addresses": "wicht-"
|
||||||
}
|
}
|
||||||
);
|
},
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"membership_number": "1234567",
|
||||||
|
"name_real_value": "Karl Liebknecht",
|
||||||
|
"name_real_index": 1,
|
||||||
|
"email_address_private": "karl@l-haus.de",
|
||||||
|
"registered": true,
|
||||||
|
"enabled": true,
|
||||||
|
"email_use_veiled_address": true,
|
||||||
|
"email_use_nominal_address": false,
|
||||||
|
"email_redirect_to_private_address": true,
|
||||||
|
"email_allow_sending": false,
|
||||||
|
"password_image": "foobar"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"output": "users:\n karl.liebknecht:\n disabled: false\n displayname: Karl Liebknecht\n email: wicht-1234567@testdomain.org\n groups: []\n password: foobar\n"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
);
|
|
162
source/test/main.mocha.ts
Normal file
162
source/test/main.mocha.ts
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
const nm_fs = require("fs");
|
||||||
|
const nm_assert = require("assert");
|
||||||
|
|
||||||
|
type type_test_section = {
|
||||||
|
cases : Array<any>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const _data : Record<string, type_test_section> = lib_plankton.json.decode(nm_fs.readFileSync("test-data.json"));
|
||||||
|
|
||||||
|
|
||||||
|
describe(
|
||||||
|
"service.member.validate_password",
|
||||||
|
() => {
|
||||||
|
const data : {
|
||||||
|
cases : Array<
|
||||||
|
{
|
||||||
|
name : string;
|
||||||
|
input : {
|
||||||
|
conf : any;
|
||||||
|
password : string;
|
||||||
|
};
|
||||||
|
output : Array<
|
||||||
|
{
|
||||||
|
incident : string;
|
||||||
|
details : Record<string, any>;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
} = _data["service.member.validate_password"];
|
||||||
|
data.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);
|
||||||
|
_espe.conf.inject({});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
describe(
|
||||||
|
"service.member.name_login",
|
||||||
|
() => {
|
||||||
|
const data : {
|
||||||
|
cases : Array<
|
||||||
|
{
|
||||||
|
name : string;
|
||||||
|
input : {
|
||||||
|
name_real_value : string;
|
||||||
|
name_real_index : int;
|
||||||
|
};
|
||||||
|
output : string;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
} = _data["service.member.name_login"];
|
||||||
|
data.cases.forEach(
|
||||||
|
case_ => {
|
||||||
|
it(
|
||||||
|
case_.name,
|
||||||
|
() => {
|
||||||
|
const member_object : _espe.type.member_object = {
|
||||||
|
"membership_number": "",
|
||||||
|
"name_real_value": case_.input.name_real_value,
|
||||||
|
"name_real_index": case_.input.name_real_index,
|
||||||
|
"email_address_private": "",
|
||||||
|
"registered": false,
|
||||||
|
"enabled": false,
|
||||||
|
"email_use_veiled_address": false,
|
||||||
|
"email_use_nominal_address": false,
|
||||||
|
"email_redirect_to_private_address": false,
|
||||||
|
"email_allow_sending": false,
|
||||||
|
"password_image": null,
|
||||||
|
};
|
||||||
|
const result : string = _espe.service.member.name_login(member_object);
|
||||||
|
nm_assert.equal(result, case_.output);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
describe(
|
||||||
|
"service.member.export_authelia_user_file",
|
||||||
|
() => {
|
||||||
|
const data : {
|
||||||
|
cases : Array<
|
||||||
|
{
|
||||||
|
name : string;
|
||||||
|
input : {
|
||||||
|
conf : any;
|
||||||
|
members : Array<
|
||||||
|
{
|
||||||
|
membership_number : string;
|
||||||
|
name_real_value : string;
|
||||||
|
name_real_index : int;
|
||||||
|
email_address_private : (null | string);
|
||||||
|
registered : boolean;
|
||||||
|
enabled : boolean;
|
||||||
|
email_use_veiled_address : boolean;
|
||||||
|
email_use_nominal_address : boolean;
|
||||||
|
email_redirect_to_private_address : boolean;
|
||||||
|
email_allow_sending : boolean;
|
||||||
|
password_image : (null | string);
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
};
|
||||||
|
output : string;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
} = _data["service.member.export_authelia_user_file"];
|
||||||
|
data.cases.forEach(
|
||||||
|
case_ => {
|
||||||
|
it(
|
||||||
|
case_.name,
|
||||||
|
async () => {
|
||||||
|
// setup
|
||||||
|
_espe.conf.inject(case_.input.conf);
|
||||||
|
|
||||||
|
// execution
|
||||||
|
const result : string = await _espe.service.member.export_authelia_user_file(
|
||||||
|
{
|
||||||
|
"custom_data": case_.input.members.map(
|
||||||
|
member_raw => (
|
||||||
|
{
|
||||||
|
"membership_number": member_raw.membership_number,
|
||||||
|
"name_real_value": member_raw.name_real_value,
|
||||||
|
"name_real_index": member_raw.name_real_index,
|
||||||
|
"email_address_private": member_raw.email_address_private,
|
||||||
|
"registered": member_raw.registered,
|
||||||
|
"enabled": member_raw.enabled,
|
||||||
|
"email_use_veiled_address": member_raw.email_use_veiled_address,
|
||||||
|
"email_use_nominal_address": member_raw.email_use_nominal_address,
|
||||||
|
"email_redirect_to_private_address": member_raw.email_redirect_to_private_address,
|
||||||
|
"email_allow_sending": member_raw.email_allow_sending,
|
||||||
|
"password_image": member_raw.password_image,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// assertions
|
||||||
|
nm_assert.equal(result, case_.output);
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
_espe.conf.inject({});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
|
@ -74,13 +74,19 @@ ${dir_build}/espe: \
|
||||||
@ ${cmd_chmod} +x $@
|
@ ${cmd_chmod} +x $@
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: core ${dir_build}/espe-test.mocha.js
|
test: core ${dir_build}/test-data.json ${dir_build}/espe-test.mocha.js
|
||||||
|
|
||||||
|
${dir_build}/test-data.json: \
|
||||||
|
${dir_source}/test/data.json
|
||||||
|
@ ${cmd_log} "test | copy data …"
|
||||||
|
@ ${cmd_mkdir} $(dir $@)
|
||||||
|
@ ${cmd_cp} -r -u -v $^ $@
|
||||||
|
|
||||||
${dir_temp}/espe-test-raw.js: \
|
${dir_temp}/espe-test-raw.js: \
|
||||||
${dir_lib}/plankton/plankton.d.ts \
|
${dir_lib}/plankton/plankton.d.ts \
|
||||||
${dir_temp}/espe-core.d.ts \
|
${dir_temp}/espe-core.d.ts \
|
||||||
${dir_lib}/node/node_modules/@types/mocha/index.d.ts \
|
${dir_lib}/node/node_modules/@types/mocha/index.d.ts \
|
||||||
${dir_source}/tests.mocha.ts
|
${dir_source}/test/main.mocha.ts
|
||||||
@ ${cmd_log} "compile | test …"
|
@ ${cmd_log} "compile | test …"
|
||||||
@ ${cmd_mkdir} $(dir $@)
|
@ ${cmd_mkdir} $(dir $@)
|
||||||
@ tsc --lib es2020 $^ --outFile $@
|
@ tsc --lib es2020 $^ --outFile $@
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
tools/build -t
|
output_directory="/tmp/espe-test"
|
||||||
mocha build/espe-test.mocha.js
|
|
||||||
|
tools/build --tests --output-directory=${output_directory}
|
||||||
|
cd ${output_directory}
|
||||||
|
mocha espe-test.mocha.js
|
||||||
|
cd -
|
||||||
|
|
Loading…
Add table
Reference in a new issue