use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method putStatus.
@Test
public void putStatus() throws Exception {
List<String> statuses = ImmutableList.of("OOO", "Busy");
AccountInfo info;
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
for (String status : statuses) {
gApi.accounts().self().setStatus(status);
info = gApi.accounts().self().get();
assertUser(info, admin, status);
accountIndexedCounter.assertReindexOf(admin);
}
gApi.accounts().self().setStatus(null);
info = gApi.accounts().self().get();
assertUser(info, admin);
accountIndexedCounter.assertReindexOf(admin);
}
}
use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method deleteEmailFromCustomExternalIdSchemes.
@Test
public void deleteEmailFromCustomExternalIdSchemes() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
String email = "foo.bar@example.com";
String extId1 = "foo:bar";
String extId2 = "foo:baz";
accountsUpdateProvider.get().update("Add External IDs", admin.id(), u -> u.addExternalId(externalIdFactory.createWithEmail(externalIdKeyFactory.parse(extId1), admin.id(), email)).addExternalId(externalIdFactory.createWithEmail(externalIdKeyFactory.parse(extId2), admin.id(), email)));
accountIndexedCounter.assertReindexOf(admin);
assertThat(gApi.accounts().self().getExternalIds().stream().map(e -> e.identity).collect(toSet())).containsAtLeast(extId1, extId2);
requestScopeOperations.resetCurrentApiUser();
assertThat(getEmails()).contains(email);
gApi.accounts().self().deleteEmail(email);
accountIndexedCounter.assertReindexOf(admin);
requestScopeOperations.resetCurrentApiUser();
assertThat(getEmails()).doesNotContain(email);
assertThat(gApi.accounts().self().getExternalIds().stream().map(e -> e.identity).collect(toSet())).containsNoneOf(extId1, extId2);
}
}
use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method addInvalidEmail.
@Test
public void addInvalidEmail() throws Exception {
List<String> emails = ImmutableList.of(// Missing domain part
"new.email", // Missing domain part
"new.email@", // Missing user part
"@example.com", // Non-supported TLD (see tlds-alpha-by-domain.txt)
"new.email@example.africa");
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
for (String email : emails) {
EmailInput input = newEmailInput(email);
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.accounts().self().addEmail(input));
assertWithMessage(email).that(thrown).hasMessageThat().isEqualTo("invalid email address");
}
accountIndexedCounter.assertNoReindex();
}
}
use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method deleteEmail.
@Test
public void deleteEmail() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
String email = "foo.bar@example.com";
EmailInput input = newEmailInput(email);
gApi.accounts().self().addEmail(input);
requestScopeOperations.resetCurrentApiUser();
assertThat(getEmails()).contains(email);
accountIndexedCounter.clear();
gApi.accounts().self().deleteEmail(input.email);
accountIndexedCounter.assertReindexOf(admin);
requestScopeOperations.resetCurrentApiUser();
assertThat(getEmails()).doesNotContain(email);
}
}
use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method adminCanAddOrRemoveSshKeyOnOtherAccount.
@Test
@UseSsh
public void adminCanAddOrRemoveSshKeyOnOtherAccount() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
// The test account should initially have exactly one ssh key
List<SshKeyInfo> info = gApi.accounts().self().listSshKeys();
assertThat(info).hasSize(1);
assertSequenceNumbers(info);
SshKeyInfo key = info.get(0);
KeyPair keyPair = sshKeys.getKeyPair(admin);
String initial = TestSshKeys.publicKey(keyPair, admin.email());
assertThat(key.sshPublicKey).isEqualTo(initial);
accountIndexedCounter.assertNoReindex();
// Add a new key
sender.clear();
String newKey = TestSshKeys.publicKey(SshSessionFactory.genSshKey(), user.email());
gApi.accounts().id(user.username()).addSshKey(newKey);
info = gApi.accounts().id(user.username()).listSshKeys();
assertThat(info).hasSize(2);
assertSequenceNumbers(info);
accountIndexedCounter.assertReindexOf(user);
assertThat(sender.getMessages()).hasSize(1);
Message message = sender.getMessages().get(0);
assertThat(message.rcpt()).containsExactly(user.getNameEmail());
assertThat(message.body()).contains("new SSH keys have been added");
// Delete key
sender.clear();
gApi.accounts().id(user.username()).deleteSshKey(1);
info = gApi.accounts().id(user.username()).listSshKeys();
assertThat(info).hasSize(1);
accountIndexedCounter.assertReindexOf(user);
assertThat(sender.getMessages()).hasSize(1);
message = sender.getMessages().get(0);
assertThat(message.rcpt()).containsExactly(user.getNameEmail());
assertThat(message.body()).contains("SSH keys have been deleted");
}
}
Aggregations