-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: hide password of mongo url (#32)
* Add URL Mask Package * Add URL Mask To Filter Mongo URL * Setup URL Mask Only Filter Password * Add New Feature filterURLPassword /lib/filterURLPassword.js add new .js file /lib/mongoose.js replace the url-mask to filterURLPassword /test/mongoose.test.js add testing * Lint Code * backwards compatibility to node.js v6.13.0 * Add semver Package, Use legacy API url.parse If version less than 6.13.0 * Refactor filterURLPassword
- Loading branch information
1 parent
0c15d08
commit 441b6fc
Showing
4 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const semver = require('semver'); | ||
|
||
/** | ||
* filter the auth of url string | ||
* @param {URL} input url | ||
* @param {String} version version string from `process.version` | ||
* @return {String} filtered url | ||
*/ | ||
module.exports = function filterURLPassword(input, version) { | ||
if (semver.lt(version, '6.13.0')) { | ||
const urlTool = require('url'); | ||
const url = urlTool.parse(input); | ||
url.password = '*****'; | ||
url.auth = url.auth && (url.auth.split(':')[0] + ':*****'); | ||
return urlTool.format(url); | ||
} | ||
const { URL } = require('url'); | ||
const url = new URL(input); | ||
url.password = '*****'; | ||
return url.toString(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,17 @@ describe('test/mongoose.test.js', () => { | |
const query = app.model.User.findOne({}); | ||
assert.equal(query.exec().constructor, Promise); | ||
}); | ||
|
||
it('should filter password of url', () => { | ||
const filterURLPassword = require('../lib/filterURLPassword'); | ||
const url = 'https://abc:[email protected]/'; | ||
const outputV10 = filterURLPassword(url, 'v10.0.0'); | ||
assert.equal(outputV10, 'https://abc:*****@example.com/'); | ||
const outputV8 = filterURLPassword(url, 'v8.0.0'); | ||
assert.equal(outputV8, 'https://abc:*****@example.com/'); | ||
const outputV6 = filterURLPassword(url, 'v6.0.0'); | ||
assert.equal(outputV6, 'https://abc:*****@example.com/'); | ||
}); | ||
}); | ||
|
||
describe('custom promise', () => { | ||
|