}
}
-configurations {
- tests
-
- testCompile.extendsFrom tests
-}
-
dependencies {
// please keep the list grouped by configuration and ordered by name
compileOnly 'com.google.code.findbugs:jsr305'
compileOnly 'javax.servlet:javax.servlet-api'
- testCompile 'com.google.code.findbugs:jsr305'
testCompile 'com.tngtech.java:junit-dataprovider'
testCompile 'javax.servlet:javax.servlet-api'
testCompile 'org.apache.logging.log4j:log4j-api'
testCompile testFixtures(project(':server:sonar-server-common'))
testCompile project(':sonar-testing-harness')
+ testCompileOnly 'com.google.code.findbugs:jsr305'
+
runtime 'io.jsonwebtoken:jjwt-jackson'
-}
-task testJar(type: Jar) {
- classifier = 'tests'
- from sourceSets.test.output
-}
+ testFixturesApi 'junit:junit'
-artifacts {
- tests testJar
+ testFixturesCompileOnly 'com.google.code.findbugs:jsr305'
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.authentication;
-
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-import org.sonar.api.server.authentication.IdentityProvider;
-
-public class IdentityProviderRepositoryRule extends IdentityProviderRepository implements TestRule {
-
- public IdentityProviderRepositoryRule addIdentityProvider(IdentityProvider identityProvider) {
- providersByKey.put(identityProvider.getKey(), identityProvider);
- return this;
- }
-
- @Override
- public Statement apply(final Statement statement, Description description) {
- return new Statement() {
- @Override
- public void evaluate() throws Throwable {
- try {
- statement.evaluate();
- } finally {
- providersByKey.clear();
- }
- }
- };
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.authentication;
-
-import org.sonar.api.server.authentication.Display;
-import org.sonar.api.server.authentication.IdentityProvider;
-
-public class TestIdentityProvider implements IdentityProvider {
-
- private String key;
- private String name;
- private Display display;
- private boolean enabled;
- private boolean allowsUsersToSignUp;
-
- @Override
- public String getKey() {
- return key;
- }
-
- public TestIdentityProvider setKey(String key) {
- this.key = key;
- return this;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- public TestIdentityProvider setName(String name) {
- this.name = name;
- return this;
- }
-
- @Override
- public Display getDisplay() {
- return display;
- }
-
- public TestIdentityProvider setDisplay(Display display) {
- this.display = display;
- return this;
- }
-
- @Override
- public boolean isEnabled() {
- return enabled;
- }
-
- public TestIdentityProvider setEnabled(boolean enabled) {
- this.enabled = enabled;
- return this;
- }
-
- @Override
- public boolean allowsUsersToSignUp() {
- return allowsUsersToSignUp;
- }
-
- public TestIdentityProvider setAllowsUsersToSignUp(boolean allowsUsersToSignUp) {
- this.allowsUsersToSignUp = allowsUsersToSignUp;
- return this;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (getClass() != o.getClass()) {
- return false;
- }
-
- TestIdentityProvider that = (TestIdentityProvider) o;
- return key.equals(that.key);
- }
-
- @Override
- public int hashCode() {
- return key.hashCode();
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.language;
-
-import com.google.common.collect.Collections2;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.resources.AbstractLanguage;
-import org.sonar.api.resources.Language;
-import org.sonar.api.resources.Languages;
-import org.sonar.core.util.NonNullInputFunction;
-
-import java.util.Arrays;
-
-public class LanguageTesting {
-
- public static Language newLanguage(String key, String name, final String... prefixes) {
- return new AbstractLanguage(key, name) {
- @Override
- public String[] getFileSuffixes() {
- return prefixes;
- }
- };
- }
-
- public static Language newLanguage(String key) {
- return newLanguage(key, StringUtils.capitalize(key));
- }
-
- public static Languages newLanguages(String... languageKeys) {
- return new Languages(Collections2.transform(Arrays.asList(languageKeys), new NonNullInputFunction<String, Language>() {
- @Override
- protected Language doApply(String languageKey) {
- return newLanguage(languageKey);
- }
-
- }).toArray(new Language[0]));
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.qualityprofile;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import org.junit.rules.ExternalResource;
-import org.sonar.api.resources.Language;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
-import org.sonar.core.util.stream.MoreCollectors;
-import org.sonar.db.rule.RuleDefinitionDto;
-
-import static com.google.common.base.Preconditions.checkState;
-
-public class BuiltInQProfileRepositoryRule extends ExternalResource implements BuiltInQProfileRepository {
- private boolean initializeCalled = false;
- private List<BuiltInQProfile> profiles = new ArrayList<>();
-
- @Override
- protected void before() {
- this.initializeCalled = false;
- this.profiles.clear();
- }
-
- @Override
- public void initialize() {
- checkState(!initializeCalled, "initialize must be called only once");
- this.initializeCalled = true;
- }
-
- @Override
- public List<BuiltInQProfile> get() {
- checkState(initializeCalled, "initialize must be called first");
-
- return ImmutableList.copyOf(profiles);
- }
-
- public boolean isInitialized() {
- return initializeCalled;
- }
-
- public BuiltInQProfile add(Language language, String profileName) {
- return add(language, profileName, false);
- }
-
- public BuiltInQProfile add(Language language, String profileName, boolean isDefault) {
- return add(language, profileName, isDefault, new BuiltInQProfile.ActiveRule[0]);
- }
-
- public BuiltInQProfile add(Language language, String profileName, boolean isDefault, BuiltInQProfile.ActiveRule... rules) {
- BuiltInQProfile builtIn = create(language, profileName, isDefault, rules);
- profiles.add(builtIn);
- return builtIn;
- }
-
- public BuiltInQProfile create(Language language, String profileName, boolean isDefault, BuiltInQProfile.ActiveRule... rules) {
- BuiltInQProfile.Builder builder = new BuiltInQProfile.Builder()
- .setLanguage(language.getKey())
- .setName(profileName)
- .setDeclaredDefault(isDefault);
- Arrays.stream(rules).forEach(builder::addRule);
- return builder.build();
- }
-
- public BuiltInQProfile create(BuiltInQualityProfilesDefinition.BuiltInQualityProfile api, RuleDefinitionDto... rules) {
- BuiltInQProfile.Builder builder = new BuiltInQProfile.Builder()
- .setLanguage(api.language())
- .setName(api.name())
- .setDeclaredDefault(api.isDefault());
- Map<RuleKey, RuleDefinitionDto> rulesByRuleKey = Arrays.stream(rules)
- .collect(MoreCollectors.uniqueIndex(RuleDefinitionDto::getKey));
- api.rules().forEach(rule -> {
- RuleKey ruleKey = RuleKey.of(rule.repoKey(), rule.ruleKey());
- RuleDefinitionDto ruleDefinition = rulesByRuleKey.get(ruleKey);
- Preconditions.checkState(ruleDefinition != null, "Rule '%s' not found", ruleKey);
- builder.addRule(rule, ruleDefinition.getId());
- });
- return builder
- .build();
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.tester;
-
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.ImmutableSet;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import org.sonar.api.web.UserRole;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.server.user.AbstractUserSession;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.collect.Maps.newHashMap;
-
-public abstract class AbstractMockUserSession<T extends AbstractMockUserSession> extends AbstractUserSession {
- private static final Set<String> PUBLIC_PERMISSIONS = ImmutableSet.of(UserRole.USER, UserRole.CODEVIEWER); // FIXME to check with Simon
-
- private final Class<T> clazz;
- private HashMultimap<String, String> projectUuidByPermission = HashMultimap.create();
- private final HashMultimap<String, OrganizationPermission> permissionsByOrganizationUuid = HashMultimap.create();
- private Map<String, String> projectUuidByComponentUuid = newHashMap();
- private Set<String> projectPermissions = new HashSet<>();
- private Set<String> organizationMembership = new HashSet<>();
- private boolean systemAdministrator = false;
-
- protected AbstractMockUserSession(Class<T> clazz) {
- this.clazz = clazz;
- }
-
- public T addPermission(OrganizationPermission permission, String organizationUuid) {
- permissionsByOrganizationUuid.put(organizationUuid, permission);
- return clazz.cast(this);
- }
-
- @Override
- protected boolean hasPermissionImpl(OrganizationPermission permission, String organizationUuid) {
- return permissionsByOrganizationUuid.get(organizationUuid).contains(permission);
- }
-
- /**
- * Use this method to register public root component and non root components the UserSession must be aware of.
- * (ie. this method can be used to emulate the content of the DB)
- */
- public T registerComponents(ComponentDto... components) {
- Arrays.stream(components)
- .forEach(component -> {
- if (component.projectUuid().equals(component.uuid()) && !component.isPrivate()) {
- this.projectUuidByPermission.put(UserRole.USER, component.uuid());
- this.projectUuidByPermission.put(UserRole.CODEVIEWER, component.uuid());
- this.projectPermissions.add(UserRole.USER);
- this.projectPermissions.add(UserRole.CODEVIEWER);
- }
- this.projectUuidByComponentUuid.put(component.uuid(), component.projectUuid());
- });
- return clazz.cast(this);
- }
-
- public T addProjectPermission(String permission, ComponentDto... components) {
- Arrays.stream(components).forEach(component -> {
- checkArgument(
- component.isPrivate() || !PUBLIC_PERMISSIONS.contains(permission),
- "public component %s can't be granted public permission %s", component.uuid(), permission);
- });
- registerComponents(components);
- this.projectPermissions.add(permission);
- Arrays.stream(components)
- .forEach(component -> this.projectUuidByPermission.put(permission, component.projectUuid()));
- return clazz.cast(this);
- }
-
- @Override
- protected Optional<String> componentUuidToProjectUuid(String componentUuid) {
- return Optional.ofNullable(projectUuidByComponentUuid.get(componentUuid));
- }
-
- @Override
- protected boolean hasProjectUuidPermission(String permission, String projectUuid) {
- return projectPermissions.contains(permission) && projectUuidByPermission.get(permission).contains(projectUuid);
- }
-
- public T setSystemAdministrator(boolean b) {
- this.systemAdministrator = b;
- return clazz.cast(this);
- }
-
- @Override
- public boolean isSystemAdministrator() {
- return isRoot() || systemAdministrator;
- }
-
- @Override
- protected boolean hasMembershipImpl(OrganizationDto organizationDto) {
- return organizationMembership.contains(organizationDto.getUuid());
- }
-
- public void addOrganizationMembership(OrganizationDto organization) {
- this.organizationMembership.add(organization.getUuid());
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.tester;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Optional;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.user.GroupDto;
-
-public class AnonymousMockUserSession extends AbstractMockUserSession<AnonymousMockUserSession> {
-
- public AnonymousMockUserSession() {
- super(AnonymousMockUserSession.class);
- }
-
- @Override
- public boolean isRoot() {
- return false;
- }
-
- @Override
- public String getLogin() {
- return null;
- }
-
- @Override public String getUuid() {
- return null;
- }
-
- @Override
- public String getName() {
- return null;
- }
-
- @Override
- public Integer getUserId() {
- return null;
- }
-
- @Override
- public boolean isLoggedIn() {
- return false;
- }
-
- @Override
- public Collection<GroupDto> getGroups() {
- return Collections.emptyList();
- }
-
- @Override
- public Optional<IdentityProvider> getIdentityProvider() {
- return Optional.empty();
- }
-
- @Override
- public Optional<ExternalIdentity> getExternalIdentity() {
- return Optional.empty();
- }
-
- @Override
- public boolean hasMembershipImpl(OrganizationDto organizationDto) {
- return false;
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.tester;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Optional;
-import org.sonar.db.user.GroupDto;
-import org.sonar.db.user.UserDto;
-import org.sonar.server.user.AbstractUserSession;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Arrays.asList;
-import static java.util.Objects.requireNonNull;
-import static org.sonar.server.user.UserSession.IdentityProvider.SONARQUBE;
-
-public class MockUserSession extends AbstractMockUserSession<MockUserSession> {
- private final String login;
- private String uuid;
- private boolean root = false;
- private Integer userId;
- private String name;
- private List<GroupDto> groups = new ArrayList<>();
- private IdentityProvider identityProvider;
- private ExternalIdentity externalIdentity;
-
- public MockUserSession(String login) {
- super(MockUserSession.class);
- checkArgument(!login.isEmpty());
- this.login = login;
- setUuid(login + "uuid");
- setUserId(login.hashCode());
- setName(login + " name");
- setInternalIdentity();
- }
-
- public MockUserSession(UserDto userDto) {
- super(MockUserSession.class);
- checkArgument(!userDto.getLogin().isEmpty());
- this.login = userDto.getLogin();
- setUuid(userDto.getUuid());
- setUserId(userDto.getId());
- setName(userDto.getName());
- AbstractUserSession.Identity identity = computeIdentity(userDto);
- this.identityProvider = identity.getIdentityProvider();
- this.externalIdentity = identity.getExternalIdentity();
- }
-
- @Override
- public boolean isLoggedIn() {
- return true;
- }
-
- @Override
- public boolean isRoot() {
- return root;
- }
-
- public void setRoot(boolean root) {
- this.root = root;
- }
-
- @Override
- public String getLogin() {
- return this.login;
- }
-
- @Override
- public String getUuid() {
- return this.uuid;
- }
-
- public MockUserSession setUuid(String uuid) {
- this.uuid = requireNonNull(uuid);
- return this;
- }
-
- @Override
- public String getName() {
- return this.name;
- }
-
- public MockUserSession setName(String s) {
- this.name = requireNonNull(s);
- return this;
- }
-
- @Override
- public Integer getUserId() {
- return this.userId;
- }
-
- public MockUserSession setUserId(int userId) {
- this.userId = userId;
- return this;
- }
-
- @Override
- public Collection<GroupDto> getGroups() {
- return groups;
- }
-
- public MockUserSession setGroups(GroupDto... groups) {
- this.groups = asList(groups);
- return this;
- }
-
- @Override
- public Optional<IdentityProvider> getIdentityProvider() {
- return Optional.ofNullable(identityProvider);
- }
-
- public void setExternalIdentity(IdentityProvider identityProvider, ExternalIdentity externalIdentity) {
- checkArgument(identityProvider != SONARQUBE);
- this.identityProvider = identityProvider;
- this.externalIdentity = requireNonNull(externalIdentity);
- }
-
- public void setInternalIdentity() {
- this.identityProvider = SONARQUBE;
- this.externalIdentity = null;
- }
-
- @Override
- public Optional<ExternalIdentity> getExternalIdentity() {
- return Optional.ofNullable(externalIdentity);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.tester;
-
-import com.google.common.base.Preconditions;
-import java.util.Collection;
-import java.util.List;
-import java.util.Optional;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.db.user.GroupDto;
-import org.sonar.db.user.UserDto;
-import org.sonar.server.user.UserSession;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-
-/**
- * {@code UserSessionRule} is intended to be used as a {@link org.junit.Rule} to easily manage {@link UserSession} in
- * unit tests.
- * <p>
- * It can be used as a {@link org.junit.ClassRule} but be careful not to modify its states from inside tests methods
- * unless you purposely want to have side effects between each tests.
- * </p>
- * <p>
- * One can define user session behavior which should apply on all tests directly on the property, eg.:
- * <pre>
- * {@literal @}Rule
- * public UserSessionRule userSession = UserSessionRule.standalone().login("admin").setOrganizationPermissions(OrganizationPermissions.SYSTEM_ADMIN);
- * </pre>
- * </p>
- * <p>
- * Behavior defined at property-level can obviously be override at test method level. For example, one could define
- * all methods to use an authenticated session such as presented above but can easily overwrite that behavior in a
- * specific test method as follow:
- * <pre>
- * {@literal @}Test
- * public void test_method() {
- * userSession.standalone();
- * {@literal [...]}
- * }
- * </pre>
- * </p>
- * <p>
- * {@code UserSessionRule}, emulates by default an anonymous
- * session. Therefore, call {@code UserSessionRule.standalone()} is equivalent to calling
- * {@code UserSessionRule.standalone().anonymous()}.
- * </p>
- * <p>
- * To emulate an identified user, either use method {@link #logIn(String)} if you want to specify the user's login, or
- * method {@link #logIn()} which will do the same but using the value of {@link #DEFAULT_LOGIN} as the user's login
- * (use the latest override if you don't care about the actual value of the login, it will save noise in your test).
- * </p>
- */
-public class UserSessionRule implements TestRule, UserSession {
- private static final String DEFAULT_LOGIN = "default_login";
-
- private UserSession currentUserSession;
-
- private UserSessionRule() {
- anonymous();
- }
-
- public static UserSessionRule standalone() {
- return new UserSessionRule();
- }
-
- /**
- * Log in with the default login {@link #DEFAULT_LOGIN}
- */
- public UserSessionRule logIn() {
- return logIn(DEFAULT_LOGIN);
- }
-
- /**
- * Log in with the specified login
- */
- public UserSessionRule logIn(String login) {
- setCurrentUserSession(new MockUserSession(login));
- return this;
- }
-
- /**
- * Log in with the specified login
- */
- public UserSessionRule logIn(UserDto userDto) {
- setCurrentUserSession(new MockUserSession(userDto));
- return this;
- }
-
- /**
- * Disconnect/go anonymous
- */
- public UserSessionRule anonymous() {
- setCurrentUserSession(new AnonymousMockUserSession());
- return this;
- }
-
- public UserSessionRule setRoot() {
- ensureMockUserSession().setRoot(true);
- return this;
- }
-
- public UserSessionRule setNonRoot() {
- ensureMockUserSession().setRoot(false);
- return this;
- }
-
- public UserSessionRule setSystemAdministrator() {
- ensureMockUserSession().setSystemAdministrator(true);
- return this;
- }
-
- public UserSessionRule setNonSystemAdministrator() {
- ensureMockUserSession().setSystemAdministrator(false);
- return this;
- }
-
- public UserSessionRule setExternalIdentity(IdentityProvider identityProvider, ExternalIdentity externalIdentity) {
- ensureMockUserSession().setExternalIdentity(identityProvider, externalIdentity);
- return this;
- }
-
- public UserSessionRule setInternalIdentity() {
- ensureMockUserSession().setInternalIdentity();
- return this;
- }
-
- @Override
- public Statement apply(Statement statement, Description description) {
- return this.statement(statement);
- }
-
- private Statement statement(final Statement base) {
- return new Statement() {
- public void evaluate() throws Throwable {
- UserSessionRule.this.before();
-
- try {
- base.evaluate();
- } finally {
- UserSessionRule.this.after();
- }
-
- }
- };
- }
-
- protected void before() {
- setCurrentUserSession(currentUserSession);
- }
-
- protected void after() {
- this.currentUserSession = null;
- }
-
- public void set(UserSession userSession) {
- checkNotNull(userSession);
- setCurrentUserSession(userSession);
- }
-
- public UserSessionRule registerComponents(ComponentDto... componentDtos) {
- ensureAbstractMockUserSession().registerComponents(componentDtos);
- return this;
- }
-
- public UserSessionRule addProjectPermission(String projectPermission, ComponentDto... components) {
- ensureAbstractMockUserSession().addProjectPermission(projectPermission, components);
- return this;
- }
-
- public UserSessionRule addPermission(OrganizationPermission permission, String organizationUuid) {
- ensureAbstractMockUserSession().addPermission(permission, organizationUuid);
- return this;
- }
-
- public UserSessionRule addPermission(OrganizationPermission permission, OrganizationDto organization) {
- ensureAbstractMockUserSession().addPermission(permission, organization.getUuid());
- return this;
- }
-
- public UserSessionRule setUserId(@Nullable Integer userId) {
- ensureMockUserSession().setUserId(userId);
- return this;
- }
-
- /**
- * Groups that user is member of. User must be logged in. An exception
- * is thrown if session is anonymous.
- */
- public UserSessionRule setGroups(GroupDto... groups) {
- ensureMockUserSession().setGroups(groups);
- return this;
- }
-
- public UserSessionRule setName(@Nullable String s) {
- ensureMockUserSession().setName(s);
- return this;
- }
-
- private AbstractMockUserSession ensureAbstractMockUserSession() {
- checkState(currentUserSession instanceof AbstractMockUserSession, "rule state can not be changed if a UserSession has explicitly been provided");
- return (AbstractMockUserSession) currentUserSession;
- }
-
- private MockUserSession ensureMockUserSession() {
- checkState(currentUserSession instanceof MockUserSession, "rule state can not be changed if a UserSession has explicitly been provided");
- return (MockUserSession) currentUserSession;
- }
-
- private void setCurrentUserSession(UserSession userSession) {
- this.currentUserSession = Preconditions.checkNotNull(userSession);
- }
-
- @Override
- public boolean hasComponentPermission(String permission, ComponentDto component) {
- return currentUserSession.hasComponentPermission(permission, component);
- }
-
- @Override
- public boolean hasComponentUuidPermission(String permission, String componentUuid) {
- return currentUserSession.hasComponentUuidPermission(permission, componentUuid);
- }
-
- @Override
- public List<ComponentDto> keepAuthorizedComponents(String permission, Collection<ComponentDto> components) {
- return currentUserSession.keepAuthorizedComponents(permission, components);
- }
-
- @Override
- @CheckForNull
- public String getLogin() {
- return currentUserSession.getLogin();
- }
-
- @Override
- @CheckForNull
- public String getUuid() {
- return currentUserSession.getUuid();
- }
-
- @Override
- @CheckForNull
- public String getName() {
- return currentUserSession.getName();
- }
-
- @Override
- @CheckForNull
- public Integer getUserId() {
- return currentUserSession.getUserId();
- }
-
- @Override
- public Collection<GroupDto> getGroups() {
- return currentUserSession.getGroups();
- }
-
- @Override
- public Optional<IdentityProvider> getIdentityProvider() {
- return currentUserSession.getIdentityProvider();
- }
-
- @Override
- public Optional<ExternalIdentity> getExternalIdentity() {
- return currentUserSession.getExternalIdentity();
- }
-
- @Override
- public boolean isLoggedIn() {
- return currentUserSession.isLoggedIn();
- }
-
- @Override
- public boolean isRoot() {
- return currentUserSession.isRoot();
- }
-
- @Override
- public UserSession checkIsRoot() {
- return currentUserSession.checkIsRoot();
- }
-
- @Override
- public UserSession checkLoggedIn() {
- currentUserSession.checkLoggedIn();
- return this;
- }
-
- @Override
- public boolean hasPermission(OrganizationPermission permission, OrganizationDto organization) {
- return currentUserSession.hasPermission(permission, organization);
- }
-
- @Override
- public boolean hasPermission(OrganizationPermission permission, String organizationUuid) {
- return currentUserSession.hasPermission(permission, organizationUuid);
- }
-
- @Override
- public UserSession checkPermission(OrganizationPermission permission, OrganizationDto organization) {
- currentUserSession.checkPermission(permission, organization);
- return this;
- }
-
- @Override
- public UserSession checkPermission(OrganizationPermission permission, String organizationUuid) {
- currentUserSession.checkPermission(permission, organizationUuid);
- return this;
- }
-
- @Override
- public UserSession checkComponentPermission(String projectPermission, ComponentDto component) {
- currentUserSession.checkComponentPermission(projectPermission, component);
- return this;
- }
-
- @Override
- public UserSession checkComponentUuidPermission(String permission, String componentUuid) {
- currentUserSession.checkComponentUuidPermission(permission, componentUuid);
- return this;
- }
-
- @Override
- public boolean isSystemAdministrator() {
- return currentUserSession.isSystemAdministrator();
- }
-
- @Override
- public UserSession checkIsSystemAdministrator() {
- currentUserSession.checkIsSystemAdministrator();
- return this;
- }
-
- @Override
- public boolean hasMembership(OrganizationDto organization) {
- return currentUserSession.hasMembership(organization);
- }
-
- @Override
- public UserSession checkMembership(OrganizationDto organization) {
- currentUserSession.checkMembership(organization);
- return this;
- }
-
- public UserSessionRule addMembership(OrganizationDto organization) {
- ensureAbstractMockUserSession().addOrganizationMembership(organization);
- return this;
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.user;
-
-import java.util.Collection;
-import java.util.Optional;
-import javax.annotation.Nullable;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.permission.OrganizationPermission;
-import org.sonar.db.user.GroupDto;
-import org.sonar.db.user.UserDto;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * Simple implementation of {@link UserSessionFactory}. It creates
- * instances of {@link UserSession} that don't manage groups nor
- * permissions. Only basic user information like {@link UserSession#isLoggedIn()}
- * and {@link UserSession#getLogin()} are available. The methods
- * relying on groups or permissions throw {@link UnsupportedOperationException}.
- */
-public class TestUserSessionFactory implements UserSessionFactory {
-
- private TestUserSessionFactory() {
- }
-
- @Override
- public UserSession create(UserDto user) {
- return new TestUserSession(requireNonNull(user));
- }
-
- @Override
- public UserSession createAnonymous() {
- return new TestUserSession(null);
- }
-
- public static TestUserSessionFactory standalone() {
- return new TestUserSessionFactory();
- }
-
- private static class TestUserSession extends AbstractUserSession {
- private final UserDto user;
-
- public TestUserSession(@Nullable UserDto user) {
- this.user = user;
- }
-
- @Override
- public String getLogin() {
- return user != null ? user.getLogin() : null;
- }
-
- @Override
- public String getUuid() {
- return user != null ? user.getUuid() : null;
- }
-
- @Override
- public String getName() {
- return user != null ? user.getName() : null;
- }
-
- @Override
- public Integer getUserId() {
- return user != null ? user.getId() : null;
- }
-
- @Override
- public Collection<GroupDto> getGroups() {
- throw notImplemented();
- }
-
- @Override
- public Optional<IdentityProvider> getIdentityProvider() {
- throw notImplemented();
- }
-
- @Override
- public Optional<ExternalIdentity> getExternalIdentity() {
- throw notImplemented();
- }
-
- @Override
- public boolean isLoggedIn() {
- return user != null;
- }
-
- @Override
- public boolean isRoot() {
- throw notImplemented();
- }
-
- @Override
- protected boolean hasPermissionImpl(OrganizationPermission permission, String organizationUuid) {
- throw notImplemented();
- }
-
- @Override
- protected Optional<String> componentUuidToProjectUuid(String componentUuid) {
- throw notImplemented();
- }
-
- @Override
- protected boolean hasProjectUuidPermission(String permission, String projectUuid) {
- throw notImplemented();
- }
-
- @Override
- public boolean isSystemAdministrator() {
- throw notImplemented();
- }
-
- @Override
- public boolean hasMembershipImpl(OrganizationDto organizationDto) {
- throw notImplemented();
- }
-
- private static RuntimeException notImplemented() {
- return new UnsupportedOperationException("not implemented");
- }
- }
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.authentication;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+import org.sonar.api.server.authentication.IdentityProvider;
+
+public class IdentityProviderRepositoryRule extends IdentityProviderRepository implements TestRule {
+
+ public IdentityProviderRepositoryRule addIdentityProvider(IdentityProvider identityProvider) {
+ providersByKey.put(identityProvider.getKey(), identityProvider);
+ return this;
+ }
+
+ @Override
+ public Statement apply(final Statement statement, Description description) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ try {
+ statement.evaluate();
+ } finally {
+ providersByKey.clear();
+ }
+ }
+ };
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.authentication;
+
+import org.sonar.api.server.authentication.Display;
+import org.sonar.api.server.authentication.IdentityProvider;
+
+public class TestIdentityProvider implements IdentityProvider {
+
+ private String key;
+ private String name;
+ private Display display;
+ private boolean enabled;
+ private boolean allowsUsersToSignUp;
+
+ @Override
+ public String getKey() {
+ return key;
+ }
+
+ public TestIdentityProvider setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public TestIdentityProvider setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ @Override
+ public Display getDisplay() {
+ return display;
+ }
+
+ public TestIdentityProvider setDisplay(Display display) {
+ this.display = display;
+ return this;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public TestIdentityProvider setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ return this;
+ }
+
+ @Override
+ public boolean allowsUsersToSignUp() {
+ return allowsUsersToSignUp;
+ }
+
+ public TestIdentityProvider setAllowsUsersToSignUp(boolean allowsUsersToSignUp) {
+ this.allowsUsersToSignUp = allowsUsersToSignUp;
+ return this;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (getClass() != o.getClass()) {
+ return false;
+ }
+
+ TestIdentityProvider that = (TestIdentityProvider) o;
+ return key.equals(that.key);
+ }
+
+ @Override
+ public int hashCode() {
+ return key.hashCode();
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.language;
+
+import com.google.common.collect.Collections2;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.resources.AbstractLanguage;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Languages;
+import org.sonar.core.util.NonNullInputFunction;
+
+import java.util.Arrays;
+
+public class LanguageTesting {
+
+ public static Language newLanguage(String key, String name, final String... prefixes) {
+ return new AbstractLanguage(key, name) {
+ @Override
+ public String[] getFileSuffixes() {
+ return prefixes;
+ }
+ };
+ }
+
+ public static Language newLanguage(String key) {
+ return newLanguage(key, StringUtils.capitalize(key));
+ }
+
+ public static Languages newLanguages(String... languageKeys) {
+ return new Languages(Collections2.transform(Arrays.asList(languageKeys), new NonNullInputFunction<String, Language>() {
+ @Override
+ protected Language doApply(String languageKey) {
+ return newLanguage(languageKey);
+ }
+
+ }).toArray(new Language[0]));
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.qualityprofile;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import org.junit.rules.ExternalResource;
+import org.sonar.api.resources.Language;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
+import org.sonar.core.util.stream.MoreCollectors;
+import org.sonar.db.rule.RuleDefinitionDto;
+
+import static com.google.common.base.Preconditions.checkState;
+
+public class BuiltInQProfileRepositoryRule extends ExternalResource implements BuiltInQProfileRepository {
+ private boolean initializeCalled = false;
+ private List<BuiltInQProfile> profiles = new ArrayList<>();
+
+ @Override
+ protected void before() {
+ this.initializeCalled = false;
+ this.profiles.clear();
+ }
+
+ @Override
+ public void initialize() {
+ checkState(!initializeCalled, "initialize must be called only once");
+ this.initializeCalled = true;
+ }
+
+ @Override
+ public List<BuiltInQProfile> get() {
+ checkState(initializeCalled, "initialize must be called first");
+
+ return ImmutableList.copyOf(profiles);
+ }
+
+ public boolean isInitialized() {
+ return initializeCalled;
+ }
+
+ public BuiltInQProfile add(Language language, String profileName) {
+ return add(language, profileName, false);
+ }
+
+ public BuiltInQProfile add(Language language, String profileName, boolean isDefault) {
+ return add(language, profileName, isDefault, new BuiltInQProfile.ActiveRule[0]);
+ }
+
+ public BuiltInQProfile add(Language language, String profileName, boolean isDefault, BuiltInQProfile.ActiveRule... rules) {
+ BuiltInQProfile builtIn = create(language, profileName, isDefault, rules);
+ profiles.add(builtIn);
+ return builtIn;
+ }
+
+ public BuiltInQProfile create(Language language, String profileName, boolean isDefault, BuiltInQProfile.ActiveRule... rules) {
+ BuiltInQProfile.Builder builder = new BuiltInQProfile.Builder()
+ .setLanguage(language.getKey())
+ .setName(profileName)
+ .setDeclaredDefault(isDefault);
+ Arrays.stream(rules).forEach(builder::addRule);
+ return builder.build();
+ }
+
+ public BuiltInQProfile create(BuiltInQualityProfilesDefinition.BuiltInQualityProfile api, RuleDefinitionDto... rules) {
+ BuiltInQProfile.Builder builder = new BuiltInQProfile.Builder()
+ .setLanguage(api.language())
+ .setName(api.name())
+ .setDeclaredDefault(api.isDefault());
+ Map<RuleKey, RuleDefinitionDto> rulesByRuleKey = Arrays.stream(rules)
+ .collect(MoreCollectors.uniqueIndex(RuleDefinitionDto::getKey));
+ api.rules().forEach(rule -> {
+ RuleKey ruleKey = RuleKey.of(rule.repoKey(), rule.ruleKey());
+ RuleDefinitionDto ruleDefinition = rulesByRuleKey.get(ruleKey);
+ Preconditions.checkState(ruleDefinition != null, "Rule '%s' not found", ruleKey);
+ builder.addRule(rule, ruleDefinition.getId());
+ });
+ return builder
+ .build();
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.tester;
+
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableSet;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import org.sonar.api.web.UserRole;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.permission.OrganizationPermission;
+import org.sonar.server.user.AbstractUserSession;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.collect.Maps.newHashMap;
+
+public abstract class AbstractMockUserSession<T extends AbstractMockUserSession> extends AbstractUserSession {
+ private static final Set<String> PUBLIC_PERMISSIONS = ImmutableSet.of(UserRole.USER, UserRole.CODEVIEWER); // FIXME to check with Simon
+
+ private final Class<T> clazz;
+ private HashMultimap<String, String> projectUuidByPermission = HashMultimap.create();
+ private final HashMultimap<String, OrganizationPermission> permissionsByOrganizationUuid = HashMultimap.create();
+ private Map<String, String> projectUuidByComponentUuid = newHashMap();
+ private Set<String> projectPermissions = new HashSet<>();
+ private Set<String> organizationMembership = new HashSet<>();
+ private boolean systemAdministrator = false;
+
+ protected AbstractMockUserSession(Class<T> clazz) {
+ this.clazz = clazz;
+ }
+
+ public T addPermission(OrganizationPermission permission, String organizationUuid) {
+ permissionsByOrganizationUuid.put(organizationUuid, permission);
+ return clazz.cast(this);
+ }
+
+ @Override
+ protected boolean hasPermissionImpl(OrganizationPermission permission, String organizationUuid) {
+ return permissionsByOrganizationUuid.get(organizationUuid).contains(permission);
+ }
+
+ /**
+ * Use this method to register public root component and non root components the UserSession must be aware of.
+ * (ie. this method can be used to emulate the content of the DB)
+ */
+ public T registerComponents(ComponentDto... components) {
+ Arrays.stream(components)
+ .forEach(component -> {
+ if (component.projectUuid().equals(component.uuid()) && !component.isPrivate()) {
+ this.projectUuidByPermission.put(UserRole.USER, component.uuid());
+ this.projectUuidByPermission.put(UserRole.CODEVIEWER, component.uuid());
+ this.projectPermissions.add(UserRole.USER);
+ this.projectPermissions.add(UserRole.CODEVIEWER);
+ }
+ this.projectUuidByComponentUuid.put(component.uuid(), component.projectUuid());
+ });
+ return clazz.cast(this);
+ }
+
+ public T addProjectPermission(String permission, ComponentDto... components) {
+ Arrays.stream(components).forEach(component -> {
+ checkArgument(
+ component.isPrivate() || !PUBLIC_PERMISSIONS.contains(permission),
+ "public component %s can't be granted public permission %s", component.uuid(), permission);
+ });
+ registerComponents(components);
+ this.projectPermissions.add(permission);
+ Arrays.stream(components)
+ .forEach(component -> this.projectUuidByPermission.put(permission, component.projectUuid()));
+ return clazz.cast(this);
+ }
+
+ @Override
+ protected Optional<String> componentUuidToProjectUuid(String componentUuid) {
+ return Optional.ofNullable(projectUuidByComponentUuid.get(componentUuid));
+ }
+
+ @Override
+ protected boolean hasProjectUuidPermission(String permission, String projectUuid) {
+ return projectPermissions.contains(permission) && projectUuidByPermission.get(permission).contains(projectUuid);
+ }
+
+ public T setSystemAdministrator(boolean b) {
+ this.systemAdministrator = b;
+ return clazz.cast(this);
+ }
+
+ @Override
+ public boolean isSystemAdministrator() {
+ return isRoot() || systemAdministrator;
+ }
+
+ @Override
+ protected boolean hasMembershipImpl(OrganizationDto organizationDto) {
+ return organizationMembership.contains(organizationDto.getUuid());
+ }
+
+ public void addOrganizationMembership(OrganizationDto organization) {
+ this.organizationMembership.add(organization.getUuid());
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.tester;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.user.GroupDto;
+
+public class AnonymousMockUserSession extends AbstractMockUserSession<AnonymousMockUserSession> {
+
+ public AnonymousMockUserSession() {
+ super(AnonymousMockUserSession.class);
+ }
+
+ @Override
+ public boolean isRoot() {
+ return false;
+ }
+
+ @Override
+ public String getLogin() {
+ return null;
+ }
+
+ @Override public String getUuid() {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public Integer getUserId() {
+ return null;
+ }
+
+ @Override
+ public boolean isLoggedIn() {
+ return false;
+ }
+
+ @Override
+ public Collection<GroupDto> getGroups() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public Optional<IdentityProvider> getIdentityProvider() {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<ExternalIdentity> getExternalIdentity() {
+ return Optional.empty();
+ }
+
+ @Override
+ public boolean hasMembershipImpl(OrganizationDto organizationDto) {
+ return false;
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.tester;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import org.sonar.db.user.GroupDto;
+import org.sonar.db.user.UserDto;
+import org.sonar.server.user.AbstractUserSession;
+import org.sonar.server.user.UserSession;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Arrays.asList;
+import static java.util.Objects.requireNonNull;
+import static org.sonar.server.user.UserSession.IdentityProvider.SONARQUBE;
+
+public class MockUserSession extends AbstractMockUserSession<MockUserSession> {
+ private final String login;
+ private String uuid;
+ private boolean root = false;
+ private Integer userId;
+ private String name;
+ private List<GroupDto> groups = new ArrayList<>();
+ private UserSession.IdentityProvider identityProvider;
+ private UserSession.ExternalIdentity externalIdentity;
+
+ public MockUserSession(String login) {
+ super(MockUserSession.class);
+ checkArgument(!login.isEmpty());
+ this.login = login;
+ setUuid(login + "uuid");
+ setUserId(login.hashCode());
+ setName(login + " name");
+ setInternalIdentity();
+ }
+
+ public MockUserSession(UserDto userDto) {
+ super(MockUserSession.class);
+ checkArgument(!userDto.getLogin().isEmpty());
+ this.login = userDto.getLogin();
+ setUuid(userDto.getUuid());
+ setUserId(userDto.getId());
+ setName(userDto.getName());
+ AbstractUserSession.Identity identity = AbstractUserSession.computeIdentity(userDto);
+ this.identityProvider = identity.getIdentityProvider();
+ this.externalIdentity = identity.getExternalIdentity();
+ }
+
+ @Override
+ public boolean isLoggedIn() {
+ return true;
+ }
+
+ @Override
+ public boolean isRoot() {
+ return root;
+ }
+
+ public void setRoot(boolean root) {
+ this.root = root;
+ }
+
+ @Override
+ public String getLogin() {
+ return this.login;
+ }
+
+ @Override
+ public String getUuid() {
+ return this.uuid;
+ }
+
+ public MockUserSession setUuid(String uuid) {
+ this.uuid = requireNonNull(uuid);
+ return this;
+ }
+
+ @Override
+ public String getName() {
+ return this.name;
+ }
+
+ public MockUserSession setName(String s) {
+ this.name = requireNonNull(s);
+ return this;
+ }
+
+ @Override
+ public Integer getUserId() {
+ return this.userId;
+ }
+
+ public MockUserSession setUserId(int userId) {
+ this.userId = userId;
+ return this;
+ }
+
+ @Override
+ public Collection<GroupDto> getGroups() {
+ return groups;
+ }
+
+ public MockUserSession setGroups(GroupDto... groups) {
+ this.groups = asList(groups);
+ return this;
+ }
+
+ @Override
+ public Optional<UserSession.IdentityProvider> getIdentityProvider() {
+ return Optional.ofNullable(identityProvider);
+ }
+
+ public void setExternalIdentity(UserSession.IdentityProvider identityProvider, UserSession.ExternalIdentity externalIdentity) {
+ checkArgument(identityProvider != SONARQUBE);
+ this.identityProvider = identityProvider;
+ this.externalIdentity = requireNonNull(externalIdentity);
+ }
+
+ public void setInternalIdentity() {
+ this.identityProvider = SONARQUBE;
+ this.externalIdentity = null;
+ }
+
+ @Override
+ public Optional<UserSession.ExternalIdentity> getExternalIdentity() {
+ return Optional.ofNullable(externalIdentity);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.tester;
+
+import com.google.common.base.Preconditions;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.permission.OrganizationPermission;
+import org.sonar.db.user.GroupDto;
+import org.sonar.db.user.UserDto;
+import org.sonar.server.user.UserSession;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+
+/**
+ * {@code UserSessionRule} is intended to be used as a {@link org.junit.Rule} to easily manage {@link UserSession} in
+ * unit tests.
+ * <p>
+ * It can be used as a {@link org.junit.ClassRule} but be careful not to modify its states from inside tests methods
+ * unless you purposely want to have side effects between each tests.
+ * </p>
+ * <p>
+ * One can define user session behavior which should apply on all tests directly on the property, eg.:
+ * <pre>
+ * {@literal @}Rule
+ * public UserSessionRule userSession = UserSessionRule.standalone().login("admin").setOrganizationPermissions(OrganizationPermissions.SYSTEM_ADMIN);
+ * </pre>
+ * </p>
+ * <p>
+ * Behavior defined at property-level can obviously be override at test method level. For example, one could define
+ * all methods to use an authenticated session such as presented above but can easily overwrite that behavior in a
+ * specific test method as follow:
+ * <pre>
+ * {@literal @}Test
+ * public void test_method() {
+ * userSession.standalone();
+ * {@literal [...]}
+ * }
+ * </pre>
+ * </p>
+ * <p>
+ * {@code UserSessionRule}, emulates by default an anonymous
+ * session. Therefore, call {@code UserSessionRule.standalone()} is equivalent to calling
+ * {@code UserSessionRule.standalone().anonymous()}.
+ * </p>
+ * <p>
+ * To emulate an identified user, either use method {@link #logIn(String)} if you want to specify the user's login, or
+ * method {@link #logIn()} which will do the same but using the value of {@link #DEFAULT_LOGIN} as the user's login
+ * (use the latest override if you don't care about the actual value of the login, it will save noise in your test).
+ * </p>
+ */
+public class UserSessionRule implements TestRule, UserSession {
+ private static final String DEFAULT_LOGIN = "default_login";
+
+ private UserSession currentUserSession;
+
+ private UserSessionRule() {
+ anonymous();
+ }
+
+ public static UserSessionRule standalone() {
+ return new UserSessionRule();
+ }
+
+ /**
+ * Log in with the default login {@link #DEFAULT_LOGIN}
+ */
+ public UserSessionRule logIn() {
+ return logIn(DEFAULT_LOGIN);
+ }
+
+ /**
+ * Log in with the specified login
+ */
+ public UserSessionRule logIn(String login) {
+ setCurrentUserSession(new MockUserSession(login));
+ return this;
+ }
+
+ /**
+ * Log in with the specified login
+ */
+ public UserSessionRule logIn(UserDto userDto) {
+ setCurrentUserSession(new MockUserSession(userDto));
+ return this;
+ }
+
+ /**
+ * Disconnect/go anonymous
+ */
+ public UserSessionRule anonymous() {
+ setCurrentUserSession(new AnonymousMockUserSession());
+ return this;
+ }
+
+ public UserSessionRule setRoot() {
+ ensureMockUserSession().setRoot(true);
+ return this;
+ }
+
+ public UserSessionRule setNonRoot() {
+ ensureMockUserSession().setRoot(false);
+ return this;
+ }
+
+ public UserSessionRule setSystemAdministrator() {
+ ensureMockUserSession().setSystemAdministrator(true);
+ return this;
+ }
+
+ public UserSessionRule setNonSystemAdministrator() {
+ ensureMockUserSession().setSystemAdministrator(false);
+ return this;
+ }
+
+ public UserSessionRule setExternalIdentity(IdentityProvider identityProvider, ExternalIdentity externalIdentity) {
+ ensureMockUserSession().setExternalIdentity(identityProvider, externalIdentity);
+ return this;
+ }
+
+ public UserSessionRule setInternalIdentity() {
+ ensureMockUserSession().setInternalIdentity();
+ return this;
+ }
+
+ @Override
+ public Statement apply(Statement statement, Description description) {
+ return this.statement(statement);
+ }
+
+ private Statement statement(final Statement base) {
+ return new Statement() {
+ public void evaluate() throws Throwable {
+ UserSessionRule.this.before();
+
+ try {
+ base.evaluate();
+ } finally {
+ UserSessionRule.this.after();
+ }
+
+ }
+ };
+ }
+
+ protected void before() {
+ setCurrentUserSession(currentUserSession);
+ }
+
+ protected void after() {
+ this.currentUserSession = null;
+ }
+
+ public void set(UserSession userSession) {
+ checkNotNull(userSession);
+ setCurrentUserSession(userSession);
+ }
+
+ public UserSessionRule registerComponents(ComponentDto... componentDtos) {
+ ensureAbstractMockUserSession().registerComponents(componentDtos);
+ return this;
+ }
+
+ public UserSessionRule addProjectPermission(String projectPermission, ComponentDto... components) {
+ ensureAbstractMockUserSession().addProjectPermission(projectPermission, components);
+ return this;
+ }
+
+ public UserSessionRule addPermission(OrganizationPermission permission, String organizationUuid) {
+ ensureAbstractMockUserSession().addPermission(permission, organizationUuid);
+ return this;
+ }
+
+ public UserSessionRule addPermission(OrganizationPermission permission, OrganizationDto organization) {
+ ensureAbstractMockUserSession().addPermission(permission, organization.getUuid());
+ return this;
+ }
+
+ public UserSessionRule setUserId(@Nullable Integer userId) {
+ ensureMockUserSession().setUserId(userId);
+ return this;
+ }
+
+ /**
+ * Groups that user is member of. User must be logged in. An exception
+ * is thrown if session is anonymous.
+ */
+ public UserSessionRule setGroups(GroupDto... groups) {
+ ensureMockUserSession().setGroups(groups);
+ return this;
+ }
+
+ public UserSessionRule setName(@Nullable String s) {
+ ensureMockUserSession().setName(s);
+ return this;
+ }
+
+ private AbstractMockUserSession ensureAbstractMockUserSession() {
+ checkState(currentUserSession instanceof AbstractMockUserSession, "rule state can not be changed if a UserSession has explicitly been provided");
+ return (AbstractMockUserSession) currentUserSession;
+ }
+
+ private MockUserSession ensureMockUserSession() {
+ checkState(currentUserSession instanceof MockUserSession, "rule state can not be changed if a UserSession has explicitly been provided");
+ return (MockUserSession) currentUserSession;
+ }
+
+ private void setCurrentUserSession(UserSession userSession) {
+ this.currentUserSession = Preconditions.checkNotNull(userSession);
+ }
+
+ @Override
+ public boolean hasComponentPermission(String permission, ComponentDto component) {
+ return currentUserSession.hasComponentPermission(permission, component);
+ }
+
+ @Override
+ public boolean hasComponentUuidPermission(String permission, String componentUuid) {
+ return currentUserSession.hasComponentUuidPermission(permission, componentUuid);
+ }
+
+ @Override
+ public List<ComponentDto> keepAuthorizedComponents(String permission, Collection<ComponentDto> components) {
+ return currentUserSession.keepAuthorizedComponents(permission, components);
+ }
+
+ @Override
+ @CheckForNull
+ public String getLogin() {
+ return currentUserSession.getLogin();
+ }
+
+ @Override
+ @CheckForNull
+ public String getUuid() {
+ return currentUserSession.getUuid();
+ }
+
+ @Override
+ @CheckForNull
+ public String getName() {
+ return currentUserSession.getName();
+ }
+
+ @Override
+ @CheckForNull
+ public Integer getUserId() {
+ return currentUserSession.getUserId();
+ }
+
+ @Override
+ public Collection<GroupDto> getGroups() {
+ return currentUserSession.getGroups();
+ }
+
+ @Override
+ public Optional<IdentityProvider> getIdentityProvider() {
+ return currentUserSession.getIdentityProvider();
+ }
+
+ @Override
+ public Optional<ExternalIdentity> getExternalIdentity() {
+ return currentUserSession.getExternalIdentity();
+ }
+
+ @Override
+ public boolean isLoggedIn() {
+ return currentUserSession.isLoggedIn();
+ }
+
+ @Override
+ public boolean isRoot() {
+ return currentUserSession.isRoot();
+ }
+
+ @Override
+ public UserSession checkIsRoot() {
+ return currentUserSession.checkIsRoot();
+ }
+
+ @Override
+ public UserSession checkLoggedIn() {
+ currentUserSession.checkLoggedIn();
+ return this;
+ }
+
+ @Override
+ public boolean hasPermission(OrganizationPermission permission, OrganizationDto organization) {
+ return currentUserSession.hasPermission(permission, organization);
+ }
+
+ @Override
+ public boolean hasPermission(OrganizationPermission permission, String organizationUuid) {
+ return currentUserSession.hasPermission(permission, organizationUuid);
+ }
+
+ @Override
+ public UserSession checkPermission(OrganizationPermission permission, OrganizationDto organization) {
+ currentUserSession.checkPermission(permission, organization);
+ return this;
+ }
+
+ @Override
+ public UserSession checkPermission(OrganizationPermission permission, String organizationUuid) {
+ currentUserSession.checkPermission(permission, organizationUuid);
+ return this;
+ }
+
+ @Override
+ public UserSession checkComponentPermission(String projectPermission, ComponentDto component) {
+ currentUserSession.checkComponentPermission(projectPermission, component);
+ return this;
+ }
+
+ @Override
+ public UserSession checkComponentUuidPermission(String permission, String componentUuid) {
+ currentUserSession.checkComponentUuidPermission(permission, componentUuid);
+ return this;
+ }
+
+ @Override
+ public boolean isSystemAdministrator() {
+ return currentUserSession.isSystemAdministrator();
+ }
+
+ @Override
+ public UserSession checkIsSystemAdministrator() {
+ currentUserSession.checkIsSystemAdministrator();
+ return this;
+ }
+
+ @Override
+ public boolean hasMembership(OrganizationDto organization) {
+ return currentUserSession.hasMembership(organization);
+ }
+
+ @Override
+ public UserSession checkMembership(OrganizationDto organization) {
+ currentUserSession.checkMembership(organization);
+ return this;
+ }
+
+ public UserSessionRule addMembership(OrganizationDto organization) {
+ ensureAbstractMockUserSession().addOrganizationMembership(organization);
+ return this;
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.user;
+
+import java.util.Collection;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.permission.OrganizationPermission;
+import org.sonar.db.user.GroupDto;
+import org.sonar.db.user.UserDto;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Simple implementation of {@link UserSessionFactory}. It creates
+ * instances of {@link UserSession} that don't manage groups nor
+ * permissions. Only basic user information like {@link UserSession#isLoggedIn()}
+ * and {@link UserSession#getLogin()} are available. The methods
+ * relying on groups or permissions throw {@link UnsupportedOperationException}.
+ */
+public class TestUserSessionFactory implements UserSessionFactory {
+
+ private TestUserSessionFactory() {
+ }
+
+ @Override
+ public UserSession create(UserDto user) {
+ return new TestUserSession(requireNonNull(user));
+ }
+
+ @Override
+ public UserSession createAnonymous() {
+ return new TestUserSession(null);
+ }
+
+ public static TestUserSessionFactory standalone() {
+ return new TestUserSessionFactory();
+ }
+
+ private static class TestUserSession extends AbstractUserSession {
+ private final UserDto user;
+
+ public TestUserSession(@Nullable UserDto user) {
+ this.user = user;
+ }
+
+ @Override
+ public String getLogin() {
+ return user != null ? user.getLogin() : null;
+ }
+
+ @Override
+ public String getUuid() {
+ return user != null ? user.getUuid() : null;
+ }
+
+ @Override
+ public String getName() {
+ return user != null ? user.getName() : null;
+ }
+
+ @Override
+ public Integer getUserId() {
+ return user != null ? user.getId() : null;
+ }
+
+ @Override
+ public Collection<GroupDto> getGroups() {
+ throw notImplemented();
+ }
+
+ @Override
+ public Optional<IdentityProvider> getIdentityProvider() {
+ throw notImplemented();
+ }
+
+ @Override
+ public Optional<ExternalIdentity> getExternalIdentity() {
+ throw notImplemented();
+ }
+
+ @Override
+ public boolean isLoggedIn() {
+ return user != null;
+ }
+
+ @Override
+ public boolean isRoot() {
+ throw notImplemented();
+ }
+
+ @Override
+ protected boolean hasPermissionImpl(OrganizationPermission permission, String organizationUuid) {
+ throw notImplemented();
+ }
+
+ @Override
+ protected Optional<String> componentUuidToProjectUuid(String componentUuid) {
+ throw notImplemented();
+ }
+
+ @Override
+ protected boolean hasProjectUuidPermission(String permission, String projectUuid) {
+ throw notImplemented();
+ }
+
+ @Override
+ public boolean isSystemAdministrator() {
+ throw notImplemented();
+ }
+
+ @Override
+ public boolean hasMembershipImpl(OrganizationDto organizationDto) {
+ throw notImplemented();
+ }
+
+ private static RuntimeException notImplemented() {
+ return new UnsupportedOperationException("not implemented");
+ }
+ }
+}
testCompile 'org.mockito:mockito-core'
testCompile 'org.subethamail:subethasmtp'
testCompile testFixtures(project(':server:sonar-server-common'))
- testCompile project(path: ":server:sonar-webserver-auth", configuration: "tests")
+ testCompile testFixtures(project(':server:sonar-webserver-auth'))
testCompile project(path: ":server:sonar-webserver-es", configuration: "tests")
testCompile testFixtures(project(':server:sonar-webserver-ws'))
testCompile project(':sonar-testing-harness')
testCompile 'com.google.code.findbugs:jsr305'
testCompile 'com.tngtech.java:junit-dataprovider'
testCompile 'org.mockito:mockito-core'
- testCompile project(path: ":server:sonar-webserver-auth", configuration: "tests")
+ testCompile testFixtures(project(':server:sonar-webserver-auth'))
testCompile testFixtures(project(':server:sonar-server-common'))
testCompile project(':sonar-testing-harness')
}
testCompile 'javax.servlet:javax.servlet-api'
testCompile 'org.mockito:mockito-core'
testCompile testFixtures(project(':server:sonar-server-common'))
- testCompile project(path: ":server:sonar-webserver-auth", configuration: "tests")
+ testCompile testFixtures(project(':server:sonar-webserver-auth'))
testCompile project(path: ":server:sonar-webserver-es", configuration: "tests")
testCompile testFixtures(project(':server:sonar-webserver-ws'))
testCompile project(':sonar-testing-harness')
testCompile 'org.eclipse.jetty:jetty-server'
testCompile 'org.eclipse.jetty:jetty-servlet'
testCompile testFixtures(project(':server:sonar-server-common'))
- testCompile project(path: ":server:sonar-webserver-auth", configuration: "tests")
+ testCompile testFixtures(project(':server:sonar-webserver-auth'))
testCompile project(path: ":server:sonar-webserver-es", configuration: "tests")
testCompile project(':sonar-testing-harness')
}