SetReviewersIT: Execute the test as both admin and regular user
The test was being executed as the admin user, which means the changes are always returned in the result without performing visibility checks. As a result, the tests had no coverage for the case where a regular user invokes the command, and thus the bug reported in issue 10764 was not discovered. Modify the test so that it executes the tests for both the admin user and the regular user. The tests run as regular user fail if the fix done in change I978277db0 is reverted. Bug: Issue 10764 Change-Id: I23181f0bc56d43eb7d5232a888329836faa45ba4
This commit is contained in:
		@@ -20,8 +20,11 @@ import com.google.common.collect.ImmutableSet;
 | 
			
		||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
 | 
			
		||||
import com.google.gerrit.acceptance.NoHttpd;
 | 
			
		||||
import com.google.gerrit.acceptance.PushOneCommit;
 | 
			
		||||
import com.google.gerrit.acceptance.SshSession;
 | 
			
		||||
import com.google.gerrit.acceptance.UseSsh;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Account.Id;
 | 
			
		||||
import com.google.gerrit.testing.ConfigSuite;
 | 
			
		||||
import org.eclipse.jgit.lib.Config;
 | 
			
		||||
import org.junit.Before;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
@@ -29,10 +32,20 @@ import org.junit.Test;
 | 
			
		||||
@NoHttpd
 | 
			
		||||
public class SetReviewersIT extends AbstractDaemonTest {
 | 
			
		||||
  PushOneCommit.Result change;
 | 
			
		||||
  SshSession session;
 | 
			
		||||
 | 
			
		||||
  @ConfigSuite.Config
 | 
			
		||||
  public static Config asAdmin() {
 | 
			
		||||
    Config cfg = new Config();
 | 
			
		||||
    cfg.setBoolean("SetReviewersIT", null, "asAdmin", true);
 | 
			
		||||
    return cfg;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Before
 | 
			
		||||
  public void setUp() throws Exception {
 | 
			
		||||
    change = createChange();
 | 
			
		||||
    session =
 | 
			
		||||
        cfg.getBoolean("SetReviewersIT", null, "asAdmin", false) ? adminSshSession : userSshSession;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
@@ -49,9 +62,8 @@ public class SetReviewersIT extends AbstractDaemonTest {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void setReviewer(boolean add, String id) throws Exception {
 | 
			
		||||
    adminSshSession.exec(
 | 
			
		||||
        String.format("gerrit set-reviewers -%s %s %s", add ? "a" : "r", user.email, id));
 | 
			
		||||
    adminSshSession.assertSuccess();
 | 
			
		||||
    session.exec(String.format("gerrit set-reviewers -%s %s %s", add ? "a" : "r", user.email, id));
 | 
			
		||||
    session.assertSuccess();
 | 
			
		||||
    ImmutableSet<Id> reviewers = change.getChange().getReviewers().all();
 | 
			
		||||
    if (add) {
 | 
			
		||||
      assertThat(reviewers).contains(user.id);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user