-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #986 from ParsePlatform/mongo-uri-encode-auth
Add URI encoding to mongo auth parameters
- Loading branch information
Showing
4 changed files
with
1,046 additions
and
1 deletion.
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,37 @@ | ||
'use strict'; | ||
|
||
const MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter'); | ||
const MongoClient = require('mongodb').MongoClient; | ||
|
||
describe('MongoStorageAdapter', () => { | ||
it('auto-escapes symbols in auth information', () => { | ||
spyOn(MongoClient, 'connect').and.returnValue(Promise.resolve(null)); | ||
new MongoStorageAdapter('mongodb://user!with@+ symbols:password!with@+ symbols@localhost:1234/parse', {}) | ||
.connect(); | ||
expect(MongoClient.connect).toHaveBeenCalledWith( | ||
'mongodb://user!with%40%2B%20symbols:password!with%40%2B%20symbols@localhost:1234/parse', | ||
jasmine.any(Object) | ||
); | ||
}); | ||
|
||
it("doesn't double escape already URI-encoded information", () => { | ||
spyOn(MongoClient, 'connect').and.returnValue(Promise.resolve(null)); | ||
new MongoStorageAdapter('mongodb://user!with%40%2B%20symbols:password!with%40%2B%20symbols@localhost:1234/parse', {}) | ||
.connect(); | ||
expect(MongoClient.connect).toHaveBeenCalledWith( | ||
'mongodb://user!with%40%2B%20symbols:password!with%40%2B%20symbols@localhost:1234/parse', | ||
jasmine.any(Object) | ||
); | ||
}); | ||
|
||
// https://github.com/ParsePlatform/parse-server/pull/148#issuecomment-180407057 | ||
it('preserves replica sets', () => { | ||
spyOn(MongoClient, 'connect').and.returnValue(Promise.resolve(null)); | ||
new MongoStorageAdapter('mongodb://test:testpass@ds056315-a0.mongolab.com:59325,ds059315-a1.mongolab.com:59315/testDBname?replicaSet=rs-ds059415', {}) | ||
.connect(); | ||
expect(MongoClient.connect).toHaveBeenCalledWith( | ||
'mongodb://test:testpass@ds056315-a0.mongolab.com:59325,ds059315-a1.mongolab.com:59315/testDBname?replicaSet=rs-ds059415', | ||
jasmine.any(Object) | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# mongoUrl | ||
|
||
A fork of node's `url` module, with the modification that commas and colons are | ||
allowed in hostnames. While this results in a slightly incorrect parsed result, | ||
as the hostname field for a mongodb should be an array of replica sets, it's | ||
good enough to let us pull out and escape the auth portion of the URL. | ||
|
||
See also: https://github.com/ParsePlatform/parse-server/pull/986 |
Oops, something went wrong.