use of com.google.gerrit.extensions.api.accounts.EmailInput in project gerrit by GerritCodeReview.
the class AccountIT method deleteAllEmails.
@Test
@Sandboxed
public void deleteAllEmails() throws Exception {
EmailInput input = new EmailInput();
input.email = "foo.bar@example.com";
input.noConfirmation = true;
gApi.accounts().self().addEmail(input);
requestScopeOperations.resetCurrentApiUser();
Set<String> allEmails = getEmails();
assertThat(allEmails).hasSize(2);
for (String email : allEmails) {
gApi.accounts().self().deleteEmail(email);
}
requestScopeOperations.resetCurrentApiUser();
assertThat(getEmails()).isEmpty();
assertThat(gApi.accounts().self().get().email).isNull();
}
use of com.google.gerrit.extensions.api.accounts.EmailInput in project gerrit by GerritCodeReview.
the class AccountIT method addEmailAndSetPreferred.
@Test
public void addEmailAndSetPreferred() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
String email = "foo.bar@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);
String preferred = gApi.accounts().self().get().email;
assertThat(preferred).isEqualTo(email);
}
}
use of com.google.gerrit.extensions.api.accounts.EmailInput in project gerrit by GerritCodeReview.
the class AccountIT method deleteEmailOfOtherUser.
@Test
public void deleteEmailOfOtherUser() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
String email = "foo.bar@example.com";
EmailInput input = new EmailInput();
input.email = email;
input.noConfirmation = true;
gApi.accounts().id(user.id().get()).addEmail(input);
accountIndexedCounter.assertReindexOf(user);
requestScopeOperations.setApiUser(user.id());
assertThat(getEmails()).contains(email);
// admin can delete email of user
requestScopeOperations.setApiUser(admin.id());
gApi.accounts().id(user.id().get()).deleteEmail(email);
accountIndexedCounter.assertReindexOf(user);
requestScopeOperations.setApiUser(user.id());
assertThat(getEmails()).doesNotContain(email);
// user cannot delete email of admin
AuthException thrown = assertThrows(AuthException.class, () -> gApi.accounts().id(admin.id().get()).deleteEmail(admin.email()));
assertThat(thrown).hasMessageThat().contains("modify account not permitted");
}
}
use of com.google.gerrit.extensions.api.accounts.EmailInput in project gerrit by GerritCodeReview.
the class OutgoingEmailIT method messageIdHeaderFromAccountUpdate.
@Test
@GerritConfig(name = "auth.registerEmailPrivateKey", value = "HsOc6l_2lhS9G7sE_RsnS7Z6GJjdRDX14co=")
public void messageIdHeaderFromAccountUpdate() throws Exception {
Repository allUsersRepo = repoManager.openRepository(allUsers);
String email = "new.email@example.com";
EmailInput input = new EmailInput();
input.email = email;
sender.clear();
gApi.accounts().self().addEmail(input);
assertThat(sender.getMessages()).hasSize(1);
FakeEmailSender.Message m = sender.getMessages().get(0);
assertThat(m.rcpt()).containsExactly(Address.create(email));
assertThat(getMessageId(sender)).isEqualTo(withPrefixAndSuffixForMessageId(allUsersRepo.getRefDatabase().exactRef(RefNames.refsUsers(admin.id())).getObjectId().getName() + "-HTML"));
}
use of com.google.gerrit.extensions.api.accounts.EmailInput in project gerrit by GerritCodeReview.
the class SetAccountCommand method addEmail.
private void addEmail(String email) throws UnloggedFailure, RestApiException, IOException, ConfigInvalidException, PermissionBackendException {
EmailInput in = new EmailInput();
in.email = email;
in.noConfirmation = true;
try {
createEmail.apply(rsrc, IdString.fromDecoded(email), in);
} catch (EmailException e) {
throw die(e.getMessage());
}
}
Aggregations