Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Ensure Database Password Security Check Covers All Possible URIs #9078

Open
wants to merge 6 commits into
base: alpha
Choose a base branch
from
20 changes: 18 additions & 2 deletions spec/SecurityCheckGroups.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,36 @@ describe('Security Check Groups', () => {
expect(group.checks().length).toBeGreaterThan(0);
});

it('checks succeed correctly', async () => {
it('checks succeed correctly with database adapter defined', async () => {
const config = Config.get(Parse.applicationId);
config.database.adapter._uri = 'protocol://user:[email protected]';
const group = new CheckGroupDatabase();
await group.run();
expect(group.checks()[0].checkState()).toBe(CheckState.success);
});

it('checks fail correctly', async () => {
it('checks succeed correctly with databaseURI defined', async () => {
const config = Config.get(Parse.applicationId);
config.databaseURI = 'protocol://user:[email protected]';
const group = new CheckGroupDatabase();
await group.run();
expect(group.checks()[0].checkState()).toBe(CheckState.success);
});

it('checks fail correctly with database adapter defined', async () => {
const config = Config.get(Parse.applicationId);
config.database.adapter._uri = 'protocol://user:[email protected]';
const group = new CheckGroupDatabase();
await group.run();
expect(group.checks()[0].checkState()).toBe(CheckState.fail);
});

it('checks fail correctly with databaseURI defined', async () => {
const config = Config.get(Parse.applicationId);
config.databaseURI = 'protocol://user:[email protected]';
const group = new CheckGroupDatabase();
await group.run();
expect(group.checks()[0].checkState()).toBe(CheckState.fail);
});
});
});
12 changes: 11 additions & 1 deletion src/Security/CheckGroups/CheckGroupDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@
}
setChecks() {
const config = Config.get(Parse.applicationId);
let databaseUrl;
const databaseAdapter = config.database.adapter;
const databaseUrl = databaseAdapter._uri;
if (databaseAdapter) {
// If database adapter is defined, use its URI
databaseUrl = databaseAdapter._uri;
} else if (config.databaseURI) {

Check warning on line 22 in src/Security/CheckGroups/CheckGroupDatabase.js

View check run for this annotation

Codecov / codecov/patch

src/Security/CheckGroups/CheckGroupDatabase.js#L22

Added line #L22 was not covered by tests
// If database adapter is not defined, fallback to config.databaseURI
databaseUrl = config.databaseURI;

Check warning on line 24 in src/Security/CheckGroups/CheckGroupDatabase.js

View check run for this annotation

Codecov / codecov/patch

src/Security/CheckGroups/CheckGroupDatabase.js#L24

Added line #L24 was not covered by tests
} else {
// Handle the case where neither database adapter nor databaseURI is defined
throw 1;

Check warning on line 27 in src/Security/CheckGroups/CheckGroupDatabase.js

View check run for this annotation

Codecov / codecov/patch

src/Security/CheckGroups/CheckGroupDatabase.js#L27

Added line #L27 was not covered by tests
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
}
return [
new Check({
title: 'Secure database password',
Expand Down