use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class UniversalGroupBackendTest method otherMemberships.
@Test
public void otherMemberships() {
final AccountGroup.UUID handled = AccountGroup.uuid("handled");
final AccountGroup.UUID notHandled = AccountGroup.uuid("not handled");
final IdentifiedUser member = mock(IdentifiedUser.class);
final IdentifiedUser notMember = mock(IdentifiedUser.class);
GroupBackend backend = mock(GroupBackend.class);
when(backend.handles(eq(handled))).thenReturn(true);
when(backend.handles(not(eq(handled)))).thenReturn(false);
when(backend.membershipsOf(any(IdentifiedUser.class))).thenAnswer(new Answer<GroupMembership>() {
@Override
public GroupMembership answer(InvocationOnMock invocation) {
GroupMembership membership = mock(GroupMembership.class);
when(membership.contains(eq(handled))).thenReturn(invocation.getArguments()[0] == member);
when(membership.contains(eq(notHandled))).thenReturn(false);
return membership;
}
});
backends = new DynamicSet<>();
backends.add("gerrit", backend);
backend = new UniversalGroupBackend(new PluginSetContext<>(backends, PluginMetrics.DISABLED_INSTANCE));
GroupMembership checker = backend.membershipsOf(member);
assertFalse(checker.contains(REGISTERED_USERS));
assertFalse(checker.contains(OTHER_UUID));
assertTrue(checker.contains(handled));
assertFalse(checker.contains(notHandled));
checker = backend.membershipsOf(notMember);
assertFalse(checker.contains(handled));
assertFalse(checker.contains(notHandled));
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class CommitRewriterTest method fixRealUserFooterIdent.
@Test
public void fixRealUserFooterIdent() throws Exception {
Change c = newChange();
String realUserIdentToFix = getAccountIdentToFix(otherUser.getAccount());
ObjectId invalidUpdateCommit = writeUpdate(RefNames.changeMetaRef(c.getId()), getChangeUpdateBody(c, "Comment on behalf of user", "Real-user: " + realUserIdentToFix), getAuthorIdent(changeOwner.getAccount()));
IdentifiedUser impersonatedChangeOwner = this.userFactory.runAs(null, changeOwner.getAccountId(), requireNonNull(otherUser).getRealUser());
ChangeUpdate impersonatedChangeMessageUpdate = newUpdate(c, impersonatedChangeOwner);
impersonatedChangeMessageUpdate.setChangeMessage("Other comment on behalf of");
impersonatedChangeMessageUpdate.commit();
Ref metaRefBeforeRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
ImmutableList<RevCommit> commitsBeforeRewrite = logMetaRef(repo, metaRefBeforeRewrite);
int invalidCommitIndex = commitsBeforeRewrite.indexOf(invalidUpdateCommit);
ChangeNotes notesBeforeRewrite = newNotes(c);
RunOptions options = new RunOptions();
options.dryRun = false;
BackfillResult result = rewriter.backfillProject(project, repo, options);
assertThat(result.fixedRefDiff.keySet()).containsExactly(RefNames.changeMetaRef(c.getId()));
ChangeNotes notesAfterRewrite = newNotes(c);
assertThat(changeMessages(notesBeforeRewrite)).containsExactly("Comment on behalf of user", "Other comment on behalf of");
assertThat(notesBeforeRewrite.getChangeMessages().get(0).getAuthor()).isEqualTo(changeOwner.getAccountId());
assertThat(notesBeforeRewrite.getChangeMessages().get(0).getRealAuthor()).isEqualTo(otherUser.getAccountId());
assertThat(changeMessages(notesAfterRewrite)).containsExactly("Comment on behalf of user", "Other comment on behalf of");
assertThat(notesBeforeRewrite.getChangeMessages().get(0).getAuthor()).isEqualTo(changeOwner.getAccountId());
assertThat(notesBeforeRewrite.getChangeMessages().get(0).getRealAuthor()).isEqualTo(otherUser.getAccountId());
Ref metaRefAfterRewrite = repo.exactRef(RefNames.changeMetaRef(c.getId()));
assertThat(metaRefAfterRewrite.getObjectId()).isNotEqualTo(metaRefBeforeRewrite.getObjectId());
ImmutableList<RevCommit> commitsAfterRewrite = logMetaRef(repo, metaRefAfterRewrite);
assertValidCommits(commitsBeforeRewrite, commitsAfterRewrite, ImmutableList.of(invalidCommitIndex));
assertFixedCommits(ImmutableList.of(invalidUpdateCommit), result, c.getId());
List<String> commitHistoryDiff = commitHistoryDiff(result, c.getId());
assertThat(commitHistoryDiff).containsExactly("@@ -9 +9 @@\n" + "-Real-user: Other Account <2@gerrit>\n" + "+Real-user: Gerrit User 2 <2@gerrit>\n");
BackfillResult secondRunResult = rewriter.backfillProject(project, repo, options);
assertThat(secondRunResult.fixedRefDiff.keySet()).isEmpty();
assertThat(secondRunResult.refsFailedToFix).isEmpty();
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class GerritPublicKeyCheckerTest method checkWithValidKeyButWrongExpectedUserInChecker.
@Test
public void checkWithValidKeyButWrongExpectedUserInChecker() throws Exception {
// A---Bx
// \
// \---C---D
// \
// \---Ex
//
// The server ultimately trusts B and D.
// D and E trust C to be a valid introducer of depth 2.
IdentifiedUser userB = addUser("userB");
TestKey keyA = add(keyA(), user);
TestKey keyB = add(keyB(), userB);
add(keyC(), addUser("userC"));
add(keyD(), addUser("userD"));
add(keyE(), addUser("userE"));
// Checker for A, checking B.
PublicKeyChecker checkerA = checkerFactory.create(user, store);
assertProblems(checkerA.check(keyB.getPublicKey()), Status.BAD, "Key is expired", "Key must contain a valid certification for one of the following" + " identities:\n" + " gerrit:user\n" + " mailto:testa@example.com\n" + " testa@example.com\n" + " username:user");
// Checker for B, checking A.
PublicKeyChecker checkerB = checkerFactory.create(userB, store);
assertProblems(checkerB.check(keyA.getPublicKey()), Status.BAD, "Key must contain a valid certification for one of the following" + " identities:\n" + " gerrit:userB\n" + " mailto:testb@example.com\n" + " testb@example.com\n" + " username:userB");
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method insert.
protected Change insert(TestRepository<Repo> repo, ChangeInserter ins, @Nullable Account.Id owner, Instant createdOn) throws Exception {
Project.NameKey project = Project.nameKey(repo.getRepository().getDescription().getRepositoryName());
Account.Id ownerId = owner != null ? owner : userId;
IdentifiedUser user = userFactory.create(ownerId);
try (BatchUpdate bu = updateFactory.create(project, user, createdOn)) {
bu.insertChange(ins);
bu.execute();
return ins.getChange();
}
}
Aggregations