use of com.google.gerrit.server.notedb.ChangeNotesCommit in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method verifyNoAccountDetailsInChangeNotes.
/**
* Verify that NoteDB commits do not persist user-sensitive information, by running checks for all
* commits in {@link RefNames#changeMetaRef} for all changes, created during the test.
*
* <p>These tests prevent regression, assuming appropriate test coverage for new features. The
* verification is disabled by default and can be enabled using {@link VerifyNoPiiInChangeNotes}
* annotation either on test class or method.
*/
protected void verifyNoAccountDetailsInChangeNotes() throws RestApiException, IOException {
List<ChangeInfo> allChanges = gApi.changes().query().get();
List<AccountState> allAccounts = accounts.all();
for (ChangeInfo change : allChanges) {
try (Repository repo = repoManager.openRepository(Project.nameKey(change.project))) {
String metaRefName = RefNames.changeMetaRef(Change.Id.tryParse(change._number.toString()).get());
ObjectId metaTip = repo.getRefDatabase().exactRef(metaRefName).getObjectId();
ChangeNotesRevWalk revWalk = ChangeNotesCommit.newRevWalk(repo);
revWalk.reset();
revWalk.markStart(revWalk.parseCommit(metaTip));
ChangeNotesCommit commit;
while ((commit = revWalk.next()) != null) {
String fullMessage = commit.getFullMessage();
for (AccountState accountState : allAccounts) {
Account account = accountState.account();
assertThat(fullMessage).doesNotContain(account.getName());
if (account.fullName() != null) {
assertThat(fullMessage).doesNotContain(account.fullName());
}
if (account.displayName() != null) {
assertThat(fullMessage).doesNotContain(account.displayName());
}
if (account.preferredEmail() != null) {
assertThat(fullMessage).doesNotContain(account.preferredEmail());
}
if (accountState.userName().isPresent()) {
assertThat(fullMessage).doesNotContain(accountState.userName().get());
}
List<String> allEmails = accountState.externalIds().stream().map(ExternalId::email).filter(Objects::nonNull).collect(toImmutableList());
for (String email : allEmails) {
assertThat(fullMessage).doesNotContain(email);
}
}
}
}
}
}
Aggregations