fix: change default open authoring scope, make it configurable (#2821)
This commit is contained in:
parent
da2dab305a
commit
002cdd77a8
@ -75,12 +75,17 @@ export default class GitHubAuthenticationPage extends React.Component {
|
|||||||
};
|
};
|
||||||
const auth = new NetlifyAuthenticator(cfg);
|
const auth = new NetlifyAuthenticator(cfg);
|
||||||
|
|
||||||
auth.authenticate({ provider: 'github', scope: 'repo' }, (err, data) => {
|
const openAuthoring = this.props.config.getIn(['backend', 'open_authoring'], false);
|
||||||
|
const scope = this.props.config.getIn(
|
||||||
|
['backend', 'auth_scope'],
|
||||||
|
openAuthoring ? 'public_repo' : 'repo',
|
||||||
|
);
|
||||||
|
auth.authenticate({ provider: 'github', scope }, (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.setState({ loginError: err.toString() });
|
this.setState({ loginError: err.toString() });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.props.config.getIn(['backend', 'open_authoring'])) {
|
if (openAuthoring) {
|
||||||
return this.loginWithOpenAuthoring(data).then(() => this.props.onLogin(data));
|
return this.loginWithOpenAuthoring(data).then(() => this.props.onLogin(data));
|
||||||
}
|
}
|
||||||
this.props.onLogin(data);
|
this.props.onLogin(data);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { merge } from 'lodash';
|
||||||
import { validateConfig } from '../configSchema';
|
import { validateConfig } from '../configSchema';
|
||||||
|
|
||||||
describe('config', () => {
|
describe('config', () => {
|
||||||
@ -6,12 +7,11 @@ describe('config', () => {
|
|||||||
* log test failures and associated errors as expected.
|
* log test failures and associated errors as expected.
|
||||||
*/
|
*/
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.spyOn(console, 'error');
|
jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('validateConfig', () => {
|
describe('validateConfig', () => {
|
||||||
it('should not throw if no errors', () => {
|
const validConfig = {
|
||||||
const config = {
|
|
||||||
foo: 'bar',
|
foo: 'bar',
|
||||||
backend: { name: 'bar' },
|
backend: { name: 'bar' },
|
||||||
media_folder: 'baz',
|
media_folder: 'baz',
|
||||||
@ -24,8 +24,10 @@ describe('config', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
it('should not throw if no errors', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
validateConfig(config);
|
validateConfig(validConfig);
|
||||||
}).not.toThrowError();
|
}).not.toThrowError();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -47,6 +49,33 @@ describe('config', () => {
|
|||||||
}).toThrowError("'backend.name' should be string");
|
}).toThrowError("'backend.name' should be string");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw if backend.open_authoring is not a boolean in config', () => {
|
||||||
|
expect(() => {
|
||||||
|
validateConfig(merge(validConfig, { backend: { open_authoring: 'true' } }));
|
||||||
|
}).toThrowError("'backend.open_authoring' should be boolean");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not throw if backend.open_authoring is boolean in config', () => {
|
||||||
|
expect(() => {
|
||||||
|
validateConfig(merge(validConfig, { backend: { open_authoring: true } }));
|
||||||
|
}).not.toThrowError();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw if backend.auth_scope is not "repo" or "public_repo" in config', () => {
|
||||||
|
expect(() => {
|
||||||
|
validateConfig(merge(validConfig, { backend: { auth_scope: 'user' } }));
|
||||||
|
}).toThrowError("'backend.auth_scope' should be equal to one of the allowed values");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not throw if backend.auth_scope is one of "repo" or "public_repo" in config', () => {
|
||||||
|
expect(() => {
|
||||||
|
validateConfig(merge(validConfig, { backend: { auth_scope: 'repo' } }));
|
||||||
|
}).not.toThrowError();
|
||||||
|
expect(() => {
|
||||||
|
validateConfig(merge(validConfig, { backend: { auth_scope: 'public_repo' } }));
|
||||||
|
}).not.toThrowError();
|
||||||
|
});
|
||||||
|
|
||||||
it('should throw if media_folder is not defined in config', () => {
|
it('should throw if media_folder is not defined in config', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
validateConfig({ foo: 'bar', backend: { name: 'bar' } });
|
validateConfig({ foo: 'bar', backend: { name: 'bar' } });
|
||||||
|
@ -31,7 +31,15 @@ const getConfigSchema = () => ({
|
|||||||
properties: {
|
properties: {
|
||||||
backend: {
|
backend: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: { name: { type: 'string', examples: ['test-repo'] } },
|
properties: {
|
||||||
|
name: { type: 'string', examples: ['test-repo'] },
|
||||||
|
auth_scope: {
|
||||||
|
type: 'string',
|
||||||
|
examples: ['repo', 'public_repo'],
|
||||||
|
enum: ['repo', 'public_repo'],
|
||||||
|
},
|
||||||
|
open_authoring: { type: 'boolean', examples: [true] },
|
||||||
|
},
|
||||||
required: ['name'],
|
required: ['name'],
|
||||||
},
|
},
|
||||||
site_url: { type: 'string', examples: ['https://example.com'] },
|
site_url: { type: 'string', examples: ['https://example.com'] },
|
||||||
@ -169,7 +177,7 @@ class ConfigError extends Error {
|
|||||||
* the config that is passed in.
|
* the config that is passed in.
|
||||||
*/
|
*/
|
||||||
export function validateConfig(config) {
|
export function validateConfig(config) {
|
||||||
const ajv = new AJV({ allErrors: true });
|
const ajv = new AJV({ allErrors: true, jsonPointers: true });
|
||||||
ajvErrors(ajv);
|
ajvErrors(ajv);
|
||||||
|
|
||||||
const valid = ajv.validate(getConfigSchema(), config);
|
const valid = ajv.validate(getConfigSchema(), config);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user