interface State {
settings: SettingDefinitionAndValue[];
- displayGithubOrganizationWarning: boolean;
+ displaySecurityWarning: boolean;
}
export default class CategoryDefinitionsList extends React.PureComponent<Props, State> {
mounted = false;
- state: State = { settings: [], displayGithubOrganizationWarning: false };
+ state: State = { settings: [], displaySecurityWarning: false };
componentDidMount() {
this.mounted = true;
this.mounted = false;
}
- shouldDisplayGithubWarning = (settings: SettingDefinitionAndValue[]) => {
+ shouldDisplaySecurityWarning = (settings: SettingDefinitionAndValue[]) => {
const { category, subCategory } = this.props;
- if (category !== 'authentication' || subCategory !== 'github') {
+ if (category !== 'authentication' || subCategory === 'saml') {
return false;
}
- const isGithubEnabled = settings.find((s) => s.definition.key === 'sonar.auth.github.enabled');
- const organizationsSetting = settings.find(
- (s) => s.definition.key === 'sonar.auth.github.organizations'
+ const isEnabled = settings.find(
+ (s) => s.definition.key === `sonar.auth.${subCategory}.enabled`
);
+ const isAllowUsersToSignUpEnabled = settings.find(
+ (s) => s.definition.key === `sonar.auth.${subCategory}.allowUsersToSignUp`
+ );
+ let organizationsSetting;
+ if (subCategory === 'github') {
+ organizationsSetting = settings.find(
+ (s) => s.definition.key === `sonar.auth.${subCategory}.organizations`
+ );
+ }
+ if (subCategory === 'bitbucket') {
+ organizationsSetting = settings.find(
+ (s) => s.definition.key === `sonar.auth.${subCategory}.workspaces`
+ );
+ }
+ if (subCategory === 'gitlab') {
+ organizationsSetting = settings.find(
+ (s) => s.definition.key === `sonar.auth.${subCategory}.allowedGroups`
+ );
+ }
+
if (
- isGithubEnabled?.settingValue?.value === 'true' &&
+ isEnabled?.settingValue?.value === 'true' &&
+ isAllowUsersToSignUpEnabled?.settingValue?.value === 'true' &&
organizationsSetting?.settingValue === undefined
) {
return true;
};
});
- const displayGithubOrganizationWarning = this.shouldDisplayGithubWarning(settings);
+ const displaySecurityWarning = this.shouldDisplaySecurityWarning(settings);
- this.setState({ settings, displayGithubOrganizationWarning });
+ this.setState({ settings, displaySecurityWarning });
};
render() {
const { category, component, subCategory, displaySubCategoryTitle } = this.props;
- const { settings, displayGithubOrganizationWarning } = this.state;
+ const { settings, displaySecurityWarning } = this.state;
return (
<>
- {displayGithubOrganizationWarning && (
+ {displaySecurityWarning && (
<Alert variant="error">
<FormattedMessage
- id="settings.authentication.github.organization.warning"
- defaultMessage={translate('settings.authentication.github.organization.warning')}
+ id={`settings.authentication.${subCategory}.organization.warning`}
+ defaultMessage={translate(
+ `settings.authentication.${subCategory}.organization.warning`
+ )}
values={{
learn_more: (
- <DocLink to="/instance-administration/authentication/github/#setting-your-authentication-settings-in-sonarqube">
- {translate('settings.authentication.github.organization.warning.learn_more')}
+ <DocLink
+ to={`/instance-administration/authentication/${
+ subCategory === 'bitbucket' ? 'bitbucket-cloud' : subCategory
+ }/#setting-your-authentication-settings-in-sonarqube`}
+ >
+ {translate('learn_more')}
</DocLink>
),
}}
textbox1: byRole('textbox', { name: 'test1' }),
textbox2: byRole('textbox', { name: 'test2' }),
githubTab: byRole('tab', { name: 'github GitHub' }),
+ gitlabTab: byRole('tab', { name: 'gitlab GitLab' }),
+ bitbucketTab: byRole('tab', { name: 'bitbucket Bitbucket' }),
githubOrganizationWarning: byText('settings.authentication.github.organization.warning'),
+ gitlabOrganizationWarning: byText('settings.authentication.gitlab.organization.warning'),
+ bitbucketOrganizationWarning: byText('settings.authentication.bitbucket.organization.warning'),
};
it('should render tabs and allow navigation', async () => {
key: 'sonar.auth.github.enabled',
category: 'authentication',
subCategory: 'github',
- name: '"Enabled"',
+ name: 'Enabled',
description:
'Enable GitHub users to login. Value is ignored if client ID and secret are not defined.',
type: SettingType.BOOLEAN,
}),
+ mockDefinition({
+ key: 'sonar.auth.github.allowUsersToSignUp',
+ category: 'authentication',
+ subCategory: 'github',
+ name: 'Allow users to sign-up',
+ description:
+ 'Allow new users to authenticate. When set to false, only existing users will be able to authenticate to the server.',
+ type: SettingType.BOOLEAN,
+ }),
mockDefinition({
key: 'sonar.auth.github.organizations',
category: 'authentication',
});
});
+describe('GitLab tab', () => {
+ it('should display a warning if gitlab authentication is enabled but no organizations are whitelisted', async () => {
+ const user = userEvent.setup();
+
+ const definitions = [
+ mockDefinition({
+ key: 'sonar.auth.gitlab.enabled',
+ category: 'authentication',
+ subCategory: 'gitlab',
+ name: '"Enabled"',
+ description:
+ 'Enable gitlab users to login. Value is ignored if client ID and secret are not defined.',
+ type: SettingType.BOOLEAN,
+ }),
+ mockDefinition({
+ key: 'sonar.auth.gitlab.allowUsersToSignUp',
+ category: 'authentication',
+ subCategory: 'gitlab',
+ name: 'Allow users to sign-up',
+ description:
+ 'Allow new users to authenticate. When set to false, only existing users will be able to authenticate to the server.',
+ type: SettingType.BOOLEAN,
+ }),
+ mockDefinition({
+ key: 'sonar.auth.gitlab.allowedGroups',
+ category: 'authentication',
+ subCategory: 'gitlab',
+ name: 'Allowed Groups',
+ description:
+ 'Only members of these groups will be able to authenticate to the server. If a user is a member of any of the group listed they will be authenticated.',
+ type: SettingType.BOOLEAN,
+ fields: [],
+ multiValues: true,
+ options: [],
+ }),
+ ];
+
+ renderAuthentication(definitions);
+
+ await user.click(await ui.gitlabTab.find());
+ expect(ui.gitlabOrganizationWarning.get()).toBeInTheDocument();
+ });
+});
+
+describe('bitbucket tab', () => {
+ it('should display a warning if bitbucket authentication is enabled but no organizations are whitelisted', async () => {
+ const user = userEvent.setup();
+
+ const definitions = [
+ mockDefinition({
+ key: 'sonar.auth.bitbucket.enabled',
+ category: 'authentication',
+ subCategory: 'bitbucket',
+ name: '"Enabled"',
+ description:
+ 'Enable bitbucket users to login. Value is ignored if client ID and secret are not defined.',
+ type: SettingType.BOOLEAN,
+ }),
+ mockDefinition({
+ key: 'sonar.auth.bitbucket.allowUsersToSignUp',
+ category: 'authentication',
+ subCategory: 'bitbucket',
+ name: 'Allow users to sign-up',
+ description:
+ 'Allow new users to authenticate. When set to false, only existing users will be able to authenticate to the server.',
+ type: SettingType.BOOLEAN,
+ }),
+ mockDefinition({
+ key: 'sonar.auth.bitbucket.organizations',
+ category: 'authentication',
+ subCategory: 'bitbucket',
+ name: 'Organizations',
+ description:
+ 'Only members of these organizations will be able to authenticate to the server. If a user is a member of any of the organizations listed they will be authenticated.',
+ type: SettingType.BOOLEAN,
+ fields: [],
+ multiValues: true,
+ options: [],
+ }),
+ ];
+
+ renderAuthentication(definitions);
+
+ await user.click(await ui.bitbucketTab.find());
+ expect(ui.bitbucketOrganizationWarning.get()).toBeInTheDocument();
+ });
+});
+
function renderAuthentication(definitions: ExtendedSettingDefinition[], features: Feature[] = []) {
renderComponent(
<AvailableFeaturesContext.Provider value={features}>