forked from eggjs/egg-mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace auth with string replace (eggjs#34)
- Loading branch information
Showing
5 changed files
with
13 additions
and
26 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ language: node_js | |
node_js: | ||
- '8' | ||
- '10' | ||
- '12' | ||
install: | ||
- npm i npminstall && npminstall | ||
script: | ||
|
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 |
---|---|---|
@@ -1,23 +1,14 @@ | ||
'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 | ||
* @see https://docs.mongodb.com/manual/reference/connection-string/ | ||
*/ | ||
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(); | ||
module.exports = function filterURLPassword(input) { | ||
const index = input.indexOf('@'); | ||
if (index === -1) return input; | ||
const startIndex = input.lastIndexOf(':', index); | ||
return input.substring(0, startIndex + 1) + '******' + input.substring(index); | ||
}; |
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 |
---|---|---|
|
@@ -82,13 +82,9 @@ describe('test/mongoose.test.js', () => { | |
|
||
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/'); | ||
assert(filterURLPassword('https://example.com/') === 'https://example.com/'); | ||
assert(filterURLPassword('https://abc:[email protected]/') === 'https://abc:******@example.com/'); | ||
assert(filterURLPassword('mongodb://abc:[email protected]:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/admin?replicaSet=myRepl') === 'mongodb://abc:******@mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/admin?replicaSet=myRepl'); | ||
}); | ||
}); | ||
|
||
|