use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class AccountIT method deletePreferredEmail.
@Test
public void deletePreferredEmail() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
String previous = gApi.accounts().self().get().email;
String email = "foo.bar.baz@example.com";
EmailInput input = new EmailInput();
input.email = email;
input.noConfirmation = true;
input.preferred = true;
gApi.accounts().self().addEmail(input);
// Account is reindexed twice; once on adding the new email,
// and then again on setting the email preferred.
accountIndexedCounter.assertReindexOf(admin, 2);
// The new preferred email is set
assertThat(gApi.accounts().self().get().email).isEqualTo(email);
accountIndexedCounter.clear();
gApi.accounts().self().deleteEmail(input.email);
accountIndexedCounter.assertReindexOf(admin);
requestScopeOperations.resetCurrentApiUser();
assertThat(getEmails()).containsExactly(previous);
assertThat(gApi.accounts().self().get().email).isNull();
}
}
use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class AccountIT method sshKeys.
@Test
@UseSsh
public void sshKeys() 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(), admin.email());
gApi.accounts().self().addSshKey(newKey);
info = gApi.accounts().self().listSshKeys();
assertThat(info).hasSize(2);
assertSequenceNumbers(info);
accountIndexedCounter.assertReindexOf(admin);
assertThat(sender.getMessages()).hasSize(1);
assertThat(sender.getMessages().get(0).body()).contains("new SSH keys have been added");
// Add an existing key (the request succeeds, but the key isn't added again)
sender.clear();
gApi.accounts().self().addSshKey(initial);
info = gApi.accounts().self().listSshKeys();
assertThat(info).hasSize(2);
assertSequenceNumbers(info);
accountIndexedCounter.assertNoReindex();
// TODO: Issue 10769: Adding an already existing key should not result in a notification email
assertThat(sender.getMessages()).hasSize(1);
assertThat(sender.getMessages().get(0).body()).contains("new SSH keys have been added");
// Add another new key
sender.clear();
String newKey2 = TestSshKeys.publicKey(SshSessionFactory.genSshKey(), admin.email());
gApi.accounts().self().addSshKey(newKey2);
info = gApi.accounts().self().listSshKeys();
assertThat(info).hasSize(3);
assertSequenceNumbers(info);
accountIndexedCounter.assertReindexOf(admin);
assertThat(sender.getMessages()).hasSize(1);
assertThat(sender.getMessages().get(0).body()).contains("new SSH keys have been added");
// Delete second key
sender.clear();
gApi.accounts().self().deleteSshKey(2);
info = gApi.accounts().self().listSshKeys();
assertThat(info).hasSize(2);
assertThat(info.get(0).seq).isEqualTo(1);
assertThat(info.get(1).seq).isEqualTo(3);
accountIndexedCounter.assertReindexOf(admin);
assertThat(sender.getMessages()).hasSize(1);
assertThat(sender.getMessages().get(0).body()).contains("SSH keys have been deleted");
// Mark first key as invalid
assertThat(info.get(0).valid).isTrue();
authorizedKeys.markKeyInvalid(admin.id(), 1);
info = gApi.accounts().self().listSshKeys();
assertThat(info).hasSize(2);
assertThat(info.get(0).seq).isEqualTo(1);
assertThat(info.get(0).valid).isFalse();
assertThat(info.get(1).seq).isEqualTo(3);
accountIndexedCounter.assertReindexOf(admin);
}
}
use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class AccountIT method reindexPermissions.
// reindex is tested by {@link AbstractQueryAccountsTest#reindex}
@Test
public void reindexPermissions() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
// admin can reindex any account
requestScopeOperations.setApiUser(admin.id());
gApi.accounts().id(user.username()).index();
accountIndexedCounter.assertReindexOf(user);
// user can reindex own account
requestScopeOperations.setApiUser(user.id());
gApi.accounts().self().index();
accountIndexedCounter.assertReindexOf(user);
// user cannot reindex any account
AuthException thrown = assertThrows(AuthException.class, () -> gApi.accounts().id(admin.username()).index());
assertThat(thrown).hasMessageThat().contains("modify account not permitted");
}
}
use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class AccountIT method addExternalIdEmail.
private void addExternalIdEmail(TestAccount account, String email) throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
requireNonNull(email);
accountsUpdateProvider.get().update("Add Email", account.id(), u -> u.addExternalId(externalIdFactory.createWithEmail(name("test"), email, account.id(), email)));
accountIndexedCounter.assertReindexOf(account);
requestScopeOperations.setApiUser(account.id());
}
}
use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.
the class AccountIT method shouldAllowQueryByEmailForInactiveUser.
@Test
public void shouldAllowQueryByEmailForInactiveUser() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
Account.Id activatableAccountId = accountOperations.newAccount().inactive().preferredEmail("foo@activatable.com").create();
accountIndexedCounter.assertReindexOf(activatableAccountId, 1);
}
gApi.changes().query("owner:foo@activatable.com").get();
}
Aggregations