Search in sources :

Example 1 with ExternalUser

use of com.google.gerrit.server.ExternalUser in project gerrit by GerritCodeReview.

the class ExternalUserPermissionIT method externalUser_isNotContainedInRegisteredUsersIfNotConfigured.

@GerritConfig(name = "groups.includeExternalUsersInRegisteredUsersGroup", value = "false")
@Test
public void externalUser_isNotContainedInRegisteredUsersIfNotConfigured() {
    ExternalUser user = createUserInGroup("1", "it-department");
    assertThat(user.getEffectiveGroups().contains(REGISTERED_USERS)).isFalse();
}
Also used : ExternalUser(com.google.gerrit.server.ExternalUser) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with ExternalUser

use of com.google.gerrit.server.ExternalUser in project gerrit by GerritCodeReview.

the class ExternalUserPermissionIT method defaultRefFilter_refVisibilityIsAgnosticOfProvidedGroups.

@Test
public void defaultRefFilter_refVisibilityIsAgnosticOfProvidedGroups() throws Exception {
    ExternalUser user = createUserInGroup("1", "it-department");
    // Check that refs/meta/config isn't visible by default
    assertThat(getVisibleRefNames(user)).containsExactly("HEAD", "refs/heads/master");
    // Grant access
    projectOperations.project(project).forUpdate().add(allow(Permission.READ).ref("refs/meta/config").group(EXTERNAL_GROUP)).update();
    // Check that refs/meta/config became visible
    assertThat(getVisibleRefNames(user)).containsExactly("HEAD", "refs/heads/master", "refs/meta/config");
}
Also used : ExternalUser(com.google.gerrit.server.ExternalUser) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with ExternalUser

use of com.google.gerrit.server.ExternalUser in project gerrit by GerritCodeReview.

the class ExternalUserPermissionIT method changeVisibility_changeOnBranchVisibleToAnonymousIsVisible.

@Test
public void changeVisibility_changeOnBranchVisibleToAnonymousIsVisible() throws Exception {
    Change.Id changeId = changeOperations.newChange().project(project).create();
    ExternalUser user = createUserInGroup("1", "it-department");
    permissionBackend.user(user).change(changeNotesFactory.create(project, changeId)).check(ChangePermission.READ);
}
Also used : ExternalUser(com.google.gerrit.server.ExternalUser) Change(com.google.gerrit.entities.Change) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with ExternalUser

use of com.google.gerrit.server.ExternalUser in project gerrit by GerritCodeReview.

the class ExternalUserPermissionIT method defaultRefFilter_changeVisibilityIsAgnosticOfProvidedGroups.

@Test
public void defaultRefFilter_changeVisibilityIsAgnosticOfProvidedGroups() throws Exception {
    ExternalUser user = createUserInGroup("1", "it-department");
    Change.Id changeOnMaster = changeOperations.newChange().project(project).create();
    Change.Id changeOnRefsMetaConfig = changeOperations.newChange().project(project).branch("refs/meta/config").create();
    // Check that only the change on the default branch is visible
    assertThat(getVisibleRefNames(user)).containsExactly("HEAD", "refs/heads/master", RefNames.changeMetaRef(changeOnMaster), RefNames.patchSetRef(PatchSet.id(changeOnMaster, 1)));
    // Grant access
    projectOperations.project(project).forUpdate().add(allow(Permission.READ).ref("refs/meta/config").group(EXTERNAL_GROUP)).update();
    // Check that both changes are visible now
    assertThat(getVisibleRefNames(user)).containsExactly("HEAD", "refs/heads/master", "refs/meta/config", RefNames.changeMetaRef(changeOnMaster), RefNames.patchSetRef(PatchSet.id(changeOnMaster, 1)), RefNames.changeMetaRef(changeOnRefsMetaConfig), RefNames.patchSetRef(PatchSet.id(changeOnRefsMetaConfig, 1)));
}
Also used : ExternalUser(com.google.gerrit.server.ExternalUser) Change(com.google.gerrit.entities.Change) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with ExternalUser

use of com.google.gerrit.server.ExternalUser in project gerrit by GerritCodeReview.

the class ExternalUserPermissionIT method changeVisibility_changeOnInvisibleBranchNotVisible.

@Test
public void changeVisibility_changeOnInvisibleBranchNotVisible() throws Exception {
    // Create a change that is not visible to members of 'externalGroup'
    Change.Id invisibleChange = changeOperations.newChange().project(project).branch("refs/meta/config").create();
    ExternalUser user = createUserInGroup("1", "it-department");
    AuthException thrown = assertThrows(AuthException.class, () -> permissionBackend.user(user).change(changeNotesFactory.create(project, invisibleChange)).check(ChangePermission.READ));
    assertThat(thrown).hasMessageThat().isEqualTo("read not permitted");
}
Also used : ExternalUser(com.google.gerrit.server.ExternalUser) AuthException(com.google.gerrit.extensions.restapi.AuthException) Change(com.google.gerrit.entities.Change) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)8 ExternalUser (com.google.gerrit.server.ExternalUser)8 Test (org.junit.Test)8 Change (com.google.gerrit.entities.Change)4 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)2 AccountGroup (com.google.gerrit.entities.AccountGroup)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1