Initial import from local backup (Documents-Playground/pakerpale)
This commit is contained in:
11
node_modules/express-logging/.eslintrc
generated
vendored
Normal file
11
node_modules/express-logging/.eslintrc
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"rules": {
|
||||
"no-use-before-define": [2, "nofunc"], //latedef in jshint
|
||||
"quotes": [2, "single"],
|
||||
"no-underscore-dangle": 0,
|
||||
"new-cap": [1, {"capIsNew": false}]
|
||||
}
|
||||
}
|
||||
10
node_modules/express-logging/.jscsrc
generated
vendored
Normal file
10
node_modules/express-logging/.jscsrc
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"preset": "google",
|
||||
"maximumLineLength": 120,
|
||||
"disallowSpacesInCallExpression": true,
|
||||
"validateJSDoc": null,
|
||||
"disallowMultipleVarDecl": null,
|
||||
"requireSpacesInNamedFunctionExpression": {
|
||||
"beforeOpeningCurlyBrace": true
|
||||
}
|
||||
}
|
||||
7
node_modules/express-logging/.npmignore
generated
vendored
Normal file
7
node_modules/express-logging/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
node_modules/
|
||||
coverage/
|
||||
report/
|
||||
site/
|
||||
.idea/
|
||||
.DS_Store
|
||||
*.log
|
||||
5
node_modules/express-logging/.travis.yml
generated
vendored
Normal file
5
node_modules/express-logging/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
script: "npm run travis"
|
||||
24
node_modules/express-logging/CONTRIBUTING.md
generated
vendored
Normal file
24
node_modules/express-logging/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Contributing
|
||||
|
||||
1. Make a fork
|
||||
|
||||
2. Test the code!
|
||||
```sh
|
||||
npm run test
|
||||
```
|
||||
|
||||
3. Check your coverage!
|
||||
```sh
|
||||
npm run coverage
|
||||
```
|
||||
|
||||
4. Lint your code!
|
||||
```sh
|
||||
npm run lint
|
||||
```
|
||||
|
||||
5. Try to squash your commits (optional)
|
||||
|
||||
6. Make a PR to the develop branch
|
||||
|
||||
7. Thanks a lot!
|
||||
176
node_modules/express-logging/LICENSE
generated
vendored
Normal file
176
node_modules/express-logging/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
13
node_modules/express-logging/NOTICE
generated
vendored
Normal file
13
node_modules/express-logging/NOTICE
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
Copyright 2014,2015 Telefónica I+D
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
99
node_modules/express-logging/README.md
generated
vendored
Normal file
99
node_modules/express-logging/README.md
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
# express-logging
|
||||
|
||||
Express middleware to log, using a configurable logger, each request and response.
|
||||
|
||||
[](http://badge.fury.io/js/express-logging)
|
||||
[](https://travis-ci.org/telefonica/node-express-logging)
|
||||
[](https://coveralls.io/r/telefonica/node-express-logging)
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install express-logging
|
||||
```
|
||||
|
||||
## Basic usage
|
||||
|
||||
```js
|
||||
var express = require('express'),
|
||||
expressLogging = require('express-logging'),
|
||||
logger = require('logops');
|
||||
|
||||
var app = express();
|
||||
app.use(expressLogging(logger));
|
||||
|
||||
app.listen(3000);
|
||||
```
|
||||
|
||||
## Extended usage with options
|
||||
|
||||
An optional argument `options` can customize enhanced aspects for the logging. This argument is an object with the following elements:
|
||||
|
||||
- `blacklist` is available to prevent some resources from being logged (for example, static resources). This argument is an array of strings. If the URL path starts with any of the elements of the blacklist array, then the logging of this request/response is ignored.
|
||||
- `policy` is a string to customize how the info is logged. It supports two values: `message` or `params`. The former serializes all the log entry into a single string message. The latter passes to the logger an object with the log entry parameters and a second argument with the message; this policy is useful in order to process these parameters by systems like logstash. The default value is `message`.
|
||||
|
||||
The following example would ignore any resource available at either `/images` or `/html`. It also activates the logging policy `params`.
|
||||
|
||||
```js
|
||||
var blacklist = ['/images', '/html'];
|
||||
app.use(expressLogging(logger, {blacklist: blacklist, policy: 'params'}));
|
||||
```
|
||||
|
||||
## Logs
|
||||
|
||||
### Logging with default policy **message**
|
||||
|
||||
The request is logged with:
|
||||
|
||||
```js
|
||||
logger.info('Request from %s: %s %s', clientIpAddress, requestMethod, requestUrl);
|
||||
```
|
||||
|
||||
A response without `Location` header is logged with:
|
||||
|
||||
```js
|
||||
logger.info('Response with status %d in %d ms.', responseStatusCode, duration);
|
||||
```
|
||||
|
||||
A response with `Location` header is logged with:
|
||||
|
||||
```js
|
||||
logger.info('Response with status %d in %d ms. Location: %s', responseStatusCode, duration, locationHeader);
|
||||
```
|
||||
|
||||
Both response log entries include the `duration` of the whole transaction (between receiving the request until replying with the response).
|
||||
|
||||
### Logging with policy **params**
|
||||
|
||||
The request is logged with:
|
||||
|
||||
```js
|
||||
var params = {requestClientIp: requestClientIp, requestMethod: requestMethod, requestUrl: requestUrl};
|
||||
logger.info(params, 'Request from %s: %s', requestMethod, requestUrl);
|
||||
```
|
||||
|
||||
A response without `Location` header is logged with:
|
||||
|
||||
```js
|
||||
var params = {responseStatusCode: responseStatusCode, responseDuration: duration};
|
||||
logger.info(params, 'Response with status %d', responseStatusCode);
|
||||
```
|
||||
|
||||
A response with `Location` header is logged with:
|
||||
|
||||
```js
|
||||
var params = {responseStatusCode: responseStatusCode, responseDuration: duration, responseLocation: locationHeader};
|
||||
logger.info(params, 'Response with status %d', responseStatusCode);
|
||||
```
|
||||
|
||||
Both response log entries include the `duration` of the whole transaction (between receiving the request until replying with the response).
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2015, 2016 [Telefónica Investigación y Desarrollo, S.A.U](http://www.tid.es)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
115
node_modules/express-logging/lib/logging.js
generated
vendored
Normal file
115
node_modules/express-logging/lib/logging.js
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var onHeaders = require('on-headers');
|
||||
|
||||
/**
|
||||
* Express middleware to log the request and response.
|
||||
*
|
||||
* @param {Object} logger
|
||||
* Logger.
|
||||
* @param {Object} opts
|
||||
* Object with optional arguments including:
|
||||
* - blacklist: Array of URL paths to be ignored (e.g. paths for static content)
|
||||
* - policy: Policy to generate the log entry in the logger. Possible values:
|
||||
* - message. Only message. Params are included into the message.
|
||||
* - params. Logger receives an object with the params, and the message.
|
||||
* @return {Function(req, res, next)} Express middleware.
|
||||
*/
|
||||
module.exports = function(logger, opts) {
|
||||
|
||||
var blacklist = opts && opts.blacklist || [];
|
||||
var policy = opts && opts.policy;
|
||||
|
||||
/**
|
||||
* Return the client address from the last IP address in X-Forwarded-For HTTP header. If not possible to
|
||||
* obtain it from X-Forwarded-For header, then return req.ip (however, this value typically is the load
|
||||
* balancer IP address and it does not provide any valuable information).
|
||||
*
|
||||
* @param {Object} req
|
||||
* Express request
|
||||
* @return {String}
|
||||
* Client IP address
|
||||
*/
|
||||
function getClientIp(req) {
|
||||
var xff = req.get('x-forwarded-for');
|
||||
if (xff) {
|
||||
var ips = xff.split(',').map(function onIp(ip) {
|
||||
return ip.trim();
|
||||
});
|
||||
var ip = ips[ips.length - 1];
|
||||
if (ip) {
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
return req.ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the request URL starts with any of the blacklist paths.
|
||||
*
|
||||
* @param {String} url
|
||||
* Request url
|
||||
* @return {Boolean}
|
||||
* True if the request URL is included in the blacklist.
|
||||
*/
|
||||
function isUrlBlackedListed(url) {
|
||||
return blacklist.some(function(blackListUrl) {
|
||||
return url.indexOf(blackListUrl) === 0;
|
||||
});
|
||||
}
|
||||
|
||||
return function loggingMiddleware(req, res, next) {
|
||||
if (!isUrlBlackedListed(req.originalUrl)) {
|
||||
var startTime = Date.now();
|
||||
if (policy === 'params') {
|
||||
var requestParams = {
|
||||
requestClientIp: getClientIp(req),
|
||||
requestMethod: req.method,
|
||||
requestUrl: req.originalUrl
|
||||
};
|
||||
logger.info(requestParams, 'Request: %s %s', req.method, req.originalUrl);
|
||||
} else {
|
||||
logger.info('Request from %s: %s %s', getClientIp(req), req.method, req.originalUrl);
|
||||
}
|
||||
|
||||
onHeaders(res, function onResponse() {
|
||||
var duration = Date.now() - startTime;
|
||||
var location = res.get('location');
|
||||
if (policy === 'params') {
|
||||
var responseParams = {
|
||||
responseStatusCode: res.statusCode,
|
||||
responseDuration: duration,
|
||||
responseLocation: location
|
||||
};
|
||||
logger.info(responseParams, 'Response with status %d', res.statusCode);
|
||||
} else {
|
||||
if (location) {
|
||||
logger.info('Response with status %d in %d ms. Location: %s', res.statusCode, duration, location);
|
||||
} else {
|
||||
logger.info('Response with status %d in %d ms.', res.statusCode, duration);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
};
|
||||
87
node_modules/express-logging/package.json
generated
vendored
Normal file
87
node_modules/express-logging/package.json
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
{
|
||||
"_from": "express-logging",
|
||||
"_id": "express-logging@1.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-YoOWGMurW7NhDxocFIU1L+nSbCo=",
|
||||
"_location": "/express-logging",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "express-logging",
|
||||
"name": "express-logging",
|
||||
"escapedName": "express-logging",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/express-logging/-/express-logging-1.1.1.tgz",
|
||||
"_shasum": "62839618cbab5bb3610f1a1c1485352fe9d26c2a",
|
||||
"_spec": "express-logging",
|
||||
"_where": "D:\\dev\\crossmap\\backend-services\\cm-app-crawlspider",
|
||||
"author": {
|
||||
"name": "Jorge Lorenzo Gallardo",
|
||||
"email": "jorge.lorenzogallardo@telefonica.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/telefonica/node-express-logging/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Juan Antonio Hernando Labajo",
|
||||
"email": "juanantonio.hernandolabajo@telefonica.com"
|
||||
},
|
||||
{
|
||||
"name": "Guido García Bernardo",
|
||||
"email": "guido.garciabernardo@telefonica.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"on-headers": "^1.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Express middleware to log each request and response",
|
||||
"devDependencies": {
|
||||
"chai": "^3.0.0",
|
||||
"coveralls": "^2.11.2",
|
||||
"eslint": "^0.23.0",
|
||||
"istanbul": "^0.3.16",
|
||||
"jscs": "^1.13.1",
|
||||
"mocha": "^2.2.5",
|
||||
"proxyquire": "^1.5.0",
|
||||
"should": "^7.0.1",
|
||||
"sinon": "~1.15.3",
|
||||
"sinon-chai": "^2.8.0",
|
||||
"supertest": "^1.0.1",
|
||||
"xunit-file": "^0.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10.26"
|
||||
},
|
||||
"homepage": "https://github.com/telefonica/node-express-logging#readme",
|
||||
"keywords": [
|
||||
"logging",
|
||||
"express",
|
||||
"middleware"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"main": "lib/logging",
|
||||
"name": "express-logging",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/telefonica/node-express-logging.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha -- -R dot test/environment.js test/unit/*-test.js",
|
||||
"lint": "jscs lib && eslint lib",
|
||||
"prepublish": "npm run test && npm run lint",
|
||||
"test": "mocha -R spec test/environment.js test/unit/*-test.js",
|
||||
"travis": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec test/environment.js test/*-test.js && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
|
||||
},
|
||||
"version": "1.1.1"
|
||||
}
|
||||
15
node_modules/express-logging/test/environment.js
generated
vendored
Normal file
15
node_modules/express-logging/test/environment.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
var sinon = require ('sinon'),
|
||||
chai = require ('chai'),
|
||||
sinonChai = require('sinon-chai');
|
||||
|
||||
chai.use(sinonChai);
|
||||
|
||||
global.expect = chai.expect;
|
||||
|
||||
beforeEach(function(){
|
||||
global.sinon = sinon.sandbox.create();
|
||||
});
|
||||
|
||||
afterEach(function(){
|
||||
global.sinon.restore();
|
||||
});
|
||||
399
node_modules/express-logging/test/unit/logging-test.js
generated
vendored
Normal file
399
node_modules/express-logging/test/unit/logging-test.js
generated
vendored
Normal file
@@ -0,0 +1,399 @@
|
||||
'use strict';
|
||||
|
||||
var proxyquire = require('proxyquire'),
|
||||
sinon = require('sinon');
|
||||
|
||||
describe('Logging Middleware Tests', function() {
|
||||
|
||||
var loggingMiddleware,
|
||||
loggerSpy;
|
||||
|
||||
beforeEach(function() {
|
||||
var loggerMock = {
|
||||
info: function() {}
|
||||
};
|
||||
loggerSpy = sinon.spy(loggerMock, 'info');
|
||||
|
||||
var onHeadersMock = function(res, cb) {
|
||||
cb();
|
||||
};
|
||||
|
||||
var LoggingMiddleware = proxyquire('../../lib/logging', {
|
||||
'on-headers': onHeadersMock
|
||||
});
|
||||
loggingMiddleware = new LoggingMiddleware(loggerMock);
|
||||
});
|
||||
|
||||
it('should log the request and response', function() {
|
||||
var req = {
|
||||
method: 'GET',
|
||||
ip: '10.128.201.134',
|
||||
originalUrl: '/test?jwt=xxx',
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
var res = {
|
||||
statusCode: 200,
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
loggingMiddleware(req, res, function() {
|
||||
expect(loggerSpy.calledTwice).to.be.true;
|
||||
expect(loggerSpy.getCall(0).args).to.be.deep.equal([
|
||||
'Request from %s: %s %s',
|
||||
'10.128.201.134',
|
||||
'GET',
|
||||
'/test?jwt=xxx']);
|
||||
expect(loggerSpy.getCall(1).args[0]).to.be.equal('Response with status %d in %d ms.');
|
||||
expect(loggerSpy.getCall(1).args[1]).to.be.equal(200);
|
||||
});
|
||||
});
|
||||
|
||||
it('should log the request and response with location header', function() {
|
||||
var req = {
|
||||
method: 'GET',
|
||||
ip: '10.128.201.134',
|
||||
originalUrl: '/test?jwt=xxx',
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
var res = {
|
||||
statusCode: 302,
|
||||
get: function(headerName) {
|
||||
if (headerName === 'location') {
|
||||
return 'http://localhost:9000/location';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
loggingMiddleware(req, res, function() {
|
||||
expect(loggerSpy.calledTwice).to.be.true;
|
||||
expect(loggerSpy.getCall(0).args).to.be.deep.equal([
|
||||
'Request from %s: %s %s',
|
||||
'10.128.201.134',
|
||||
'GET',
|
||||
'/test?jwt=xxx']);
|
||||
expect(loggerSpy.getCall(1).args[0]).to.be.equal('Response with status %d in %d ms. Location: %s');
|
||||
expect(loggerSpy.getCall(1).args[1]).to.be.equal(302);
|
||||
expect(loggerSpy.getCall(1).args[3]).to.be.equal('http://localhost:9000/location');
|
||||
});
|
||||
});
|
||||
|
||||
it('should log the request and response with client IP from XFF header', function() {
|
||||
var req = {
|
||||
method: 'GET',
|
||||
ip: '10.128.201.134',
|
||||
originalUrl: '/test?jwt=xxx',
|
||||
get: function(name) {
|
||||
if (name === 'x-forwarded-for') {
|
||||
return '1.1.1.1, 10.128.201.200';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
var res = {
|
||||
statusCode: 200,
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
loggingMiddleware(req, res, function() {
|
||||
expect(loggerSpy.calledTwice).to.be.true;
|
||||
expect(loggerSpy.getCall(0).args).to.be.deep.equal([
|
||||
'Request from %s: %s %s',
|
||||
'10.128.201.200',
|
||||
'GET',
|
||||
'/test?jwt=xxx']);
|
||||
expect(loggerSpy.getCall(1).args[0]).to.be.equal('Response with status %d in %d ms.');
|
||||
expect(loggerSpy.getCall(1).args[1]).to.be.equal(200);
|
||||
});
|
||||
});
|
||||
|
||||
it('should log the request and response with client IP from request if invalid XFF header', function() {
|
||||
var req = {
|
||||
method: 'GET',
|
||||
ip: '10.128.201.134',
|
||||
originalUrl: '/test?jwt=xxx',
|
||||
get: function(name) {
|
||||
if (name === 'x-forwarded-for') {
|
||||
return '1.1.1.1, 10.128.201.200, ';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
var res = {
|
||||
statusCode: 200,
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
loggingMiddleware(req, res, function() {
|
||||
expect(loggerSpy.calledTwice).to.be.true;
|
||||
expect(loggerSpy.getCall(0).args).to.be.deep.equal([
|
||||
'Request from %s: %s %s',
|
||||
'10.128.201.134',
|
||||
'GET',
|
||||
'/test?jwt=xxx']);
|
||||
expect(loggerSpy.getCall(1).args[0]).to.be.equal('Response with status %d in %d ms.');
|
||||
expect(loggerSpy.getCall(1).args[1]).to.be.equal(200);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Logging Middleware Tests with params policy', function() {
|
||||
|
||||
var loggingMiddleware,
|
||||
loggerSpy;
|
||||
|
||||
beforeEach(function() {
|
||||
var loggerMock = {
|
||||
info: function() {}
|
||||
};
|
||||
loggerSpy = sinon.spy(loggerMock, 'info');
|
||||
|
||||
var onHeadersMock = function(res, cb) {
|
||||
cb();
|
||||
};
|
||||
|
||||
var LoggingMiddleware = proxyquire('../../lib/logging', {
|
||||
'on-headers': onHeadersMock
|
||||
});
|
||||
loggingMiddleware = new LoggingMiddleware(loggerMock, {policy: 'params'});
|
||||
});
|
||||
|
||||
it('should log the request and response', function() {
|
||||
var req = {
|
||||
method: 'GET',
|
||||
ip: '10.128.201.134',
|
||||
originalUrl: '/test?jwt=xxx',
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
var res = {
|
||||
statusCode: 200,
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
loggingMiddleware(req, res, function() {
|
||||
expect(loggerSpy.calledTwice).to.be.true;
|
||||
expect(loggerSpy.getCall(0).args).to.be.deep.equal([
|
||||
{
|
||||
requestClientIp: '10.128.201.134',
|
||||
requestMethod: 'GET',
|
||||
requestUrl: '/test?jwt=xxx'
|
||||
},
|
||||
'Request: %s %s',
|
||||
'GET',
|
||||
'/test?jwt=xxx'
|
||||
]);
|
||||
expect(loggerSpy.getCall(1).args[0].responseStatusCode).to.be.equal(200);
|
||||
expect(loggerSpy.getCall(1).args[0].responseLocation).not.to.be.defined;
|
||||
expect(loggerSpy.getCall(1).args[1]).to.be.equal('Response with status %d');
|
||||
expect(loggerSpy.getCall(1).args[2]).to.be.equal(200);
|
||||
});
|
||||
});
|
||||
|
||||
it('should log the request and response with location header', function() {
|
||||
var req = {
|
||||
method: 'GET',
|
||||
ip: '10.128.201.134',
|
||||
originalUrl: '/test?jwt=xxx',
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
var res = {
|
||||
statusCode: 302,
|
||||
get: function(headerName) {
|
||||
if (headerName === 'location') {
|
||||
return 'http://localhost:9000/location';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
loggingMiddleware(req, res, function() {
|
||||
expect(loggerSpy.calledTwice).to.be.true;
|
||||
expect(loggerSpy.getCall(0).args).to.be.deep.equal([
|
||||
{
|
||||
requestClientIp: '10.128.201.134',
|
||||
requestMethod: 'GET',
|
||||
requestUrl: '/test?jwt=xxx'
|
||||
},
|
||||
'Request: %s %s',
|
||||
'GET',
|
||||
'/test?jwt=xxx'
|
||||
]);
|
||||
expect(loggerSpy.getCall(1).args[0].responseStatusCode).to.be.equal(302);
|
||||
expect(loggerSpy.getCall(1).args[0].responseLocation).to.be.equal('http://localhost:9000/location');
|
||||
expect(loggerSpy.getCall(1).args[1]).to.be.equal('Response with status %d');
|
||||
expect(loggerSpy.getCall(1).args[2]).to.be.equal(302);
|
||||
});
|
||||
});
|
||||
|
||||
it('should log the request and response with client IP from XFF header', function() {
|
||||
var req = {
|
||||
method: 'GET',
|
||||
ip: '10.128.201.134',
|
||||
originalUrl: '/test?jwt=xxx',
|
||||
get: function(name) {
|
||||
if (name === 'x-forwarded-for') {
|
||||
return '1.1.1.1, 10.128.201.200';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
var res = {
|
||||
statusCode: 200,
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
loggingMiddleware(req, res, function() {
|
||||
expect(loggerSpy.calledTwice).to.be.true;
|
||||
expect(loggerSpy.getCall(0).args).to.be.deep.equal([
|
||||
{
|
||||
requestClientIp: '10.128.201.200',
|
||||
requestMethod: 'GET',
|
||||
requestUrl: '/test?jwt=xxx'
|
||||
},
|
||||
'Request: %s %s',
|
||||
'GET',
|
||||
'/test?jwt=xxx'
|
||||
]);
|
||||
expect(loggerSpy.getCall(1).args[0].responseStatusCode).to.be.equal(200);
|
||||
expect(loggerSpy.getCall(1).args[0].responseLocation).not.to.be.defined;
|
||||
expect(loggerSpy.getCall(1).args[1]).to.be.equal('Response with status %d');
|
||||
expect(loggerSpy.getCall(1).args[2]).to.be.equal(200);
|
||||
});
|
||||
});
|
||||
|
||||
it('should log the request and response with client IP from request if invalid XFF header', function() {
|
||||
var req = {
|
||||
method: 'GET',
|
||||
ip: '10.128.201.134',
|
||||
originalUrl: '/test?jwt=xxx',
|
||||
get: function(name) {
|
||||
if (name === 'x-forwarded-for') {
|
||||
return '1.1.1.1, 10.128.201.200, ';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
var res = {
|
||||
statusCode: 200,
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
loggingMiddleware(req, res, function() {
|
||||
expect(loggerSpy.calledTwice).to.be.true;
|
||||
expect(loggerSpy.getCall(0).args).to.be.deep.equal([
|
||||
{
|
||||
requestClientIp: '10.128.201.134',
|
||||
requestMethod: 'GET',
|
||||
requestUrl: '/test?jwt=xxx'
|
||||
},
|
||||
'Request: %s %s',
|
||||
'GET',
|
||||
'/test?jwt=xxx'
|
||||
]);
|
||||
expect(loggerSpy.getCall(1).args[0].responseStatusCode).to.be.equal(200);
|
||||
expect(loggerSpy.getCall(1).args[0].responseLocation).not.to.be.defined;
|
||||
expect(loggerSpy.getCall(1).args[1]).to.be.equal('Response with status %d');
|
||||
expect(loggerSpy.getCall(1).args[2]).to.be.equal(200);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Logging Middleware Tests with blacklist', function() {
|
||||
|
||||
var loggingMiddleware,
|
||||
loggerSpy;
|
||||
|
||||
beforeEach(function() {
|
||||
var loggerMock = {
|
||||
info: function() {}
|
||||
};
|
||||
loggerSpy = sinon.spy(loggerMock, 'info');
|
||||
|
||||
var onHeadersMock = function(res, cb) {
|
||||
cb();
|
||||
};
|
||||
|
||||
var LoggingMiddleware = proxyquire('../../lib/logging', {
|
||||
'on-headers': onHeadersMock
|
||||
});
|
||||
loggingMiddleware = new LoggingMiddleware(loggerMock, {blacklist: ['/blacklist']});
|
||||
});
|
||||
|
||||
it('should log the request and response', function() {
|
||||
var req = {
|
||||
method: 'GET',
|
||||
ip: '10.128.201.134',
|
||||
originalUrl: '/test?jwt=xxx',
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
var res = {
|
||||
statusCode: 200,
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
loggingMiddleware(req, res, function() {
|
||||
expect(loggerSpy.calledTwice).to.be.true;
|
||||
expect(loggerSpy.getCall(0).args).to.be.deep.equal([
|
||||
'Request from %s: %s %s',
|
||||
'10.128.201.134',
|
||||
'GET',
|
||||
'/test?jwt=xxx']);
|
||||
expect(loggerSpy.getCall(1).args[0]).to.be.equal('Response with status %d in %d ms.');
|
||||
expect(loggerSpy.getCall(1).args[1]).to.be.equal(200);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not log anything when the url path is in the blacklist', function() {
|
||||
var req = {
|
||||
method: 'GET',
|
||||
ip: '10.128.201.134',
|
||||
originalUrl: '/blacklist/test?jwt=xxx',
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
var res = {
|
||||
statusCode: 200,
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
loggingMiddleware(req, res, function() {
|
||||
expect(loggerSpy.called).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user