Skip to content

Commit 966f6bc

Browse files
committed
Merge branch 'allow-to-set-file-to-null' into package
2 parents 5b3e799 + 86cd24f commit 966f6bc

File tree

10 files changed

+187
-63
lines changed

10 files changed

+187
-63
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ jobs:
5050
env: POSTGRES_MAJOR_VERSION=11 PARSE_SERVER_TEST_DB=postgres PARSE_SERVER_TEST_DATABASE_URI=postgres://localhost:5433/parse_server_postgres_adapter_test_database
5151
before_install: bash scripts/before_install_postgres.sh
5252
before_script: bash scripts/before_script_postgres.sh
53+
script:
54+
- npm run lint
55+
- npm run coverage
5356
- stage: release
5457
node_js: '10'
5558
env:

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"uuid": "3.4.0",
5656
"winston": "3.2.1",
5757
"winston-daily-rotate-file": "4.4.2",
58-
"ws": "7.2.3"
58+
"ws": "7.2.5"
5959
},
6060
"devDependencies": {
6161
"@babel/cli": "7.8.4",

scripts/before_install_postgres.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#!/bin/bash
2-
2+
33
set -e
4+
source ~/.nvm/nvm.sh
45

56
echo "[SCRIPT] Before Install Script :: Setup Postgres ${POSTGRES_MAJOR_VERSION}"
67

8+
nvm install $NODE_VERSION
9+
nvm use $NODE_VERSION
10+
npm install -g greenkeeper-lockfile@1
11+
712
if [[ $POSTGRES_MAJOR_VERSION -lt 11 ]]; then
813
# Setup postgres 9 or 10
914
sudo sed -i 's/port = 5432/port = 5433/' /etc/postgresql/${POSTGRES_MAJOR_VERSION}/main/postgresql.conf
@@ -20,7 +25,7 @@ if [[ $POSTGRES_MAJOR_VERSION -lt 11 ]]; then
2025

2126
sudo service postgresql start
2227

23-
else
28+
else
2429
# Setup postgres 11 or higher
2530

2631
#Copy defauilt hba config file and tell postgres to restart

scripts/before_script_postgres.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#!/bin/bash
2-
2+
33
set -e
44

55
echo "[SCRIPT] Before Script :: Setup Parse DB for Postgres ${POSTGRES_MAJOR_VERSION}"
66

7+
node -e 'require("./lib/index.js")'
8+
greenkeeper-lockfile-update
9+
710
psql -v ON_ERROR_STOP=1 -p 5433 --username "postgres" --dbname "${POSTGRES_DB}" <<-EOSQL
811
CREATE DATABASE parse_server_postgres_adapter_test_database;
912
\c parse_server_postgres_adapter_test_database;
1013
CREATE EXTENSION postgis;
1114
CREATE EXTENSION postgis_topology;
1215
EOSQL
13-

spec/ParseGraphQLServer.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9522,6 +9522,29 @@ describe('ParseGraphQLServer', () => {
95229522

95239523
expect(res.status).toEqual(200);
95249524
expect(await res.text()).toEqual('My File Content');
9525+
9526+
const mutationResult = await apolloClient.mutate({
9527+
mutation: gql`
9528+
mutation UnlinkFile($id: ID!) {
9529+
updateSomeClass(
9530+
input: { id: $id, fields: { someField: { file: null } } }
9531+
) {
9532+
someClass {
9533+
someField {
9534+
name
9535+
url
9536+
}
9537+
}
9538+
}
9539+
}
9540+
`,
9541+
variables: {
9542+
id: result2.data.createSomeClass3.someClass.id,
9543+
},
9544+
});
9545+
expect(
9546+
mutationResult.data.updateSomeClass.someClass.someField
9547+
).toEqual(null);
95259548
} catch (e) {
95269549
handleError(e);
95279550
}

spec/PostgresConfigParser.spec.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const parser = require('../lib/Adapters/Storage/Postgres/PostgresConfigParser');
2+
const fs = require('fs');
23

34
const queryParamTests = {
45
'a=1&b=2': { a: '1', b: '2' },
@@ -23,7 +24,7 @@ describe('PostgresConfigParser.parseQueryParams', () => {
2324
});
2425

2526
const baseURI = 'postgres://username:password@localhost:5432/db-name';
26-
27+
const testfile = fs.readFileSync('./Dockerfile').toString();
2728
const dbOptionsTest = {};
2829
dbOptionsTest[
2930
`${baseURI}?ssl=true&binary=true&application_name=app_name&fallback_application_name=f_app_name&poolSize=10`
@@ -35,9 +36,38 @@ dbOptionsTest[
3536
poolSize: 10,
3637
};
3738
dbOptionsTest[`${baseURI}?ssl=&binary=aa`] = {
38-
ssl: false,
3939
binary: false,
4040
};
41+
dbOptionsTest[
42+
`${baseURI}?ssl=true&ca=./Dockerfile&pfx=./Dockerfile&cert=./Dockerfile&key=./Dockerfile&binary=aa&passphrase=word&secureOptions=20`
43+
] = {
44+
ssl: {
45+
ca: testfile,
46+
pfx: testfile,
47+
cert: testfile,
48+
key: testfile,
49+
passphrase: 'word',
50+
secureOptions: 20,
51+
},
52+
binary: false,
53+
};
54+
dbOptionsTest[
55+
`${baseURI}?ssl=false&ca=./Dockerfile&pfx=./Dockerfile&cert=./Dockerfile&key=./Dockerfile&binary=aa`
56+
] = {
57+
ssl: { ca: testfile, pfx: testfile, cert: testfile, key: testfile },
58+
binary: false,
59+
};
60+
dbOptionsTest[`${baseURI}?rejectUnauthorized=true`] = {
61+
ssl: { rejectUnauthorized: true },
62+
};
63+
dbOptionsTest[
64+
`${baseURI}?max=5&query_timeout=100&idleTimeoutMillis=1000&keepAlive=true`
65+
] = {
66+
max: 5,
67+
query_timeout: 100,
68+
idleTimeoutMillis: 1000,
69+
keepAlive: true,
70+
};
4171

4272
describe('PostgresConfigParser.getDatabaseOptionsFromURI', () => {
4373
it('creates a db options map from a query string', () => {

src/Adapters/Storage/Postgres/PostgresConfigParser.js

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const url = require('url');
2-
2+
const fs = require('fs');
33
function getDatabaseOptionsFromURI(uri) {
44
const databaseOptions = {};
55

@@ -16,8 +16,44 @@ function getDatabaseOptionsFromURI(uri) {
1616
databaseOptions.user = authParts.length > 0 ? authParts[0] : '';
1717
databaseOptions.password = authParts.length > 1 ? authParts[1] : '';
1818

19-
databaseOptions.ssl =
20-
queryParams.ssl && queryParams.ssl.toLowerCase() === 'true' ? true : false;
19+
if (queryParams.ssl && queryParams.ssl.toLowerCase() === 'true') {
20+
databaseOptions.ssl = true;
21+
}
22+
23+
if (
24+
queryParams.ca ||
25+
queryParams.pfx ||
26+
queryParams.cert ||
27+
queryParams.key ||
28+
queryParams.passphrase ||
29+
queryParams.rejectUnauthorized ||
30+
queryParams.secureOptions
31+
) {
32+
databaseOptions.ssl = {};
33+
if (queryParams.ca) {
34+
databaseOptions.ssl.ca = fs.readFileSync(queryParams.ca).toString();
35+
}
36+
if (queryParams.pfx) {
37+
databaseOptions.ssl.pfx = fs.readFileSync(queryParams.pfx).toString();
38+
}
39+
if (queryParams.cert) {
40+
databaseOptions.ssl.cert = fs.readFileSync(queryParams.cert).toString();
41+
}
42+
if (queryParams.key) {
43+
databaseOptions.ssl.key = fs.readFileSync(queryParams.key).toString();
44+
}
45+
if (queryParams.passphrase) {
46+
databaseOptions.ssl.passphrase = queryParams.passphrase;
47+
}
48+
if (queryParams.rejectUnauthorized) {
49+
databaseOptions.ssl.rejectUnauthorized =
50+
queryParams.rejectUnauthorized.toLowerCase() === 'true' ? true : false;
51+
}
52+
if (queryParams.secureOptions) {
53+
databaseOptions.ssl.secureOptions = parseInt(queryParams.secureOptions);
54+
}
55+
}
56+
2157
databaseOptions.binary =
2258
queryParams.binary && queryParams.binary.toLowerCase() === 'true'
2359
? true
@@ -31,6 +67,19 @@ function getDatabaseOptionsFromURI(uri) {
3167
if (queryParams.poolSize) {
3268
databaseOptions.poolSize = parseInt(queryParams.poolSize) || 10;
3369
}
70+
if (queryParams.max) {
71+
databaseOptions.max = parseInt(queryParams.max) || 10;
72+
}
73+
if (queryParams.query_timeout) {
74+
databaseOptions.query_timeout = parseInt(queryParams.query_timeout);
75+
}
76+
if (queryParams.idleTimeoutMillis) {
77+
databaseOptions.idleTimeoutMillis = parseInt(queryParams.idleTimeoutMillis);
78+
}
79+
if (queryParams.keepAlive) {
80+
databaseOptions.keepAlive =
81+
queryParams.keepAlive.toLowerCase() === 'true' ? true : false;
82+
}
3483

3584
return databaseOptions;
3685
}

0 commit comments

Comments
 (0)