Skip to content

Commit 741039b

Browse files
committed
Add (failing) tests for uri encoding auth
1 parent d5b9af2 commit 741039b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

spec/MongoStorageAdapter.spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
const MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
4+
const MongoClient = require('mongodb').MongoClient;
5+
6+
describe('MongoStorageAdapter', () => {
7+
it('auto-escapes symbols in auth information', () => {
8+
spyOn(MongoClient, 'connect').and.returnValue(Promise.resolve(null));
9+
new MongoStorageAdapter('mongodb://user!with@+ symbols:password!with@+ symbols@localhost:1234/parse', {})
10+
.connect();
11+
expect(MongoClient.connect).toHaveBeenCalledWith(
12+
'mongodb://user!with%40%2B%20symbols:password!with%40%2B%20symbols@localhost:1234/parse',
13+
jasmine.any(Object)
14+
);
15+
});
16+
17+
it("doesn't double escape already URI-encoded information", () => {
18+
spyOn(MongoClient, 'connect').and.returnValue(Promise.resolve(null));
19+
new MongoStorageAdapter('mongodb://user!with%40%2B%20symbols:password!with%40%2B%20symbols@localhost:1234/parse', {})
20+
.connect();
21+
expect(MongoClient.connect).toHaveBeenCalledWith(
22+
'mongodb://user!with%40%2B%20symbols:password!with%40%2B%20symbols@localhost:1234/parse',
23+
jasmine.any(Object)
24+
);
25+
});
26+
27+
// https://github.com/ParsePlatform/parse-server/pull/148#issuecomment-180407057
28+
it('preserves replica sets', () => {
29+
spyOn(MongoClient, 'connect').and.returnValue(Promise.resolve(null));
30+
new MongoStorageAdapter('mongodb://test:[email protected]:59325,ds059315-a1.mongolab.com:59315/testDBname?replicaSet=rs-ds059415', {})
31+
.connect();
32+
expect(MongoClient.connect).toHaveBeenCalledWith(
33+
'mongodb://test:[email protected]:59325,ds059315-a1.mongolab.com:59315/testDBname?replicaSet=rs-ds059415',
34+
jasmine.any(Object)
35+
);
36+
});
37+
});

0 commit comments

Comments
 (0)