Search in sources :

Example 6 with EmailInput

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();
}
Also used : PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) Sandboxed(com.google.gerrit.acceptance.Sandboxed)

Example 7 with EmailInput

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);
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 8 with EmailInput

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");
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AuthException(com.google.gerrit.extensions.restapi.AuthException) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 9 with EmailInput

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"));
}
Also used : Repository(org.eclipse.jgit.lib.Repository) FakeEmailSender(com.google.gerrit.testing.FakeEmailSender) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test)

Example 10 with EmailInput

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());
    }
}
Also used : EmailException(com.google.gerrit.exceptions.EmailException) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput)

Aggregations

EmailInput (com.google.gerrit.extensions.api.accounts.EmailInput)24 Test (org.junit.Test)19 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)18 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)16 TestAccount (com.google.gerrit.acceptance.TestAccount)9 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)7 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)7 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)4 AccountDetailInfo (com.google.gerrit.extensions.common.AccountDetailInfo)4 EmailInfo (com.google.gerrit.extensions.common.EmailInfo)3 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)3 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)3 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)2 Sandboxed (com.google.gerrit.acceptance.Sandboxed)2 EmailException (com.google.gerrit.exceptions.EmailException)2 StopStrategies (com.github.rholder.retry.StopStrategies)1 FluentIterable (com.google.common.collect.FluentIterable)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1