Skip to content

Commit 042d1ba

Browse files
Remove CLI flag, use databaseVersion & engine
1 parent de188d3 commit 042d1ba

File tree

9 files changed

+74
-25
lines changed

9 files changed

+74
-25
lines changed

spec/DatabaseController.spec.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,62 @@
11
const DatabaseController = require('../lib/Controllers/DatabaseController.js');
2+
const isVersionAffectedByServer13732 =
3+
DatabaseController._isVersionAffectedByServer13732;
24
const validateQuery = DatabaseController._validateQuery;
35

46
describe('DatabaseController', function() {
7+
describe('isVersionAffectedByServer13732', function() {
8+
it('should only return true for affected versions of mongodb', function() {
9+
for (let patch = 0; patch <= 12; patch++) {
10+
expect(
11+
isVersionAffectedByServer13732('MongoDB', '2.6.' + patch)
12+
).toEqual(true);
13+
expect(
14+
isVersionAffectedByServer13732('PostgreSQL', '2.6.' + patch)
15+
).toEqual(false);
16+
}
17+
for (let patch = 0; patch <= 15; patch++) {
18+
expect(
19+
isVersionAffectedByServer13732('MongoDB', '3.0.' + patch)
20+
).toEqual(true);
21+
expect(
22+
isVersionAffectedByServer13732('PostgreSQL', '3.0.' + patch)
23+
).toEqual(false);
24+
}
25+
for (let patch = 0; patch <= 22; patch++) {
26+
expect(
27+
isVersionAffectedByServer13732('MongoDB', '3.2.' + patch)
28+
).toEqual(true);
29+
expect(
30+
isVersionAffectedByServer13732('PostgreSQL', '3.2.' + patch)
31+
).toEqual(false);
32+
}
33+
for (let patch = 0; patch <= 21; patch++) {
34+
expect(
35+
isVersionAffectedByServer13732('MongoDB', '3.4.' + patch)
36+
).toEqual(true);
37+
expect(
38+
isVersionAffectedByServer13732('PostgreSQL', '3.4.' + patch)
39+
).toEqual(false);
40+
}
41+
for (let patch = 0; patch <= 13; patch++) {
42+
expect(
43+
isVersionAffectedByServer13732('MongoDB', '3.6.' + patch)
44+
).toEqual(false);
45+
expect(
46+
isVersionAffectedByServer13732('PostgreSQL', '3.6.' + patch)
47+
).toEqual(false);
48+
}
49+
for (let patch = 0; patch <= 10; patch++) {
50+
expect(
51+
isVersionAffectedByServer13732('MongoDB', '4.0.' + patch)
52+
).toEqual(false);
53+
expect(
54+
isVersionAffectedByServer13732('PostgreSQL', '4.0.' + patch)
55+
).toEqual(false);
56+
}
57+
});
58+
});
59+
560
describe('validateQuery', function() {
661
describe('with skipMongoDBServer13732Workaround disabled (the default)', function() {
762
it('should restructure simple cases of SERVER-13732', done => {

src/Config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export class Config {
3434
);
3535
config.database = new DatabaseController(
3636
cacheInfo.databaseController.adapter,
37-
schemaCache,
38-
cacheInfo.skipMongoDBServer13732Workaround
37+
schemaCache
3938
);
4039
} else {
4140
config[key] = cacheInfo[key];

src/Controllers/DatabaseController.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,24 +406,26 @@ const relationSchema = {
406406
fields: { relatedId: { type: 'String' }, owningId: { type: 'String' } },
407407
};
408408

409+
const isVersionAffectedByServer13732 = (engine, version) =>
410+
engine == 'MongoDB' && /^(2\.6|3\.0|3\.2|3\.4)/.test(version);
411+
409412
class DatabaseController {
410413
adapter: StorageAdapter;
411414
schemaCache: any;
412415
schemaPromise: ?Promise<SchemaController.SchemaController>;
413416
skipMongoDBServer13732Workaround: boolean;
414417

415-
constructor(
416-
adapter: StorageAdapter,
417-
schemaCache: any,
418-
skipMongoDBServer13732Workaround: boolean
419-
) {
418+
constructor(adapter: StorageAdapter, schemaCache: any) {
420419
this.adapter = adapter;
421420
this.schemaCache = schemaCache;
422421
// We don't want a mutable this.schema, because then you could have
423422
// one request that uses different schemas for different parts of
424423
// it. Instead, use loadSchema to get a schema.
425424
this.schemaPromise = null;
426-
this.skipMongoDBServer13732Workaround = skipMongoDBServer13732Workaround;
425+
this.skipMongoDBServer13732Workaround = !isVersionAffectedByServer13732(
426+
adapter.engine,
427+
adapter.databaseVersion
428+
);
427429
}
428430

429431
collectionExists(className: string): Promise<boolean> {
@@ -1605,9 +1607,11 @@ class DatabaseController {
16051607
]);
16061608
}
16071609

1610+
static _isVersionAffectedByServer13732: (string, string) => boolean;
16081611
static _validateQuery: (any, boolean) => void;
16091612
}
16101613

16111614
module.exports = DatabaseController;
1612-
// Expose validateQuery for tests
1615+
// Expose validateQuery & isVersionAffectedByServer13732 for tests
1616+
module.exports._isVersionAffectedByServer13732 = isVersionAffectedByServer13732;
16131617
module.exports._validateQuery = validateQuery;

src/Controllers/SchemaController.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ function validateCLP(perms: ClassLevelPermissions, fields: SchemaFields) {
228228
// @flow-disable-next
229229
throw new Parse.Error(
230230
Parse.Error.INVALID_JSON,
231-
`'${perms[operation]}' is not a valid value for class level permissions ${operation}`
231+
`'${
232+
perms[operation]
233+
}' is not a valid value for class level permissions ${operation}`
232234
);
233235
} else {
234236
perms[operation].forEach(key => {

src/Controllers/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ export function getDatabaseController(
147147
const {
148148
databaseURI,
149149
databaseOptions,
150-
skipMongoDBServer13732Workaround,
151150
collectionPrefix,
152151
schemaCacheTTL,
153152
enableSingleSchemaCache,
@@ -171,8 +170,7 @@ export function getDatabaseController(
171170
}
172171
return new DatabaseController(
173172
databaseAdapter,
174-
new SchemaCache(cacheController, schemaCacheTTL, enableSingleSchemaCache),
175-
skipMongoDBServer13732Workaround
173+
new SchemaCache(cacheController, schemaCacheTTL, enableSingleSchemaCache)
176174
);
177175
}
178176

src/Options/Definitions.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,6 @@ module.exports.ParseServerOptions = {
320320
help: 'Disables console output',
321321
action: parsers.booleanParser,
322322
},
323-
skipMongoDBServer13732Workaround: {
324-
env: 'PARSE_SKIP_MONGODB_SERVER_13732_WORKAROUND',
325-
help: 'Circumvent Parse workaround for historical MongoDB bug SERVER-13732',
326-
action: parsers.booleanParser,
327-
default: false,
328-
},
329323
startLiveQueryServer: {
330324
env: 'PARSE_SERVER_START_LIVE_QUERY_SERVER',
331325
help: 'Starts the liveQuery server',

src/Options/docs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
* @property {String} serverURL URL to your parse server with http:// or https://.
5858
* @property {Number} sessionLength Session duration, in seconds, defaults to 1 year
5959
* @property {Boolean} silent Disables console output
60-
* @property {Boolean} skipMongoDBServer13732Workaround Circumvent Parse workaround for historical MongoDB bug SERVER-13732
6160
* @property {Boolean} startLiveQueryServer Starts the liveQuery server
6261
* @property {String[]} userSensitiveFields Personally identifiable information fields in the user table the should be removed for non-authorized users. Deprecated @see protectedFields
6362
* @property {Boolean} verbose Set the logging to verbose

src/Options/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ export interface ParseServerOptions {
5858
databaseOptions: ?any;
5959
/* Adapter module for the database */
6060
databaseAdapter: ?Adapter<StorageAdapter>;
61-
/* Circumvent Parse workaround for historical MongoDB bug SERVER-13732
62-
:ENV: PARSE_SKIP_MONGODB_SERVER_13732_WORKAROUND
63-
:DEFAULT: false */
64-
skipMongoDBServer13732Workaround: ?boolean;
6561
/* Full path to your cloud code main.js */
6662
cloud: ?string;
6763
/* A collection prefix for the classes

src/RestWrite.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,9 @@ RestWrite.prototype._validatePasswordHistory = function() {
781781
return Promise.reject(
782782
new Parse.Error(
783783
Parse.Error.VALIDATION_ERROR,
784-
`New password should not be the same as last ${this.config.passwordPolicy.maxPasswordHistory} passwords.`
784+
`New password should not be the same as last ${
785+
this.config.passwordPolicy.maxPasswordHistory
786+
} passwords.`
785787
)
786788
);
787789
throw err;

0 commit comments

Comments
 (0)