key
});
});
+
+ it('should correctly identify URL', () => {
+ (getSettingsAppDefinition as jest.Mock).mockReturnValue({
+ key: 'sonar.core.serverBaseURL'
+ });
+
+ (getSettingsAppChangedValue as jest.Mock).mockReturnValue('http://test');
+ const key = 'sonar.core.serverBaseURL';
+ expect(checkValue(key)(dispatch, jest.fn())).toBe(true);
+ expect(dispatch).toBeCalledWith({
+ type: 'settingsPage/PASS_VALIDATION',
+ key
+ });
+
+ (getSettingsAppChangedValue as jest.Mock).mockReturnValue('not valid');
+ expect(checkValue(key)(dispatch, jest.fn())).toBe(false);
+ expect(dispatch).toBeCalledWith({
+ type: 'settingsPage/PASS_VALIDATION',
+ key
+ });
+ });
});
resetSettingValue,
setSettingValue
} from '../../../api/settings';
-import { translate } from '../../../helpers/l10n';
+import { translate, translateWithParameters } from '../../../helpers/l10n';
import { parseError } from '../../../helpers/request';
import { closeAllGlobalMessages } from '../../../store/globalMessages';
import {
getSettingsAppDefinition,
Store
} from '../../../store/rootReducer';
+import { SettingDefinition } from '../../../types/settings';
import { isEmptyValue } from '../utils';
import { receiveDefinitions } from './definitions';
import {
} from './settingsPage';
import { receiveValues } from './values';
+function isURLKind(definition: SettingDefinition) {
+ return [
+ 'sonar.core.serverBaseURL',
+ 'sonar.auth.github.apiUrl',
+ 'sonar.auth.github.webUrl',
+ 'sonar.auth.gitlab.url',
+ 'sonar.lf.gravatarServerUrl',
+ 'sonar.lf.logoUrl',
+ 'sonar.auth.saml.loginUrl'
+ ].includes(definition.key);
+}
+
export function fetchSettings(component?: string) {
return (dispatch: Dispatch) => {
return getDefinitions(component).then(definitions => {
return false;
}
+ if (isURLKind(definition)) {
+ try {
+ // eslint-disable-next-line no-new
+ new URL(value);
+ } catch (e) {
+ dispatch(
+ failValidation(key, translateWithParameters('settings.state.url_not_valid', value))
+ );
+ return false;
+ }
+ }
+
if (definition.type === 'JSON') {
try {
JSON.parse(value);
} catch (e) {
dispatch(failValidation(key, e.message));
+
return false;
}
}
settings.state.validation_failed=Validation failed. {0}
settings.state.value_cant_be_empty=Provide a value or use "Reset" to set the value to the default one.
settings.state.value_cant_be_empty_no_default=Provide a value.
+settings.state.url_not_valid={0} is not a valid URL
settings._default=(default)
settings.boolean.true=True
settings.boolean.false=False