Skip to content

feat: Update config to automatically check types #8535

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

Draft
wants to merge 6 commits into
base: alpha
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions resources/buildConfigDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ function inject(t, list) {
type = 'String|String[]';
}
comments += ` * @property {${type}} ${elt.name} ${elt.help}\n`;
if (nestedOptionTypes.includes(type) && type !== 'Object') {
props.push(t.objectProperty(t.stringLiteral('group'), t.stringLiteral(`${type}`)));
}
const obj = t.objectExpression(props);
return t.objectProperty(t.stringLiteral(elt.name), obj);
})
Expand Down
2 changes: 1 addition & 1 deletion spec/SecurityCheck.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('Security Check', () => {

describe('server options', () => {
it('uses default configuration when none is set', async () => {
await reconfigureServerWithSecurityConfig({});
await reconfigureServer();
expect(Config.get(Parse.applicationId).security.enableCheck).toBe(
Definitions.SecurityOptions.enableCheck.default
);
Expand Down
36 changes: 36 additions & 0 deletions spec/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,42 @@ describe('server', () => {
});
});

it('default interface keys are set', async () => {
delete process.env.PARSE_SERVER_PASSWORD_POLICY_RESET_TOKEN_REUSE_IF_VALID;
delete process.env.PARSE_SERVER_PASSWORD_POLICY_RESET_TOKEN_VALIDITY_DURATION;
await reconfigureServer();
const config = Config.get('test');
expect(config.passwordPolicy.resetTokenReuseIfValid).toBeDefined();
expect(config.passwordPolicy.resetTokenReuseIfValid).toBeFalse();
});

it('can set subkeys via environment variables', async () => {
process.env.PARSE_SERVER_PASSWORD_POLICY_RESET_TOKEN_REUSE_IF_VALID = true;
process.env.PARSE_SERVER_PASSWORD_POLICY_RESET_TOKEN_VALIDITY_DURATION = 3000;
await reconfigureServer();
const config = Config.get('test');
expect(config.passwordPolicy.resetTokenReuseIfValid).toBeDefined();
expect(config.passwordPolicy.resetTokenReuseIfValid).toBeTrue();
});

it('can set throw on invalid type', async () => {
await expectAsync(
reconfigureServer({
revokeSessionOnPasswordReset: [],
})
).toBeRejectedWith('revokeSessionOnPasswordReset must be a boolean value.');
});

it('can set throw on invalid subkeys', async () => {
await expectAsync(
reconfigureServer({
fileUpload: {
enableForAnonymousUser: [],
},
})
).toBeRejectedWith('fileUpload.enableForAnonymousUser must be a boolean value.');
});

it('fails if you try to set revokeSessionOnPasswordReset to non-boolean', done => {
reconfigureServer({ revokeSessionOnPasswordReset: 'non-bool' }).catch(done);
});
Expand Down
Loading