The 'admin' user is replaced by a new random admin user in order to avoid the onboarding tutorial to be displayed
import pageobjects.Navigation;
import pageobjects.ProjectsManagementPage;
import util.ItUtils;
+import util.user.UserRule;
import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.newAdminWsClient;
@ClassRule
public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
+
@Rule
public Navigation nav = Navigation.get(orchestrator);
+ private String adminUser;
+
@Before
- public void deleteAnalysisData() throws SQLException {
+ public void initData() throws SQLException {
orchestrator.resetData();
+ adminUser = userRule.createAdminUser();
}
@Test
// Remove 'Admin' permission for admin group on project 2 -> No one can access or admin this project, expect System Admin
newAdminWsClient(orchestrator).permissions().removeGroup(new RemoveGroupWsRequest().setProjectKey("sample2").setGroupName("sonar-administrators").setPermission("admin"));
- nav.logIn().asAdmin().openProjectsManagement()
+ nav.logIn().submitCredentials(adminUser).openProjectsManagement()
.shouldHaveProject("sample1")
.shouldHaveProject("sample2");
}
}
private void createProjectAndVerify(String visibility) {
- ProjectsManagementPage page = nav.logIn().asAdmin().openProjectsManagement();
+ ProjectsManagementPage page = nav.logIn().submitCredentials(adminUser, adminUser).openProjectsManagement();
page
.shouldHaveProjectsCount(0)
.createProject("foo", "foo", visibility)
import com.sonar.orchestrator.Orchestrator;
import it.Category1Suite;
import java.util.List;
+import org.junit.After;
+import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
public class UsersPageTest {
+ private static final String ADMIN_USER_LOGIN = "admin-user";
+
@ClassRule
public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
private WsClient adminClient = newAdminWsClient(orchestrator);
+ @Before
+ public void initAdminUser() throws Exception {
+ userRule.createAdminUser(ADMIN_USER_LOGIN, ADMIN_USER_LOGIN);
+ }
+
+ @After
+ public void deleteAdminUser() {
+ userRule.resetUsers();
+ }
+
@Test
public void generate_and_revoke_user_token() {
Selenese.runSelenese(orchestrator, "/administration/UsersPageTest/generate_and_revoke_user_token.html");
import com.sonar.orchestrator.Orchestrator;
import it.Category2Suite;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
@ClassRule
public static Orchestrator ORCHESTRATOR = Category2Suite.ORCHESTRATOR;
- @ClassRule
- public static UserRule userRule = UserRule.from(ORCHESTRATOR);
+ @Rule
+ public UserRule userRule = UserRule.from(ORCHESTRATOR);
@Rule
public Navigation nav = Navigation.get(ORCHESTRATOR);
+ private String adminUser;
+
@BeforeClass
public static void prepareData() {
ORCHESTRATOR.resetData();
runProjectAnalysis(ORCHESTRATOR, "shared/xoo-multi-modules-sample");
}
+ @Before
+ public void before() {
+ adminUser = userRule.createAdminUser();
+ }
+
@Test
public void should_display_actions() {
- IssuesPage page = nav.logIn().asAdmin().openIssues();
+ IssuesPage page = nav.logIn().submitCredentials(adminUser).openIssues();
Issue issue = page.getFirstIssue();
issue.shouldAllowAssign().shouldAllowChangeType();
}
@ClassRule
public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
-
@Rule
public OrganizationRule organizations = new OrganizationRule(orchestrator);
@Rule
- public UserRule userRule = new UserRule(orchestrator);
- @Rule
- public IssueRule issueRule = IssueRule.from(orchestrator);
+ public UserRule userRule = UserRule.from(orchestrator);
+ @ClassRule
+ public static IssueRule issueRule = IssueRule.from(orchestrator);
@Rule
public Navigation nav = Navigation.get(orchestrator);
private WsClient adminClient = newAdminWsClient(orchestrator);
+ private String adminUser;
@Before
public void setUp() throws Exception {
createOrganization(ORGANIZATION_KEY);
restoreProfile(orchestrator, getClass().getResource("/organization/IssueAssignTest/one-issue-per-file-profile.xml"), ORGANIZATION_KEY);
+ adminUser = userRule.createRootUser();
}
@Test
adminClient.organizations().addMember(ORGANIZATION_KEY, ASSIGNEE_LOGIN);
userRule.createUser(OTHER_LOGIN, "pwd");
provisionAndAnalyseProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY);
- IssuesPage page = nav.logIn().asAdmin().openIssues();
+ IssuesPage page = nav.logIn().submitCredentials(adminUser).openIssues();
page.getFirstIssue()
.shouldAllowAssign()
.assigneeSearchResultCount(OTHER_LOGIN, 0)
adminClient.organizations().addMember(ORGANIZATION_KEY, ASSIGNEE_LOGIN);
userRule.createUser(OTHER_LOGIN, "pwd");
provisionAndAnalyseProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY);
- IssuesPage page = nav.logIn().asAdmin().openComponentIssues(SAMPLE_PROJECT_KEY);
+ IssuesPage page = nav.logIn().submitCredentials(adminUser).openComponentIssues(SAMPLE_PROJECT_KEY);
page
.bulkChangeOpen()
.bulkChangeAssigneeSearchCount(ASSIGNEE_LOGIN, 1)
adminClient.organizations().addMember(ORGANIZATION_KEY, ASSIGNEE_LOGIN);
userRule.createUser(OTHER_LOGIN, "pwd");
provisionAndAnalyseProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY);
- IssuesPage page = nav.logIn().asAdmin().openIssues();
+ IssuesPage page = nav.logIn().submitCredentials(adminUser).openIssues();
page
.bulkChangeOpen()
.bulkChangeAssigneeSearchCount(ASSIGNEE_LOGIN, 1)
import org.sonarqube.ws.client.WsClient;
import pageobjects.Navigation;
import pageobjects.ProjectDashboardPage;
+import util.user.UserRule;
import static com.codeborne.selenide.Condition.hasText;
import static com.codeborne.selenide.Condition.text;
import static util.selenium.Selenese.runSelenese;
public class ProjectDashboardTest {
+
@ClassRule
public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
+
@Rule
public Navigation nav = Navigation.get(orchestrator);
private static WsClient wsClient;
+ private String adminUser;
@Before
public void setUp() throws Exception {
wsClient = newAdminWsClient(orchestrator);
orchestrator.resetData();
+ adminUser = userRule.createAdminUser();
}
@Test
wsClient.wsConnector().call(
new PostRequest("api/project_tags/set")
.setParam("project", "sample")
- .setParam("tags", "foo,bar,baz")
- );
+ .setParam("tags", "foo,bar,baz"));
ProjectDashboardPage page = nav.openProjectDashboard("sample");
page
executeBuild("shared/xoo-sample", "sample-with-tags", "Sample with tags");
// Add some tags to another project to have them in the list
wsClient.wsConnector().call(
- new PostRequest("api/project_tags/set")
- .setParam("project", "sample-with-tags")
- .setParam("tags", "foo,bar,baz")
- );
+ new PostRequest("api/project_tags/set")
+ .setParam("project", "sample-with-tags")
+ .setParam("tags", "foo,bar,baz"));
executeBuild("shared/xoo-sample", "sample", "Sample");
- ProjectDashboardPage page = nav.logIn().asAdmin().openProjectDashboard("sample");
+ ProjectDashboardPage page = nav.logIn().submitCredentials(adminUser).openProjectDashboard("sample");
page
.shouldHaveTags("No tags")
.shouldBeEditable()
orchestrator.executeBuild(
SonarScanner.create(projectDir(projectLocation))
.setProjectKey(projectKey)
- .setProjectName(projectName)
- );
+ .setProjectName(projectName));
}
}
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.ws.client.WsClient;
import pageobjects.Navigation;
import util.ItUtils;
+import util.user.UserRule;
import static org.apache.commons.lang.time.DateUtils.addDays;
import static org.assertj.core.api.Assertions.assertThat;
@ClassRule
public static final Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
+
+ private String adminUser;
+
@BeforeClass
public static void createWsClient() throws Exception {
CLIENT = newAdminWsClient(orchestrator);
@Before
public void cleanUpAnalysisData() {
orchestrator.resetData();
+ adminUser = userRule.createAdminUser();
}
@After
assertThat(getLeakPeriodValue(orchestrator, PROJECT_KEY, "violations")).isEqualTo(17);
// Check on ui that it's possible to define leak period on project
- Navigation.get(orchestrator).openHomepage().logIn().asAdmin().openSettings("sample")
+ Navigation.get(orchestrator).openHomepage().logIn().submitCredentials(adminUser).openSettings("sample")
.assertSettingDisplayed("sonar.leak.period");
}
public Navigation nav = Navigation.get(orchestrator);
private static WsClient adminClient;
+ private String adminUser;
@BeforeClass
public static void prepare() {
resetSettings(orchestrator, null, PROPERTY_PREVENT_ANALYSIS, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate");
}
+ @Before
+ public void createAdminUser() throws Exception {
+ adminUser = userRule.createRootUser();
+ }
+
@Test
public void execute_successfully_ce_analysis_on_organization() {
String organizationKey = createOrganization();
String projectKey = createPublicProject(createOrganization());
setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "true");
- nav.logIn().asAdmin().openProjectPermissions(projectKey)
+ nav.logIn().submitCredentials(adminUser).openProjectPermissions(projectKey)
.shouldBePublic()
.shouldNotAllowPrivate();
}
String projectKey = createPublicProject(createOrganization());
setServerProperty(orchestrator, "sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
- nav.logIn().asAdmin().openProjectPermissions(projectKey)
+ nav.logIn().submitCredentials(adminUser).openProjectPermissions(projectKey)
.shouldBePublic()
.turnToPrivate();
}
- private static String createOrganization() {
+ private String createOrganization() {
String key = newOrganizationKey();
adminClient.organizations().create(new CreateWsRequest.Builder().setKey(key).setName(key).build()).getOrganization();
return key;
return projectKey;
}
- private static String executeAnalysis(String organizationKey) {
+ private String executeAnalysis(String organizationKey) {
return executeAnalysis(newProjectKey(), organizationKey);
}
- private static String executeAnalysis(String projectKey, String organizationKey) {
+ private String executeAnalysis(String projectKey, String organizationKey) {
BuildResult buildResult = orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"),
"sonar.organization", organizationKey,
"sonar.projectKey", projectKey,
- "sonar.login", "admin",
- "sonar.password", "admin"));
+ "sonar.login", adminUser,
+ "sonar.password", adminUser));
return ItUtils.extractCeTaskId(buildResult);
}
import org.sonarqube.ws.client.HttpException;
import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.permission.AddUserWsRequest;
+import pageobjects.Navigation;
import util.OrganizationRule;
import util.user.UserRule;
private static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
private static OrganizationRule organizations = new OrganizationRule(orchestrator);
private static UserRule users = new UserRule(orchestrator);
+ private static Navigation nav = Navigation.get(orchestrator);
@ClassRule
public static TestRule chain = RuleChain.outerRule(orchestrator)
.around(users)
- .around(organizations);
+ .around(organizations)
+ .around(nav);
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private static WsClient rootWsClient;
+ private static WsClient adminClient;
@BeforeClass
public static void setUp() {
- rootWsClient = newAdminWsClient(orchestrator);
+ adminClient = newAdminWsClient(orchestrator);
setServerProperty(orchestrator, "sonar.organizations.anyoneCanCreate", "true");
}
User user = users.createUser();
addMembership(organization, user);
- rootWsClient.permissions().addUser(new AddUserWsRequest().setLogin(user.getLogin()).setPermission("admin").setOrganization(organization.getKey()));
+ adminClient.permissions().addUser(new AddUserWsRequest().setLogin(user.getLogin()).setPermission("admin").setOrganization(organization.getKey()));
organizations.assertThatMemberOf(organization, user);
removeMembership(organization, user);
User user = users.createUser();
addMembership(organization, user);
- rootWsClient.permissions().addUser(new AddUserWsRequest().setLogin(user.getLogin()).setPermission("admin").setOrganization(organization.getKey()));
+ adminClient.permissions().addUser(new AddUserWsRequest().setLogin(user.getLogin()).setPermission("admin").setOrganization(organization.getKey()));
organizations.assertThatMemberOf(organization, user);
// Admin is the creator of the organization so he was granted with admin permission
- rootWsClient.organizations().removeMember(organization.getKey(), "admin");
+ adminClient.organizations().removeMember(organization.getKey(), "admin");
expectedException.expect(HttpException.class);
expectedException.expectMessage("The last administrator member cannot be removed");
}
private void addMembership(Organization organization, User user) {
- rootWsClient.organizations().addMember(organization.getKey(), user.getLogin());
+ adminClient.organizations().addMember(organization.getKey(), user.getLogin());
}
private void removeMembership(Organization organization, User user) {
- rootWsClient.organizations().removeMember(organization.getKey(), user.getLogin());
+ adminClient.organizations().removeMember(organization.getKey(), user.getLogin());
}
}
import com.sonar.orchestrator.Orchestrator;
import it.Category6Suite;
+import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
public Navigation nav = Navigation.get(orchestrator);
private static WsClient rootWsClient;
+ private String adminUser;
@BeforeClass
public static void setUp() {
setServerProperty(orchestrator, "sonar.organizations.anyoneCanCreate", null);
}
+ @Before
+ public void createRootUser() {
+ adminUser = users.createRootUser();
+ }
+
+ @After
+ public void purgeData() throws Exception {
+ organizations.deleteOrganizations();
+ users.deactivateAllUsers();
+ }
+
@Test
public void should_display_members_page() {
Organization organization = organizations.create();
addMembership(organization, member1);
User member2 = users.createUser(p -> p.setName("bar"));
addMembership(organization, member2);
- User nonMember = users.createUser();
+ users.createUser();
MembersPage page = nav.openOrganizationMembers(organization.getKey());
page
@Test
public void search_for_members() {
Organization organization = organizations.create();
- User member1 = users.createUser(p -> p.setName("foo"));
- addMembership(organization, member1);
- User member2 = users.createUser(p -> p.setName("barGuy"));
- addMembership(organization, member2);
+
+ User user1 = users.createUser();
+ rootWsClient.organizations().addMember(organization.getKey(), user1.getLogin());
+
+ User user2 = users.createUser(p -> p.setLogin("sameprefixuser1"));
+ rootWsClient.organizations().addMember(organization.getKey(), user2.getLogin());
+
// Created to verify that only the user part of the org is returned
- User userWithSameNamePrefix = users.createUser(p -> p.setName(member2.getName() + "barOtherGuy"));
+ users.createUser(p -> p.setLogin("sameprefixuser2"));
MembersPage page = nav.openOrganizationMembers(organization.getKey());
page
- .searchForMember("bar")
+ .searchForMember("sameprefixuser")
.shouldHaveTotal(1);
- page.getMembersByIdx(0)
- .shouldBeNamed(member2.getLogin(), member2.getName());
+ page.getMembersByIdx(0).shouldBeNamed(user2.getLogin(), user2.getName());
page
- .searchForMember(member1.getName())
+ .searchForMember(user1.getLogin())
.shouldHaveTotal(1);
- page.getMembersByIdx(0)
- .shouldBeNamed(member1.getLogin(), member1.getName());
+ page.getMembersByIdx(0).shouldBeNamed(user1.getLogin(), user1.getName());
}
@Test
public void admin_can_add_members() {
Organization organization = organizations.create();
- User user = users.createUser();
+ String orgKey = organization.getKey();
+ User user = users.createUser(p -> p.setLogin("foo"));
+ users.createUser();
- MembersPage page = nav.logIn().asAdmin().openOrganizationMembers(organization.getKey());
+ MembersPage page = nav.logIn().submitCredentials(adminUser).openOrganizationMembers(orgKey);
page
.shouldHaveTotal(1)
.addMember(user.getLogin())
.shouldHaveTotal(2);
- page.getMembersByIdx(0)
- .shouldBeNamed("admin", "Administrator")
- .shouldHaveGroups(2);
- page.getMembersByIdx(1)
- .shouldBeNamed(user.getLogin(), user.getName())
- .shouldHaveGroups(1);
+ page.getMembersByIdx(0).shouldBeNamed("admin", "Administrator").shouldHaveGroups(2);
+ page.getMembersByIdx(1).shouldBeNamed(user.getLogin(), user.getName()).shouldHaveGroups(1);
}
@Test
public void admin_can_remove_members() {
Organization organization = organizations.create();
+ String orgKey = organization.getKey();
+
User user1 = users.createUser();
- addMembership(organization, user1);
+ rootWsClient.organizations().addMember(orgKey, user1.getLogin());
+
User user2 = users.createUser();
- addMembership(organization, user2);
+ rootWsClient.organizations().addMember(orgKey, user2.getLogin());
- MembersPage page = nav.logIn().asAdmin().openOrganizationMembers(organization.getKey());
+ MembersPage page = nav.logIn().submitCredentials(adminUser).openOrganizationMembers(orgKey);
page.shouldHaveTotal(3)
.getMembersByIdx(1).removeMembership();
page.shouldHaveTotal(2);
@Test
public void admin_can_manage_groups() {
Organization organization = organizations.create();
- User user = users.createUser();
- addMembership(organization, user);
+ String orgKey = organization.getKey();
+
+ User user = users.createUser(p -> p.setLogin("foo"));
+ rootWsClient.organizations().addMember(orgKey, user.getLogin());
- MembersPage page = nav.logIn().asAdmin().openOrganizationMembers(organization.getKey());
+ MembersPage page = nav.logIn().submitCredentials(adminUser).openOrganizationMembers(orgKey);
// foo user
page.getMembersByIdx(1)
.manageGroupsOpen()
@Test
public void groups_count_should_be_updated_when_a_member_was_just_added() {
Organization organization = organizations.create();
- User user = users.createUser();
+ String orgKey = organization.getKey();
+ User user = users.createUser(p -> p.setLogin("foo"));
- MembersPage page = nav.logIn().asAdmin().openOrganizationMembers(organization.getKey());
+ MembersPage page = nav.logIn().submitCredentials(adminUser).openOrganizationMembers(orgKey);
page
.addMember(user.getLogin())
.getMembersByIdx(1)
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
import it.Category1Suite;
+import org.junit.After;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import pageobjects.BackgroundTaskItem;
import pageobjects.BackgroundTasksPage;
import pageobjects.Navigation;
+import util.user.UserRule;
import static com.codeborne.selenide.CollectionCondition.sizeGreaterThan;
import static util.ItUtils.projectDir;
public class BackgroundTasksTest {
+ private static final String ADMIN_USER_LOGIN = "admin-user";
+
@ClassRule
public static Orchestrator ORCHESTRATOR = Category1Suite.ORCHESTRATOR;
+ @Rule
+ public UserRule userRule = UserRule.from(ORCHESTRATOR);
+
@Rule
public Navigation nav = Navigation.get(ORCHESTRATOR);
executeBuild("test-project-2", "Another Test Project");
}
+ @Before
+ public void before() {
+ userRule.createAdminUser(ADMIN_USER_LOGIN, ADMIN_USER_LOGIN);
+ }
+
+ @After
+ public void deleteAdminUser() {
+ userRule.resetUsers();
+ }
+
@Test
public void should_not_display_failing_and_search_and_filter_elements_on_project_level_page() throws Exception {
- runSelenese(ORCHESTRATOR,
- "/projectAdministration/BackgroundTasksTest/should_not_display_failing_and_search_and_filter_elements_on_project_level_page.html");
+ runSelenese(ORCHESTRATOR, "/projectAdministration/BackgroundTasksTest/should_not_display_failing_and_search_and_filter_elements_on_project_level_page.html");
}
@Test
public void display_scanner_context() {
- nav.logIn().submitCredentials("admin", "admin");
+ nav.logIn().submitCredentials(ADMIN_USER_LOGIN);
BackgroundTasksPage page = nav.openBackgroundTasksPage();
page.getTasks().shouldHave(sizeGreaterThan(0));
public void display_error_stacktrace() {
executeBuild("test-project", "Test Project", "2010-01-01");
- nav.logIn().submitCredentials("admin", "admin");
+ nav.logIn().submitCredentials(ADMIN_USER_LOGIN);
BackgroundTasksPage page = nav.openBackgroundTasksPage();
page.getTasks().shouldHave(sizeGreaterThan(0));
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
import it.Category1Suite;
+import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
+import util.user.UserRule;
import static util.ItUtils.projectDir;
import static util.selenium.Selenese.runSelenese;
public class BulkDeletionTest {
+ private static final String ADMIN_USER_LOGIN = "admin-user";
+
@ClassRule
public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
+
@Before
public void deleteData() {
orchestrator.resetData();
+ userRule.createAdminUser(ADMIN_USER_LOGIN, ADMIN_USER_LOGIN);
+ }
+
+ @After
+ public void deleteAdminUser() {
+ userRule.resetUsers();
}
/**
import org.sonar.wsclient.user.UserParameters;
import pageobjects.Navigation;
import pageobjects.settings.SettingsPage;
+import util.user.UserRule;
import static org.apache.commons.lang.time.DateUtils.addDays;
import static org.assertj.core.api.Assertions.assertThat;
@Rule
public ExpectedException expectedException = ExpectedException.none();
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
+
@Rule
public Navigation nav = Navigation.get(orchestrator);
private static final String PROJECT_KEY = "sample";
private static final String FILE_KEY = "sample:src/main/xoo/sample/Sample.xoo";
+ private String adminUser;
@Before
public void deleteAnalysisData() throws SQLException {
orchestrator.resetData();
+ adminUser = userRule.createAdminUser();
}
@Test
public void display_project_settings() throws UnsupportedEncodingException {
scanSample(null, null);
- SettingsPage page = nav.logIn().asAdmin().openSettings("sample")
+ SettingsPage page = nav.logIn().submitCredentials(adminUser).openSettings("sample")
.assertMenuContains("Analysis Scope")
.assertMenuContains("Category 1")
.assertMenuContains("DEV")
public void display_module_settings() throws UnsupportedEncodingException {
orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-multi-modules-sample")));
- nav.logIn().asAdmin()
+ nav.logIn().submitCredentials(adminUser)
.openSettings("com.sonarsource.it.samples:multi-modules-sample:module_a")
.assertMenuContains("Analysis Scope")
.assertSettingDisplayed("sonar.coverage.exclusions");
import pageobjects.Navigation;
import pageobjects.ProjectLinkItem;
import pageobjects.ProjectLinksPage;
+import util.user.UserRule;
import static com.codeborne.selenide.Condition.hasText;
import static com.codeborne.selenide.Selenide.$;
@Rule
public Navigation nav = Navigation.get(ORCHESTRATOR);
+ @Rule
+ public UserRule userRule = UserRule.from(ORCHESTRATOR);
+
private static WsClient wsClient;
private long customLinkId;
+ private String adminUser;
@BeforeClass
public static void setUp() {
@Before
public void prepare() {
customLinkId = Long.parseLong(createCustomLink().getLink().getId());
+ adminUser = userRule.createAdminUser();
}
@After
}
private ProjectLinksPage openPage() {
- nav.logIn().submitCredentials("admin", "admin");
+ nav.logIn().submitCredentials(adminUser, adminUser);
return nav.openProjectLinks("sample");
}
}
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
import it.Category1Suite;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import pageobjects.Navigation;
import pageobjects.ProjectPermissionsPage;
+import util.user.UserRule;
import static util.ItUtils.projectDir;
import static util.selenium.Selenese.runSelenese;
@ClassRule
public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
+
@Rule
public Navigation nav = Navigation.get(orchestrator);
+ private String adminUser;
@BeforeClass
public static void beforeClass() {
executeBuild("project-permissions-project-2", "Another Test Project");
}
+ @Before
+ public void before() {
+ adminUser = userRule.createAdminUser();
+ }
+
@Test
public void test_project_permissions_page_shows_only_single_project() throws Exception {
runSelenese(orchestrator, "/projectAdministration/ProjectPermissionsTest/test_project_permissions_page_shows_only_single_project.html");
@Test
public void change_project_visibility() {
- ProjectPermissionsPage page = nav.logIn().asAdmin().openProjectPermissions("project-permissions-project");
+ ProjectPermissionsPage page = nav.logIn().submitCredentials(adminUser).openProjectPermissions("project-permissions-project");
page
.shouldBePublic()
.turnToPrivate()
import pageobjects.Navigation;
import pageobjects.ProjectActivityPage;
import pageobjects.ProjectAnalysisItem;
+import util.user.UserRule;
import static util.ItUtils.projectDir;
@ClassRule
public static Orchestrator ORCHESTRATOR = Category4Suite.ORCHESTRATOR;
+ @Rule
+ public UserRule userRule = UserRule.from(ORCHESTRATOR);
+
@Rule
public Navigation nav = Navigation.get(ORCHESTRATOR);
}
private ProjectActivityPage openPage() {
- nav.logIn().submitCredentials("admin", "admin");
+ String userAdmin = userRule.createAdminUser();
+ nav.logIn().submitCredentials(userAdmin, userAdmin);
return nav.openProjectActivity("sample");
}
analyzeProject(projectKey1, "shared/xoo-sample", null);
// Check the facets and project cards
- ProjectsPage page = nav.logIn().asAdmin().openProjects(organization.getKey());
+ ProjectsPage page = nav.openProjects(organization.getKey());
page.changePerspective("Leak");
assertThat(url()).endsWith("/projects?view=leak");
page.shouldHaveTotal(2);
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
import it.Category1Suite;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.sonarqube.ws.client.WsClient;
import pageobjects.Navigation;
import pageobjects.projects.ProjectsPage;
+import util.user.UserRule;
import static com.codeborne.selenide.WebDriverRunner.url;
import static org.assertj.core.api.Assertions.assertThat;
-import static util.ItUtils.newAdminWsClient;
+import static util.ItUtils.newUserWsClient;
import static util.ItUtils.projectDir;
public class ProjectsPageTest {
@ClassRule
public static Orchestrator ORCHESTRATOR = Category1Suite.ORCHESTRATOR;
+ @Rule
+ public UserRule userRule = UserRule.from(ORCHESTRATOR);
+
@Rule
public Navigation nav = Navigation.get(ORCHESTRATOR);
- private static WsClient wsClient;
private static final String PROJECT_KEY = "key-foo";
+ private WsClient userAdminWsClient;
+ private String adminUser;
@BeforeClass
public static void setUp() {
- wsClient = newAdminWsClient(ORCHESTRATOR);
ORCHESTRATOR.resetData();
ORCHESTRATOR.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")).setProjectKey(PROJECT_KEY));
ORCHESTRATOR.executeBuild(SonarScanner.create(projectDir("duplications/file-duplications")).setProjectKey("key-bar"));
}
+ @Before
+ public void before() {
+ adminUser = userRule.createAdminUser();
+ userAdminWsClient = newUserWsClient(ORCHESTRATOR, adminUser, adminUser);
+ }
+
@Test
public void should_display_projects() {
ProjectsPage page = nav.openProjects();
page.shouldHaveTotal(2).shouldDisplayAllProjectsWidthSort("-analysis_date");
// all projects by default for logged in user
- page = nav.logIn().asAdmin().openProjects();
+ page = nav.logIn().submitCredentials(adminUser).openProjects();
page.shouldHaveTotal(2).shouldDisplayAllProjects();
// favorite one project
- wsClient.favorites().add(PROJECT_KEY);
+ userAdminWsClient.favorites().add(PROJECT_KEY);
page = nav.openProjects();
page.shouldHaveTotal(1).shouldDisplayFavoriteProjects();
// un-favorite this project
- wsClient.favorites().remove(PROJECT_KEY);
+ userAdminWsClient.favorites().remove(PROJECT_KEY);
page = nav.openProjects();
page.shouldHaveTotal(2).shouldDisplayAllProjects();
@Test
public void should_add_tag_to_facet() {
// Add some tags to this project
- wsClient.wsConnector().call(
+ userAdminWsClient.wsConnector().call(
new PostRequest("api/project_tags/set")
.setParam("project", PROJECT_KEY)
- .setParam("tags", "aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,zz")
- );
+ .setParam("tags", "aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,zz"));
ProjectsPage page = nav.openProjects();
page.getFacetByProperty("tags")
@Test
public void should_switch_between_perspectives() {
- ProjectsPage page = nav.logIn().asAdmin().openProjects();
+ ProjectsPage page = nav.logIn().submitCredentials(adminUser).openProjects();
page.changePerspective("Risk");
assertThat(url()).endsWith("/projects?view=visualizations&visualization=risk");
page.changePerspective("Leak");
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsClient;
-import org.sonarqube.ws.client.organization.CreateWsRequest;
import pageobjects.Navigation;
import util.OrganizationRule;
+import util.user.UserRule;
import static com.codeborne.selenide.Selenide.$;
import static util.ItUtils.newAdminWsClient;
public class OrganizationQualityProfilesUiTest {
+ private final static String ROOT_USER = "root-user";
+
private static WsClient adminWsClient;
@ClassRule
public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
-
@Rule
public OrganizationRule organizationRule = new OrganizationRule(orchestrator);
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
private static Organizations.Organization organization;
@Before
public void setUp() {
adminWsClient = newAdminWsClient(orchestrator);
- organization = adminWsClient.organizations().create(new CreateWsRequest.Builder().setKey("test-org").setName("test-org").build()).getOrganization();
+ organization = organizationRule.create(o -> o.setKey("test-org").setName("test-org"));
+ userRule.createRootUser(ROOT_USER, ROOT_USER);
}
@Before
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsClient;
import pageobjects.Navigation;
+import util.user.UserRule;
import static com.codeborne.selenide.Selenide.$;
import static util.ItUtils.newAdminWsClient;
public class QualityProfilesUiTest {
+ private static final String ADMIN_USER_LOGIN = "admin-user";
+
@ClassRule
public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
+
private static WsClient adminWsClient;
@BeforeClass
orchestrator.resetData();
}
+ @Before
+ public void initAdminUser() throws Exception {
+ userRule.createAdminUser(ADMIN_USER_LOGIN, ADMIN_USER_LOGIN);
+ }
+
+ @After
+ public void deleteAdminUser() {
+ userRule.resetUsers();
+ }
+
@Before
public void createSampleProfile() {
createProfile("xoo", "sample");
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.json.simple.JSONValue;
+import org.junit.After;
+import org.junit.Before;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.ServerId.ShowWsResponse;
import pageobjects.Navigation;
import pageobjects.ServerIdPage;
import util.ItUtils;
+import util.user.UserRule;
import static org.apache.commons.lang.StringUtils.startsWithAny;
import static org.assertj.core.api.Assertions.assertThat;
public class ServerSystemTest {
+ private static final String ADMIN_USER_LOGIN = "admin-user";
+
@ClassRule
public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
+
+ @Before
+ public void initAdminUser() {
+ userRule.createAdminUser(ADMIN_USER_LOGIN, ADMIN_USER_LOGIN);
+ }
+
+ @After
+ public void deleteAdminUser() {
+ userRule.resetUsers();
+ }
+
@Test
public void get_sonarqube_version() {
Map<String, Object> json = callStatus();
@Test
public void generate_server_id() throws IOException {
- Navigation nav = Navigation.get(orchestrator).openHomepage().logIn().asAdmin();
+ Navigation nav = Navigation.get(orchestrator).openHomepage().logIn().submitCredentials(ADMIN_USER_LOGIN);
String validIpAddress = getValidIpAddress();
nav.openServerId()
import com.sonar.orchestrator.Orchestrator;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import pageobjects.Navigation;
import pageobjects.licenses.LicenseItem;
import pageobjects.licenses.LicensesPage;
+import util.user.UserRule;
import static com.codeborne.selenide.Condition.text;
import static org.assertj.core.api.Assertions.assertThat;
private static Orchestrator orchestrator;
private static WsClient wsClient;
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
+
@Rule
public Navigation nav = Navigation.get(orchestrator);
+ private String adminUser;
@BeforeClass
public static void start() {
}
}
+ @Before
+ public void before() {
+ adminUser = userRule.createAdminUser();
+ }
+
@Test
public void display_licenses() {
- LicensesPage page = nav.logIn().asAdmin().openLicenses();
+ LicensesPage page = nav.logIn().submitCredentials(adminUser).openLicenses();
page.getLicenses().shouldHaveSize(2);
page.getLicensesAsItems().get(0).getName().shouldHave(text("Typed property"));
public void change_licenses() {
String EXAMPLE_LICENSE = "TmFtZTogRGV2ZWxvcHBlcnMKUGx1Z2luOiBhdXRvY29udHJvbApFeHBpcmVzOiAyMDEyLTA0LTAxCktleTogNjI5N2MxMzEwYzg2NDZiZTE5MDU1MWE4ZmZmYzk1OTBmYzEyYTIyMgo=";
- LicensesPage page = nav.logIn().asAdmin().openLicenses();
+ LicensesPage page = nav.logIn().submitCredentials(adminUser).openLicenses();
LicenseItem licenseItem = page.getLicenseByKey("typed.license.secured");
licenseItem.setLicense(EXAMPLE_LICENSE);
import java.util.List;
import java.util.Map;
import org.junit.After;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.sonarqube.ws.client.setting.ValuesRequest;
import pageobjects.Navigation;
import pageobjects.settings.SettingsPage;
+import util.user.UserRule;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Arrays.asList;
@ClassRule
public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
+
@Rule
public Navigation nav = Navigation.get(orchestrator);
static SettingsService SETTINGS;
+ private String adminUser;
@BeforeClass
public static void initSettingsService() throws Exception {
SETTINGS = newAdminWsClient(orchestrator).settingsService();
}
+ @Before
+ public void before() {
+ adminUser = userRule.createAdminUser();
+ }
+
@After
public void reset_settings() throws Exception {
resetSettings(orchestrator, null, "sonar.demo", "sonar.autogenerated", "sonar.test.jira.servers");
@Test
public void support_property_sets() throws UnsupportedEncodingException {
- SettingsPage page = nav.logIn().asAdmin().openSettings(null).openCategory("DEV")
+ SettingsPage page = nav.logIn().submitCredentials(adminUser).openSettings(null).openCategory("DEV")
.assertSettingDisplayed("sonar.test.jira.servers");
page.getPropertySetInput("sonar.test.jira.servers")
@Test
public void support_property_sets_with_auto_generated_keys() throws UnsupportedEncodingException {
- SettingsPage page = nav.logIn().asAdmin().openSettings(null).openCategory("DEV")
+ SettingsPage page = nav.logIn().submitCredentials(adminUser).openSettings(null).openCategory("DEV")
.assertSettingDisplayed("sonar.autogenerated");
page.getPropertySetInput("sonar.autogenerated")
import org.junit.rules.ExpectedException;
import pageobjects.EncryptionPage;
import pageobjects.Navigation;
+import util.user.UserRule;
import static com.codeborne.selenide.Condition.visible;
import static org.assertj.core.api.Assertions.assertThat;
*/
public class SettingsTestRestartingOrchestrator {
- Orchestrator orchestrator;
-
@Rule
public ExpectedException thrown = ExpectedException.none();
+ private Orchestrator orchestrator;
+
+ private UserRule userRule;
+
@After
public void stop() {
if (orchestrator != null) {
+ userRule.resetUsers();
orchestrator.stop();
}
}
.addPlugin(pluginArtifact("license-plugin"))
.setServerProperty("sonar.secretKeyPath", secretKeyUrl.getFile())
.build();
- orchestrator.start();
+ startOrchestrator();
- Navigation nav = Navigation.get(orchestrator).openHomepage().logIn().asAdmin();
+ String adminUser = userRule.createAdminUser();
+ Navigation nav = Navigation.get(orchestrator).openHomepage().logIn().submitCredentials(adminUser);
nav.openSettings(null)
.assertMenuContains("General")
.addPlugin(xooPlugin())
.setServerProperty("sonar.deprecatedKey", "true")
.build();
- orchestrator.start();
+ startOrchestrator();
SonarScanner withDeprecatedKey = SonarScanner.create(projectDir("shared/xoo-sample"))
.setProperty("sonar.deprecatedKey", "true");
// should not fail
orchestrator.executeBuilds(withDeprecatedKey, withNewKey);
- Navigation.get(orchestrator).openHomepage().logIn().asAdmin().openSettings(null)
+ String adminUser = userRule.createAdminUser();
+ Navigation.get(orchestrator).openHomepage().logIn().submitCredentials(adminUser).openSettings(null)
.assertMenuContains("General")
.assertSettingDisplayed("sonar.newKey")
.assertSettingNotDisplayed("sonar.deprecatedKey");
}
+ private void startOrchestrator() {
+ orchestrator.start();
+ userRule = UserRule.from(orchestrator);
+ }
+
}
import com.codeborne.selenide.Condition;
import com.sonar.orchestrator.Orchestrator;
import it.Category6Suite;
+import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.ws.Organizations.Organization;
import pageobjects.Navigation;
import util.OrganizationRule;
+import util.user.UserRule;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.$;
private static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
private static OrganizationRule organizations = new OrganizationRule(orchestrator);
+ private static UserRule userRule = UserRule.from(orchestrator);
@ClassRule
public static TestRule chain = RuleChain.outerRule(orchestrator)
- .around(organizations);
+ .around(organizations)
+ .around(userRule);
@Rule
public Navigation nav = Navigation.get(orchestrator);
+ private String adminUser;
+
+ @Before
+ public void before() {
+ adminUser = userRule.createRootUser();
+ }
+
@Test
public void organization_page() {
Organization organization = organizations.create();
@Test
public void organization_admin_page() {
Organization organization = organizations.create();
- nav.logIn().asAdmin().open("/organizations/" + organization.getKey() + "/projects");
+ nav.logIn().submitCredentials(adminUser).open("/organizations/" + organization.getKey() + "/projects");
$("#context-navigation a.navbar-admin-link").click();
$(By.linkText("Organization Admin Page")).shouldBe(Condition.visible).click();
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
import it.Category4Suite;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.openqa.selenium.By;
import pageobjects.Navigation;
+import util.user.UserRule;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.$;
@ClassRule
public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
+
@Rule
public Navigation nav = Navigation.get(orchestrator);
+ private String adminUser;
@BeforeClass
public static void setUp() throws Exception {
orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));
}
+ @Before
+ public void before() {
+ adminUser = userRule.createAdminUser();
+ }
+
@Test
public void test_static_files() {
runSelenese(orchestrator, "/uiExtension/UiExtensionsTest/static-files.html");
@Test
public void global_admin_page() {
- nav.logIn().asAdmin().open("/about");
+ nav.logIn().submitCredentials(adminUser).open("/about");
$(".navbar-admin-link").click();
$("#settings-navigation-configuration").click();
@Test
public void project_admin_page() {
- nav.logIn().asAdmin().open("/dashboard?id=sample");
+ nav.logIn().submitCredentials(adminUser).open("/dashboard?id=sample");
$("#component-navigation-admin").click();
$(By.linkText("Project Admin Page")).click();
import com.sonar.orchestrator.Orchestrator;
import it.Category4Suite;
import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import static org.sonarqube.ws.client.WsRequest.Method.POST;
import static util.ItUtils.newAdminWsClient;
import static util.ItUtils.newWsClient;
+import static util.ItUtils.resetSettings;
import static util.ItUtils.setServerProperty;
public class ForceAuthenticationTest {
@ClassRule
public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
- @ClassRule
- public static UserRule userRule = UserRule.from(orchestrator);
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
@Rule
public Navigation nav = Navigation.get(orchestrator);
- static WsClient anonymousClient;
- static WsClient adminWsClient;
+ private static WsClient anonymousClient;
+ private static WsClient adminWsClient;
- @BeforeClass
- public static void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
userRule.resetUsers();
userRule.createUser(LOGIN, LOGIN);
setServerProperty(orchestrator, "sonar.forceAuthentication", "true");
@AfterClass
public static void tearDown() throws Exception {
- setServerProperty(orchestrator, "sonar.forceAuthentication", null);
+ resetSettings(orchestrator, null, "sonar.forceAuthentication");
}
@Test
@Test
public void redirect_to_login_page() {
+ String userAdmin = userRule.createAdminUser();
Navigation page = nav.openHomepage();
page.shouldBeRedirectToLogin();
- page.openLogin().submitCredentials("admin", "admin").shouldBeLoggedIn();
+ page.openLogin().submitCredentials(userAdmin, userAdmin).shouldBeLoggedIn();
page.logOut().shouldBeRedirectToLogin();
}
import it.Category4Suite;
import java.util.UUID;
import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.WsClientFactories;
import org.sonarqube.ws.client.WsResponse;
-import org.sonarqube.ws.client.permission.AddGroupWsRequest;
import org.sonarqube.ws.client.permission.AddUserWsRequest;
-import org.sonarqube.ws.client.permission.RemoveGroupWsRequest;
import org.sonarqube.ws.client.usertoken.GenerateWsRequest;
import org.sonarqube.ws.client.usertoken.RevokeWsRequest;
import org.sonarqube.ws.client.usertoken.SearchWsRequest;
public class LocalAuthenticationTest {
+ private static final String ADMIN_USER_LOGIN = "admin-user";
+
+ private static final String LOGIN = "george.orwell";
+
@ClassRule
public static Orchestrator ORCHESTRATOR = Category4Suite.ORCHESTRATOR;
- @ClassRule
- public static UserRule userRule = UserRule.from(ORCHESTRATOR);
+ @Rule
+ public UserRule userRule = UserRule.from(ORCHESTRATOR);
@Rule
public Navigation nav = Navigation.get(ORCHESTRATOR);
private static UserTokensService userTokensWsClient;
- private static final String LOGIN = "george.orwell";
-
- @BeforeClass
- public static void setUp() {
- ORCHESTRATOR.resetData();
-
+ @Before
+ public void setUp() {
adminWsClient = newAdminWsClient(ORCHESTRATOR);
userTokensWsClient = adminWsClient.userTokens();
addUserPermission(LOGIN, "admin");
userRule.createUser("simple-user", "password");
+ userRule.createAdminUser(ADMIN_USER_LOGIN, ADMIN_USER_LOGIN);
}
- @AfterClass
- public static void deleteAndRestoreData() {
+ @After
+ public void deleteAndRestoreData() {
userRule.resetUsers();
}
.setPermission(permission));
}
- private static void removeGroupPermission(String groupName, String permission) {
- adminWsClient.permissions().removeGroup(new RemoveGroupWsRequest()
- .setGroupName(groupName)
- .setPermission(permission));
- }
-
- private static void addGroupPermission(String groupName, String permission) {
- adminWsClient.permissions().addGroup(new AddGroupWsRequest()
- .setGroupName(groupName)
- .setPermission(permission));
- }
}
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsClient;
import pageobjects.Navigation;
+import util.user.UserRule;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Condition.visible;
public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
private static WsClient adminWsClient;
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
+
@Rule
public Navigation nav = Navigation.get(orchestrator);
+ private String adminUser;
@BeforeClass
public static void setUp() {
@Before
public void initUser() {
+ adminUser = userRule.createAdminUser();
createUser("account-user", "User With Account", "user@example.com");
}
@Test
public void notifications() {
- nav.logIn().asAdmin().openNotifications()
+ nav.logIn().submitCredentials(adminUser).openNotifications()
.addGlobalNotification("ChangesOnMyIssue")
.addGlobalNotification("NewIssues")
.removeGlobalNotification("ChangesOnMyIssue");
import static util.ItUtils.newAdminWsClient;
import static util.ItUtils.newUserWsClient;
import static util.ItUtils.pluginArtifact;
+import static util.ItUtils.resetSettings;
import static util.ItUtils.setServerProperty;
import static util.selenium.Selenese.runSelenese;
*/
public class RealmAuthenticationTest {
+ private static final String TECH_USER = "techUser";
+ private static final String USER_LOGIN = "tester";
+ private static final String ADMIN_USER_LOGIN = "admin-user";
+
@Rule
public ExpectedException thrown = ExpectedException.none();
- static final String TECH_USER = "techUser";
- static final String USER_LOGIN = "tester";
-
/**
* Property from security-plugin for user management.
*/
.setServerProperty("sonar.security.realm", "FakeRealm")
.build();
- @ClassRule
- public static UserRule USER_RULE = UserRule.from(orchestrator);
+ @Rule
+ public UserRule userRule = UserRule.from(orchestrator);
@Before
@After
public void resetData() throws Exception {
- setServerProperty(orchestrator, USERS_PROPERTY, null);
- setServerProperty(orchestrator, "sonar.security.updateUserAttributes", null);
- USER_RULE.resetUsers();
+ resetSettings(orchestrator, null, USERS_PROPERTY, "sonar.security.updateUserAttributes");
+ }
+
+ @Before
+ public void initAdminUser() throws Exception {
+ userRule.createAdminUser(ADMIN_USER_LOGIN, ADMIN_USER_LOGIN);
+ }
+
+ @After
+ public void deleteAdminUser() {
+ userRule.resetUsers();
}
/**
USER_LOGIN + ".email", "tester@example.org"));
verifyAuthenticationIsOk(USER_LOGIN, "123");
- assertThat(USER_RULE.getUserByLogin(USER_LOGIN).get())
+ assertThat(userRule.getUserByLogin(USER_LOGIN).get())
.extracting(Users.User::isLocal, Users.User::getExternalIdentity, Users.User::getExternalProvider)
.containsOnly(false, USER_LOGIN, "sonarqube");
}
$("#login_form").should(Condition.exist);
}
- public Navigation submitCredentials(String login, String password) {
- return submitCredentials(login, password, Navigation.class);
+ public Navigation submitCredentials(String login) {
+ return submitCredentials(login, login, Navigation.class);
}
- public Navigation asAdmin() {
- return submitCredentials("admin", "admin");
+ public Navigation submitCredentials(String login, String password) {
+ return submitCredentials(login, password, Navigation.class);
}
public Navigation useOAuth2() {
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.WsResponse;
+import org.sonarqube.ws.client.permission.AddUserWsRequest;
import org.sonarqube.ws.client.user.CreateRequest;
import org.sonarqube.ws.client.user.SearchRequest;
import org.sonarqube.ws.client.user.UsersService;
import static java.util.Arrays.asList;
import static java.util.Arrays.stream;
import static java.util.Objects.requireNonNull;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.guava.api.Assertions.assertThat;
import static util.ItUtils.newAdminWsClient;
return user;
}
+ /**
+ * Create a new admin user with random login, having password same as login
+ */
+ public String createAdminUser() {
+ String login = randomAlphabetic(10).toLowerCase();
+ return createAdminUser(login, login);
+ }
+
+ public String createAdminUser(String login, String password) {
+ createUser(login, password);
+ adminWsClient.permissions().addUser(new AddUserWsRequest().setLogin(login).setPermission("admin"));
+ adminWsClient.userGroups().addUser(org.sonarqube.ws.client.usergroup.AddUserWsRequest.builder().setLogin(login).setName("sonar-administrators").build());
+ return login;
+ }
+
+ /**
+ * Create a new root user with random login, having password same as login
+ */
+ public String createRootUser() {
+ String login = randomAlphabetic(10).toLowerCase();
+ return createRootUser(login, login);
+ }
+
+ public String createRootUser(String login, String password) {
+ createUser(login, password);
+ setRoot(login);
+ return login;
+ }
+
public void setRoot(String login) {
adminWsClient().rootService().setRoot(login);
}
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
</tr>
<tr>
<td>waitForElementPresent</td>
- <td>css=[data-login=admin]</td>
+ <td>css=[data-login=admin-user]</td>
<td></td>
</tr>
<tr>
<td>click</td>
- <td>css=[data-login=admin] .js-user-change-password</td>
+ <td>css=[data-login=admin-user] .js-user-change-password</td>
<td></td>
</tr>
<tr>
<tr>
<td>type</td>
<td>id=change-user-password-old-password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>id=change-user-password-password</td>
- <td>admin</td>
+ <td>new-admin-user</td>
</tr>
<tr>
<td>type</td>
<td>id=change-user-password-password-confirmation</td>
- <td>admin</td>
+ <td>new-admin-user</td>
</tr>
<tr>
<td>click</td>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<table cellpadding="1" cellspacing="1" border="1">
<tbody>
<tr>
- <td>open</td>
- <td>/sessions/logout</td>
- <td></td>
-</tr>
-<tr>
- <td>open</td>
- <td>/sessions/new</td>
- <td></td>
-</tr>
-<tr>
- <td>type</td>
- <td>login</td>
- <td>admin</td>
-</tr>
-<tr>
- <td>type</td>
- <td>password</td>
- <td>admin</td>
-</tr>
-<tr>
- <td>clickAndWait</td>
- <td>commit</td>
- <td></td>
-</tr>
-<tr>
- <td>open</td>
- <td>/permission_templates</td>
- <td></td>
-</tr>
-<tr>
- <td>waitForElementPresent</td>
- <td>css=.page-actions button</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>css=.page-actions button</td>
- <td></td>
-</tr>
-<tr>
- <td>waitForElementPresent</td>
- <td>css=#permission-template-name</td>
- <td></td>
-</tr>
-<tr>
- <td>type</td>
- <td>css=#permission-template-name</td>
- <td>Custom</td>
-</tr>
-<tr>
- <td>type</td>
- <td>css=#permission-template-description</td>
- <td>Description</td>
-</tr>
-<tr>
- <td>type</td>
- <td>css=#permission-template-project-key-pattern</td>
- <td>.*</td>
-</tr>
-<tr>
- <td>click</td>
- <td>css=#permission-template-submit</td>
- <td></td>
-</tr>
-<tr>
- <td>waitForElementPresent</td>
- <td>css=tr[data-name="Custom"]</td>
- <td></td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>css=tr[data-name="Custom"] .js-name</td>
- <td>*Custom*</td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>css=tr[data-name="Custom"] .js-description</td>
- <td>*Description*</td>
-</tr>
-<tr>
- <td>assertText</td>
- <td>css=tr[data-name="Custom"] .js-project-key-pattern</td>
- <td>*.*</td>
-</tr>
-</tbody>
+ <td>open</td>
+ <td>/sessions/logout</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>open</td>
+ <td>/sessions/new</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>type</td>
+ <td>password</td>
+ <td>root-user</td>
+ </tr>
+ <tr>
+ <td>type</td>
+ <td>login</td>
+ <td>root-user</td>
+ </tr>
+ <tr>
+ <td>clickAndWait</td>
+ <td>name=commit</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>open</td>
+ <td>/permission_templates</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>waitForElementPresent</td>
+ <td>css=.page-actions button</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>click</td>
+ <td>css=.page-actions button</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>waitForElementPresent</td>
+ <td>css=#permission-template-name</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>type</td>
+ <td>css=#permission-template-name</td>
+ <td>Custom</td>
+ </tr>
+ <tr>
+ <td>type</td>
+ <td>css=#permission-template-description</td>
+ <td>Description</td>
+ </tr>
+ <tr>
+ <td>type</td>
+ <td>css=#permission-template-project-key-pattern</td>
+ <td>.*</td>
+ </tr>
+ <tr>
+ <td>click</td>
+ <td>css=#permission-template-submit</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>waitForElementPresent</td>
+ <td>css=tr[data-name="Custom"]</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>assertText</td>
+ <td>css=tr[data-name="Custom"] .js-name</td>
+ <td>*Custom*</td>
+ </tr>
+ <tr>
+ <td>assertText</td>
+ <td>css=tr[data-name="Custom"] .js-description</td>
+ <td>*Description*</td>
+ </tr>
+ <tr>
+ <td>assertText</td>
+ <td>css=tr[data-name="Custom"] .js-project-key-pattern</td>
+ <td>*.*</td>
+ </tr>
+ </tbody>
</table>
</body>
</html>
<table cellpadding="1" cellspacing="1" border="1">
<tbody>
<tr>
- <td>open</td>
- <td>/sessions/logout</td>
- <td></td>
-</tr>
-<tr>
- <td>open</td>
- <td>/sessions/new</td>
- <td></td>
-</tr>
-<tr>
- <td>type</td>
- <td>login</td>
- <td>admin</td>
-</tr>
-<tr>
- <td>type</td>
- <td>password</td>
- <td>admin</td>
-</tr>
-<tr>
- <td>clickAndWait</td>
- <td>commit</td>
- <td></td>
-</tr>
-<tr>
- <td>open</td>
- <td>/permission_templates</td>
- <td></td>
-</tr>
-<tr>
- <td>waitForElementPresent</td>
- <td>css=td[data-permission="user"]</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>css=td[data-permission="user"] .js-update-users</td>
- <td></td>
-</tr>
-<tr>
- <td>waitForElementPresent</td>
- <td>css=#grant-to-project-creators</td>
- <td></td>
-</tr>
-<tr>
- <td>assertElementPresent</td>
- <td>css=#grant-to-project-creators:not(:checked)</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>css=#grant-to-project-creators</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>css=.js-modal-close</td>
- <td></td>
-</tr>
-<tr>
- <td>waitForElementPresent</td>
- <td>css=td[data-permission="user"] .js-project-creators</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>css=td[data-permission="user"] .js-update-users</td>
- <td></td>
-</tr>
-<tr>
- <td>waitForElementPresent</td>
- <td>css=#grant-to-project-creators</td>
- <td></td>
-</tr>
-<tr>
- <td>assertElementPresent</td>
- <td>css=#grant-to-project-creators:checked</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>css=#grant-to-project-creators</td>
- <td></td>
-</tr>
-<tr>
- <td>click</td>
- <td>css=.js-modal-close</td>
- <td></td>
-</tr>
-<tr>
- <td>waitForElementNotPresent</td>
- <td>css=td[data-permission="user"] .js-project-creators</td>
- <td></td>
-</tr>
-</tbody>
+ <td>open</td>
+ <td>/sessions/logout</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>open</td>
+ <td>/sessions/new</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>type</td>
+ <td>password</td>
+ <td>admin-user</td>
+ </tr>
+ <tr>
+ <td>type</td>
+ <td>login</td>
+ <td>admin-user</td>
+ </tr>
+ <tr>
+ <td>clickAndWait</td>
+ <td>name=commit</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>open</td>
+ <td>/permission_templates</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>waitForElementPresent</td>
+ <td>css=td[data-permission="user"]</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>click</td>
+ <td>css=td[data-permission="user"] .js-update-users</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>waitForElementPresent</td>
+ <td>css=#grant-to-project-creators</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>assertElementPresent</td>
+ <td>css=#grant-to-project-creators:not(:checked)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>click</td>
+ <td>css=#grant-to-project-creators</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>click</td>
+ <td>css=.js-modal-close</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>waitForElementPresent</td>
+ <td>css=td[data-permission="user"] .js-project-creators</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>click</td>
+ <td>css=td[data-permission="user"] .js-update-users</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>waitForElementPresent</td>
+ <td>css=#grant-to-project-creators</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>assertElementPresent</td>
+ <td>css=#grant-to-project-creators:checked</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>click</td>
+ <td>css=#grant-to-project-creators</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>click</td>
+ <td>css=.js-modal-close</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>waitForElementNotPresent</td>
+ <td>css=td[data-permission="user"] .js-project-creators</td>
+ <td></td>
+ </tr>
+ </tbody>
</table>
</body>
</html>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>root-user</td>
</tr>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>root-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>root-user</td>
</tr>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>root-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>root-user</td>
</tr>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>root-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>root-user</td>
</tr>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>root-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>root-user</td>
</tr>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>root-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>root-user</td>
</tr>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>root-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>click</td>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>click</td>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>
<tr>
<td>type</td>
<td>login</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
- <td>admin</td>
+ <td>admin-user</td>
</tr>
<tr>
<td>clickAndWait</td>