From 98e553676bd86ef023d9574262c07276fdb1a608 Mon Sep 17 00:00:00 2001 From: Felipe Signorini Date: Tue, 24 Sep 2019 17:21:09 +0100 Subject: [PATCH] create e2e testing on audit microservice --- app/audit/entities/Audit.js | 4 +- app/audit/entities/Snapshot.js | 4 +- app/audit/repositories/dao/audit.js | 4 +- app/audit/repositories/dao/snapshot.js | 4 +- docs/audit/api_data.js | 2 +- docs/audit/api_data.json | 2 +- docs/audit/api_project.js | 2 +- docs/audit/api_project.json | 2 +- test/e2e/audit.js | 393 +++++++++++++++++++++++++ test/e2e/libs/cleaner_db.js | 2 + 10 files changed, 407 insertions(+), 12 deletions(-) create mode 100644 test/e2e/audit.js diff --git a/app/audit/entities/Audit.js b/app/audit/entities/Audit.js index 0a1b144..9e699ec 100644 --- a/app/audit/entities/Audit.js +++ b/app/audit/entities/Audit.js @@ -2,7 +2,7 @@ const _ = require('lodash'); -const Audit = require('../repositories/dao/audit'); +const Audits = require('../repositories/dao/audit'); const audit = () => { const resFilled = ['_id', 'updated_at', 'entity', 'entity_id', 'user', 'body']; @@ -18,7 +18,7 @@ const audit = () => { validators: require('../validators/audit'), - dao: Audit, + dao: Audits, filled, singleFilled, diff --git a/app/audit/entities/Snapshot.js b/app/audit/entities/Snapshot.js index fe8967f..c6155a4 100644 --- a/app/audit/entities/Snapshot.js +++ b/app/audit/entities/Snapshot.js @@ -2,7 +2,7 @@ const _ = require('lodash'); -const Snapshot = require('../repositories/dao/snapshot'); +const Snapshots = require('../repositories/dao/snapshot'); const snapshot = () => { const resFilled = ['_id', 'updated_at', 'entity', 'entity_id', 'user', 'body']; @@ -18,7 +18,7 @@ const snapshot = () => { validators: require('../validators/audit'), - dao: Snapshot, + dao: Snapshots, filled, singleFilled, diff --git a/app/audit/repositories/dao/audit.js b/app/audit/repositories/dao/audit.js index 468ca0f..ed96e25 100644 --- a/app/audit/repositories/dao/audit.js +++ b/app/audit/repositories/dao/audit.js @@ -2,5 +2,5 @@ const Dao = require('core/repositories/daos/DBConnector'); -class Audit extends Dao {} -module.exports = Audit; +class Audits extends Dao {} +module.exports = Audits; diff --git a/app/audit/repositories/dao/snapshot.js b/app/audit/repositories/dao/snapshot.js index 9c8f919..0dfba77 100644 --- a/app/audit/repositories/dao/snapshot.js +++ b/app/audit/repositories/dao/snapshot.js @@ -2,5 +2,5 @@ const Dao = require('core/repositories/daos/DBConnector'); -class Snapshot extends Dao {} -module.exports = Snapshot; +class Snapshots extends Dao {} +module.exports = Snapshots; diff --git a/docs/audit/api_data.js b/docs/audit/api_data.js index b289015..146166b 100644 --- a/docs/audit/api_data.js +++ b/docs/audit/api_data.js @@ -1 +1 @@ -define({ "api": [ { "type": "post", "url": "/api/:entity", "title": "c. Create record", "name": "CreateAudit", "group": "Audit", "parameter": { "fields": { "Body x-www": [ { "group": "Body x-www", "type": "String", "optional": true, "field": "entity_id", "description": "

Entity ID

" }, { "group": "Body x-www", "type": "String", "optional": true, "field": "roles", "description": "

Current roles

" }, { "group": "Body x-www", "type": "String", "optional": false, "field": "field", "description": "

All fields

" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT Audit (Contract)" } ], "header": { "fields": { "Header": [ { "group": "Header", "type": "String", "optional": false, "field": "Authorization", "description": "

JWT {Token}

" } ] } }, "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 201 OK\n{}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "get", "url": "/api/:entity", "title": "a. List record by entity", "name": "GetAudit", "group": "Audit", "parameter": { "fields": { "Query": [ { "group": "Query", "type": "String", "optional": true, "field": "token", "description": "

Authorization JWT {Token}

" }, { "group": "Query", "type": "String", "optional": false, "field": "entity_id", "description": "

Entity unique id

" }, { "group": "Query", "type": "Object", "optional": false, "field": "data", "description": "

Filter by field
Must used with dot notation, like

  \"data.hostname\": 'search by hostname' // or
\"data.datacenters.providers\": 'search by providers'
" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT (Read | Write | Admin)" } ], "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 200 OK\n[\n {\n _id: \n entity_id: \n entity: \n created_at: \n data: \n {}\n }\n]", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "get", "url": "/api/:entity/:id", "title": "b. Show record", "name": "GetAuditId", "group": "Audit", "parameter": { "fields": { "Query": [ { "group": "Query", "type": "String", "optional": true, "field": "token", "description": "

Authorization JWT {Token}

" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Entity unique id.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT (Read | Write | Admin)" } ], "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 200 OK\n[\n {\n _id: \n entity_id: \n entity: \n created_at: \n data: \n {}\n }\n]", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "get", "url": "/", "title": "Ping", "name": "GetPing", "group": "Ping", "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 200 OK\n{\n app: (String),\n description: (String),\n version: (Float),\n api_timeout: (Number)\n}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Ping" }, { "type": "post", "url": "/teams/:id/audit/:entity", "title": "ac. Create record", "name": "CreateTeamApi", "group": "Teams", "description": "

Use for teams scope, have be all actions, params and option in /audit/:entity,

", "parameter": { "fields": { "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Team unique ID.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "version": "0.0.0", "filename": "app/audit/routers/audit/index.js", "groupTitle": "Teams" }, { "type": "get", "url": "/teams/:id/audit/:entity", "title": "aa. List record by entity", "name": "GetTeamApi", "group": "Teams", "description": "

Use for teams scope, have be all actions, params and option in /audit/:entity,

", "parameter": { "fields": { "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Team unique ID.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "version": "0.0.0", "filename": "app/audit/routers/audit/index.js", "groupTitle": "Teams" }, { "type": "get", "url": "/teams/:id/audit/:entity", "title": "ab. Show record", "name": "GetTeamApiID", "group": "Teams", "description": "

Use for teams scope, have be all actions, params and option in /audit/:entity/:id,

", "parameter": { "fields": { "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Team unique ID.

" }, { "group": "Param", "type": "String", "optional": false, "field": "idu", "description": "

Entity unique ID.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "version": "0.0.0", "filename": "app/audit/routers/audit/index.js", "groupTitle": "Teams" } ] }); +define({ "api": [ { "type": "post", "url": "/audit/:entity/:id", "title": "c. Create new record", "name": "CreateAudit", "group": "Audit", "description": "

Set a full record on track

", "parameter": { "fields": { "Body x-www": [ { "group": "Body x-www", "type": "String", "optional": false, "field": "field", "description": "

All fields

" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Entity unique id.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT Private (MAESTRO_SECRETJWT_PRIVATE)" } ], "header": { "fields": { "Header": [ { "group": "Header", "type": "String", "optional": false, "field": "Authorization", "description": "

JWT {Token}

" } ] } }, "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 201 OK\n{}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "get", "url": "/audit/:entity/:id", "title": "b. Show record", "name": "GetAuditId", "group": "Audit", "parameter": { "fields": { "Query": [ { "group": "Query", "type": "String", "optional": true, "field": "token", "description": "

Authorization JWT {Token}

" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Entity unique id.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT Private (MAESTRO_SECRETJWT_PRIVATE)" } ], "header": { "fields": { "Header": [ { "group": "Header", "type": "String", "optional": false, "field": "Authorization", "description": "

JWT {Token}

" } ] } }, "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 200 OK\n[\n {\n _id: \n entity_id: \n entity: \n created_at: \n body: \n {}\n }\n]", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "patch", "url": "/audit/:entity/:id", "title": "e. Patch record command", "name": "PatchAudit", "group": "Audit", "description": "

Set a partial record on track

", "parameter": { "fields": { "Body x-www": [ { "group": "Body x-www", "type": "String", "optional": false, "field": "field", "description": "

All fields

" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Entity unique id.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT Private (MAESTRO_SECRETJWT_PRIVATE)" } ], "header": { "fields": { "Header": [ { "group": "Header", "type": "String", "optional": false, "field": "Authorization", "description": "

JWT {Token}

" } ] } }, "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 201 OK\n{}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "delete", "url": "/audit/:entity/:id", "title": "f. Remove record command", "name": "RemoveAudit", "group": "Audit", "description": "

Set a delete record on track

", "parameter": { "fields": { "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Entity unique id.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT Private (MAESTRO_SECRETJWT_PRIVATE)" } ], "header": { "fields": { "Header": [ { "group": "Header", "type": "String", "optional": false, "field": "Authorization", "description": "

JWT {Token}

" } ] } }, "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 201 OK\n{}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "put", "url": "/audit/:entity/:id", "title": "d. Set record command", "name": "UpdateAudit", "group": "Audit", "description": "

Set a full record on track

", "parameter": { "fields": { "Body x-www": [ { "group": "Body x-www", "type": "String", "optional": false, "field": "field", "description": "

All fields

" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Entity unique id.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT Private (MAESTRO_SECRETJWT_PRIVATE)" } ], "header": { "fields": { "Header": [ { "group": "Header", "type": "String", "optional": false, "field": "Authorization", "description": "

JWT {Token}

" } ] } }, "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 204 OK\n{}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "get", "url": "/", "title": "Ping", "name": "GetPing", "group": "Ping", "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 200 OK\n{\n app: (String),\n description: (String),\n version: (Float),\n api_timeout: (Number)\n}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Ping" } ] }); diff --git a/docs/audit/api_data.json b/docs/audit/api_data.json index 9d79475..b8c8484 100644 --- a/docs/audit/api_data.json +++ b/docs/audit/api_data.json @@ -1 +1 @@ -[ { "type": "post", "url": "/api/:entity", "title": "c. Create record", "name": "CreateAudit", "group": "Audit", "parameter": { "fields": { "Body x-www": [ { "group": "Body x-www", "type": "String", "optional": true, "field": "entity_id", "description": "

Entity ID

" }, { "group": "Body x-www", "type": "String", "optional": true, "field": "roles", "description": "

Current roles

" }, { "group": "Body x-www", "type": "String", "optional": false, "field": "field", "description": "

All fields

" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT Audit (Contract)" } ], "header": { "fields": { "Header": [ { "group": "Header", "type": "String", "optional": false, "field": "Authorization", "description": "

JWT {Token}

" } ] } }, "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 201 OK\n{}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "get", "url": "/api/:entity", "title": "a. List record by entity", "name": "GetAudit", "group": "Audit", "parameter": { "fields": { "Query": [ { "group": "Query", "type": "String", "optional": true, "field": "token", "description": "

Authorization JWT {Token}

" }, { "group": "Query", "type": "String", "optional": false, "field": "entity_id", "description": "

Entity unique id

" }, { "group": "Query", "type": "Object", "optional": false, "field": "data", "description": "

Filter by field
Must used with dot notation, like

  \"data.hostname\": 'search by hostname' // or
\"data.datacenters.providers\": 'search by providers'
" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT (Read | Write | Admin)" } ], "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 200 OK\n[\n {\n _id: \n entity_id: \n entity: \n created_at: \n data: \n {}\n }\n]", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "get", "url": "/api/:entity/:id", "title": "b. Show record", "name": "GetAuditId", "group": "Audit", "parameter": { "fields": { "Query": [ { "group": "Query", "type": "String", "optional": true, "field": "token", "description": "

Authorization JWT {Token}

" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Entity unique id.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT (Read | Write | Admin)" } ], "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 200 OK\n[\n {\n _id: \n entity_id: \n entity: \n created_at: \n data: \n {}\n }\n]", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "get", "url": "/", "title": "Ping", "name": "GetPing", "group": "Ping", "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 200 OK\n{\n app: (String),\n description: (String),\n version: (Float),\n api_timeout: (Number)\n}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Ping" }, { "type": "post", "url": "/teams/:id/audit/:entity", "title": "ac. Create record", "name": "CreateTeamApi", "group": "Teams", "description": "

Use for teams scope, have be all actions, params and option in /audit/:entity,

", "parameter": { "fields": { "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Team unique ID.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "version": "0.0.0", "filename": "app/audit/routers/audit/index.js", "groupTitle": "Teams" }, { "type": "get", "url": "/teams/:id/audit/:entity", "title": "aa. List record by entity", "name": "GetTeamApi", "group": "Teams", "description": "

Use for teams scope, have be all actions, params and option in /audit/:entity,

", "parameter": { "fields": { "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Team unique ID.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "version": "0.0.0", "filename": "app/audit/routers/audit/index.js", "groupTitle": "Teams" }, { "type": "get", "url": "/teams/:id/audit/:entity", "title": "ab. Show record", "name": "GetTeamApiID", "group": "Teams", "description": "

Use for teams scope, have be all actions, params and option in /audit/:entity/:id,

", "parameter": { "fields": { "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Team unique ID.

" }, { "group": "Param", "type": "String", "optional": false, "field": "idu", "description": "

Entity unique ID.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "version": "0.0.0", "filename": "app/audit/routers/audit/index.js", "groupTitle": "Teams" } ] +[ { "type": "post", "url": "/audit/:entity/:id", "title": "c. Create new record", "name": "CreateAudit", "group": "Audit", "description": "

Set a full record on track

", "parameter": { "fields": { "Body x-www": [ { "group": "Body x-www", "type": "String", "optional": false, "field": "field", "description": "

All fields

" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Entity unique id.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT Private (MAESTRO_SECRETJWT_PRIVATE)" } ], "header": { "fields": { "Header": [ { "group": "Header", "type": "String", "optional": false, "field": "Authorization", "description": "

JWT {Token}

" } ] } }, "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 201 OK\n{}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "get", "url": "/audit/:entity/:id", "title": "b. Show record", "name": "GetAuditId", "group": "Audit", "parameter": { "fields": { "Query": [ { "group": "Query", "type": "String", "optional": true, "field": "token", "description": "

Authorization JWT {Token}

" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Entity unique id.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT Private (MAESTRO_SECRETJWT_PRIVATE)" } ], "header": { "fields": { "Header": [ { "group": "Header", "type": "String", "optional": false, "field": "Authorization", "description": "

JWT {Token}

" } ] } }, "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 200 OK\n[\n {\n _id: \n entity_id: \n entity: \n created_at: \n body: \n {}\n }\n]", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "patch", "url": "/audit/:entity/:id", "title": "e. Patch record command", "name": "PatchAudit", "group": "Audit", "description": "

Set a partial record on track

", "parameter": { "fields": { "Body x-www": [ { "group": "Body x-www", "type": "String", "optional": false, "field": "field", "description": "

All fields

" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Entity unique id.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT Private (MAESTRO_SECRETJWT_PRIVATE)" } ], "header": { "fields": { "Header": [ { "group": "Header", "type": "String", "optional": false, "field": "Authorization", "description": "

JWT {Token}

" } ] } }, "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 201 OK\n{}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "delete", "url": "/audit/:entity/:id", "title": "f. Remove record command", "name": "RemoveAudit", "group": "Audit", "description": "

Set a delete record on track

", "parameter": { "fields": { "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Entity unique id.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT Private (MAESTRO_SECRETJWT_PRIVATE)" } ], "header": { "fields": { "Header": [ { "group": "Header", "type": "String", "optional": false, "field": "Authorization", "description": "

JWT {Token}

" } ] } }, "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 201 OK\n{}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "put", "url": "/audit/:entity/:id", "title": "d. Set record command", "name": "UpdateAudit", "group": "Audit", "description": "

Set a full record on track

", "parameter": { "fields": { "Body x-www": [ { "group": "Body x-www", "type": "String", "optional": false, "field": "field", "description": "

All fields

" } ], "Param": [ { "group": "Param", "type": "String", "optional": false, "field": "id", "description": "

Entity unique id.

" }, { "group": "Param", "type": "String", "optional": false, "field": "entity", "description": "

Entity type {applications, servers, systems, clients, networks and etc}.

" } ] } }, "permission": [ { "name": "JWT Private (MAESTRO_SECRETJWT_PRIVATE)" } ], "header": { "fields": { "Header": [ { "group": "Header", "type": "String", "optional": false, "field": "Authorization", "description": "

JWT {Token}

" } ] } }, "error": { "fields": { "Error": [ { "group": "Error", "optional": false, "field": "PermissionError", "description": "

Token don`t have permission

" }, { "group": "Error", "optional": false, "field": "Unauthorized", "description": "

Invalid Token

" } ] } }, "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 204 OK\n{}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Audit" }, { "type": "get", "url": "/", "title": "Ping", "name": "GetPing", "group": "Ping", "success": { "examples": [ { "title": "Success-Response:", "content": "HTTP/1.1 200 OK\n{\n app: (String),\n description: (String),\n version: (Float),\n api_timeout: (Number)\n}", "type": "json" } ] }, "version": "0.0.0", "filename": "app/audit/routers/audit/audit.js", "groupTitle": "Ping" } ] diff --git a/docs/audit/api_project.js b/docs/audit/api_project.js index b68d8a0..d242bd1 100644 --- a/docs/audit/api_project.js +++ b/docs/audit/api_project.js @@ -1 +1 @@ -define({ "name": "API Maestro - Audit App", "version": "0.1.0", "description": "API documentation - HTML/RestFull", "apidoc": "0.3.0", "header": { "content": "

Maestro server - Cloud inventory is smart inventory platform, its a database of all information of multi datacenters.\nAudit App is webapp application port of Maestro Server stack, control and manage time tracking for each entity.

\n" }, "order": [ "Ping", "Audit" ], "sampleUrl": false, "defaultVersion": "0.0.0", "generator": { "name": "apidoc", "time": "2018-12-18T13:28:24.063Z", "url": "http://apidocjs.com", "version": "0.17.7" } }); +define({ "name": "API Maestro - Audit App", "version": "0.1.0", "description": "API documentation - HTML/RestFull", "apidoc": "0.3.0", "header": { "content": "

Maestro server - Cloud inventory is smart inventory platform, its a database of all information of multi datacenters.\nAudit App is webapp application port of Maestro Server stack, control and manage time tracking for each entity.

\n" }, "order": [ "Ping", "Audit" ], "sampleUrl": false, "defaultVersion": "0.0.0", "generator": { "name": "apidoc", "time": "2019-09-24T11:03:10.910Z", "url": "http://apidocjs.com", "version": "0.17.7" } }); diff --git a/docs/audit/api_project.json b/docs/audit/api_project.json index 700a483..0c2fd7e 100644 --- a/docs/audit/api_project.json +++ b/docs/audit/api_project.json @@ -1 +1 @@ -{ "name": "API Maestro - Audit App", "version": "0.1.0", "description": "API documentation - HTML/RestFull", "apidoc": "0.3.0", "header": { "content": "

Maestro server - Cloud inventory is smart inventory platform, its a database of all information of multi datacenters.\nAudit App is webapp application port of Maestro Server stack, control and manage time tracking for each entity.

\n" }, "order": [ "Ping", "Audit" ], "sampleUrl": false, "defaultVersion": "0.0.0", "generator": { "name": "apidoc", "time": "2018-12-18T13:28:24.063Z", "url": "http://apidocjs.com", "version": "0.17.7" } } +{ "name": "API Maestro - Audit App", "version": "0.1.0", "description": "API documentation - HTML/RestFull", "apidoc": "0.3.0", "header": { "content": "

Maestro server - Cloud inventory is smart inventory platform, its a database of all information of multi datacenters.\nAudit App is webapp application port of Maestro Server stack, control and manage time tracking for each entity.

\n" }, "order": [ "Ping", "Audit" ], "sampleUrl": false, "defaultVersion": "0.0.0", "generator": { "name": "apidoc", "time": "2019-09-24T11:03:10.910Z", "url": "http://apidocjs.com", "version": "0.17.7" } } diff --git a/test/e2e/audit.js b/test/e2e/audit.js new file mode 100644 index 0000000..cf1e802 --- /dev/null +++ b/test/e2e/audit.js @@ -0,0 +1,393 @@ +'use strict'; + +require('dotenv').config({path: '.env.test'}); + +let chai = require('chai'), + request = require('supertest'), + cleaner_db = require('./libs/cleaner_db'), + {expect} = chai; + +describe('e2e audit', function () { + + let app, mock; + + const token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhcHAiOiJzZXJ2ZXItYXBwIiwidmVyc2lvbiI6IjAuNS4xOCIsIm5vYXV0aCI6ImRlZmF1bHRTZWNyZXROb0F1dGhUb2tlbiJ9.mC4C8o7egeyR-az4Tnq2Lq6jv-uIg73OzjSueZdyLfg" + + let apps = [{ + hostname: "Myserver", + ipv4_private: "127.0.0.1", + ipv4_public: "127.0.0.1", + os: {base: 'Linux', dist: 'CentOs', version: "7"}, + cpu: '24', + memory: '24', + storage: [{name: '/dev/sda', size: 30, root: "true"}, {name: '/dev/sdb', size: 24}], + services: [{name: 'Apache', version: '7'}], + role: 'Application', + auth: [{name: 'mykey', type: 'PKI', username: 'signorini', key: 'master.pem'}], + tags: [{key: 'Tager', value: 'ValueTager'}], + }, { + name: "MySecondeapplication", + description: "My app description", + role: {role: 'Application'}, + family: "DNS", + thisFieldMustnApper: 'NotApper' + }]; + + let entries = [ + { + 'id': '5d8a25132cf2688fd2407ca6', + 'entity': 'servers' + }, + { + 'id': '5d8a25132cf2688fd2407ca7', + 'entity': 'applications' + } + ] + + before(function (done) { + cleaner_db([{tb: 'snapshots'}, {tb: 'audits'}], () => { + app = require('./libs/bootApp')(); + + app.once('start', done); + mock = app.listen(1344); + }, null); + }); + + after(function (done) { + mock.close(done); + }); + + + /** + * + * Create entry + * @depends create entry + * @description I like to create a new entry + */ + describe('create new entry', function () { + it('Create entry - create servers', function (done) { + request(mock) + .post('/audit/'+entries[0]['entity']+'/'+entries[0]['id']) + .send(apps[0]) + .set('Authorization', `JWT ${token}`) + .expect(201) + .expect('Content-Type', /json/) + .expect(/Myserver/) + .expect(/_id/) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + it('Create entry - create project without token', function (done) { + request(mock) + .post('/audit/'+entries[0]['entity']+'/'+entries[0]['id']) + .send(apps[0]) + .expect(401) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + it('Create entry - create applications', function (done) { + request(mock) + .post('/audit/'+entries[1]['entity']+'/'+entries[1]['id']) + .send(apps[1]) + .set('Authorization', `JWT ${token}`) + .expect(201) + .expect('Content-Type', /json/) + .expect(/MySecondeapplication/) + .expect(/_id/) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + }); + + /** + * + * read entry + * @depends read entry + * @description I like to read my entries + */ + describe('read entry', function () { + it('read server', function (done) { + request(mock) + .get('/audit/'+entries[0]['entity']+'/'+entries[0]['id']) + .set('Authorization', `JWT ${token}`) + .expect(200) + .expect('Content-Type', /json/) + .expect(/\"entity\":\"servers\"/) + .expect(/Myserver/) + .expect(/body/) + .expect(/memory/) + .expect(/tags/) + .expect(/tags/) + .expect(/role/) + .expect(/tags/) + .expect(/_id/) + .expect(/127.0.0.1/) + .expect(function (res) { + expect(res.body.items).to.have.length(1); + }) + .expect(function (res) { + Object.assign(entries[0]['entity'], res.body.entity); + Object.assign(apps[0], res.body.body); + }) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + it('read app', function (done) { + request(mock) + .get('/audit/'+entries[1]['entity']+'/'+entries[1]['id']) + .set('Authorization', `JWT ${token}`) + .expect(200) + .expect('Content-Type', /json/) + .expect(/\"entity\":\"applications\"/) + .expect(/MySecondeapplication/) + .expect(/body/) + .expect(/family/) + .expect(function (res) { + expect(res.body.items).to.have.length(1); + }) + .expect(function (res) { + Object.assign(entries[1]['entity'], res.body.entity); + Object.assign(apps[1], res.body.body); + }) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + }); + + describe('update new entry', function () { + it('Update entry - update servers - no changes', function (done) { + request(mock) + .put('/audit/'+entries[0]['entity']+'/'+entries[0]['id']) + .send(apps[0]) + .set('Authorization', `JWT ${token}`) + .expect(204) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + it('Update entry - update servers - with changes', function (done) { + apps[0]['hostname'] = 'Changename' + + request(mock) + .put('/audit/'+entries[0]['entity']+'/'+entries[0]['id']) + .send(apps[0]) + .set('Authorization', `JWT ${token}`) + .expect(204) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + it('Update entry - update project without token', function (done) { + request(mock) + .put('/audit/'+entries[0]['entity']+'/'+entries[0]['id']) + .send(apps[0]) + .expect(401) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + it('Update entry - update applications - no changes', function (done) { + request(mock) + .put('/audit/'+entries[1]['entity']+'/'+entries[1]['id']) + .send(apps[1]) + .set('Authorization', `JWT ${token}`) + .expect(204) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + }); + + describe('update new entry', function () { + it('Patch entry - patch servers - no changes', function (done) { + request(mock) + .patch('/audit/'+entries[0]['entity']+'/'+entries[0]['id']) + .send(apps[0]) + .set('Authorization', `JWT ${token}`) + .expect('Content-Type', /json/) + .expect(/\"entity\":\"servers\"/) + .expect(/Changename/) + .expect(201) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + it('Patch entry - patch servers - with changes', function (done) { + apps[0]['hostname'] = 'Changename2' + + request(mock) + .patch('/audit/'+entries[0]['entity']+'/'+entries[0]['id']) + .send(apps[0]) + .set('Authorization', `JWT ${token}`) + .expect('Content-Type', /json/) + .expect(/\"entity\":\"servers\"/) + .expect(/Changename2/) + .expect(201) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + it('Patch entry - patch project without token', function (done) { + request(mock) + .patch('/audit/'+entries[0]['entity']+'/'+entries[0]['id']) + .send(apps[0]) + .expect(401) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + }); + + + /** + * + * checking history + * @depends read entry + * @description I like to read my histories + */ + describe('read entry', function () { + it('checking history servers', function (done) { + request(mock) + .get('/audit/'+entries[0]['entity']+'/'+entries[0]['id']) + .set('Authorization', `JWT ${token}`) + .expect(200) + .expect('Content-Type', /json/) + .expect(/\"entity\":\"servers\"/) + .expect(/Myserver/) + .expect(/Changename/) + .expect(/Changename2/) + .expect(function (res) { + expect(res.body.items).to.have.length(3); + }) + .expect(function (res) { + Object.assign(entries[0]['entity'], res.body.entity); + Object.assign(apps[0], res.body.body); + }) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + it('checking history applications', function (done) { + request(mock) + .get('/audit/'+entries[1]['entity']+'/'+entries[1]['id']) + .set('Authorization', `JWT ${token}`) + .expect(200) + .expect('Content-Type', /json/) + .expect(/\"entity\":\"applications\"/) + .expect(/MySecondeapplication/) + .expect(/body/) + .expect(/family/) + .expect(function (res) { + expect(res.body.items).to.have.length(1); + }) + .expect(function (res) { + Object.assign(entries[1]['entity'], res.body.entity); + Object.assign(apps[1], res.body.body); + }) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + }); + + /** + * + * deleted entry + * @depends delete entry + * @description I like to mark a deleted item + */ + describe('delete servers', function () { + it('Delete entry - delete server', function (done) { + request(mock) + .delete('/audit/'+entries[0]['entity']+'/'+entries[0]['id']) + .set('Authorization', `JWT ${token}`) + .expect(201) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + it('Delete entry - delete application', function (done) { + request(mock) + .delete('/audit/'+entries[1]['entity']+'/'+entries[1]['id']) + .set('Authorization', `JWT ${token}`) + .expect(201) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + }); + + describe('read entry', function () { + it('checking deleted servers', function (done) { + request(mock) + .get('/audit/'+entries[0]['entity']+'/'+entries[0]['id']) + .set('Authorization', `JWT ${token}`) + .expect(200) + .expect('Content-Type', /json/) + .expect(/\"entity\":\"servers\"/) + .expect(/removed/) + .expect(function (res) { + expect(res.body.items).to.have.length(4); + }) + .expect(function (res) { + Object.assign(entries[0]['entity'], res.body.entity); + Object.assign(apps[0], res.body.body); + }) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + + it('checking deleted applications', function (done) { + request(mock) + .get('/audit/'+entries[1]['entity']+'/'+entries[1]['id']) + .set('Authorization', `JWT ${token}`) + .expect(200) + .expect('Content-Type', /json/) + .expect(/\"entity\":\"applications\"/) + .expect(/removed/) + .expect(function (res) { + expect(res.body.items).to.have.length(2); + }) + .end(function (err) { + if (err) return done(err); + done(err); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/e2e/libs/cleaner_db.js b/test/e2e/libs/cleaner_db.js index 8116980..ec7e94b 100644 --- a/test/e2e/libs/cleaner_db.js +++ b/test/e2e/libs/cleaner_db.js @@ -1,5 +1,7 @@ "use strict"; +require('app-module-path').addPath(`${__dirname}/../../../app`); + const _ = require('lodash'); let MongoClient = require("mongodb").MongoClient; const dbpath = require('core/libs/dbpath')();