Search in sources :

Example 91 with TestAccount

use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.

the class AccountIT method lookUpByPreferredEmail.

@Test
public void lookUpByPreferredEmail() throws Exception {
    // create an inconsistent account that has a preferred email without external ID
    String prefix = "foo.preferred";
    String prefEmail = prefix + "@example.com";
    TestAccount foo = accountCreator.create(name("foo"));
    accountsUpdateProvider.get().update("Set Preferred Email", foo.id(), u -> u.setPreferredEmail(prefEmail));
    // verify that the account is still found when using the preferred email to lookup the account
    ImmutableSet<Account.Id> accountsByPrefEmail = emails.getAccountFor(prefEmail);
    assertThat(accountsByPrefEmail).hasSize(1);
    assertThat(Iterables.getOnlyElement(accountsByPrefEmail)).isEqualTo(foo.id());
    // look up by email prefix doesn't find the account
    accountsByPrefEmail = emails.getAccountFor(prefix);
    assertThat(accountsByPrefEmail).isEmpty();
    // look up by other case doesn't find the account
    accountsByPrefEmail = emails.getAccountFor(prefEmail.toUpperCase(Locale.US));
    assertThat(accountsByPrefEmail).isEmpty();
}
Also used : PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ObjectId(org.eclipse.jgit.lib.ObjectId) TestKeys.validKeyWithSecondUserId(com.google.gerrit.gpg.testing.TestKeys.validKeyWithSecondUserId) TestAccount(com.google.gerrit.acceptance.TestAccount) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 92 with TestAccount

use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.

the class AccountIT method createByAccountCreator.

private Account.Id createByAccountCreator(int expectedAccountReindexCalls) throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        String name = "foo";
        TestAccount foo = accountCreator.create(name);
        AccountInfo info = gApi.accounts().id(foo.id().get()).get();
        assertThat(info.username).isEqualTo(name);
        assertThat(info.name).isEqualTo(name);
        accountIndexedCounter.assertReindexOf(foo, expectedAccountReindexCalls);
        assertUserBranch(foo.id(), name, null);
        return foo.id();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) TestAccount(com.google.gerrit.acceptance.TestAccount) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 93 with TestAccount

use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.

the class AccountIT method detailOfOtherAccountIncludeSecondaryEmailsWithModifyAccount.

@Test
public void detailOfOtherAccountIncludeSecondaryEmailsWithModifyAccount() throws Exception {
    String email = "preferred@example.com";
    TestAccount foo = accountCreator.create(name("foo"), email, "Foo", null);
    String secondaryEmail = "secondary@example.com";
    EmailInput input = newEmailInput(secondaryEmail);
    gApi.accounts().id(foo.id().get()).addEmail(input);
    AccountDetailInfo detail = gApi.accounts().id(foo.id().get()).detail();
    assertThat(detail.secondaryEmails).containsExactly(secondaryEmail);
}
Also used : AccountDetailInfo(com.google.gerrit.extensions.common.AccountDetailInfo) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) TestAccount(com.google.gerrit.acceptance.TestAccount) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 94 with TestAccount

use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.

the class AccountIT method detailOfOtherAccountDoesntIncludeSecondaryEmailsWithoutModifyAccount.

@Test
public void detailOfOtherAccountDoesntIncludeSecondaryEmailsWithoutModifyAccount() throws Exception {
    String email = "preferred@example.com";
    TestAccount foo = accountCreator.create(name("foo"), email, "Foo", null);
    String secondaryEmail = "secondary@example.com";
    EmailInput input = newEmailInput(secondaryEmail);
    gApi.accounts().id(foo.id().get()).addEmail(input);
    requestScopeOperations.setApiUser(user.id());
    AccountDetailInfo detail = gApi.accounts().id(foo.id().get()).detail();
    assertThat(detail.secondaryEmails).isNull();
}
Also used : AccountDetailInfo(com.google.gerrit.extensions.common.AccountDetailInfo) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) TestAccount(com.google.gerrit.acceptance.TestAccount) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 95 with TestAccount

use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.

the class AbstractSubmitOnPush method pushForSubmitWithNotifyingUsersExplicitly.

@Test
public void pushForSubmitWithNotifyingUsersExplicitly() throws Exception {
    projectOperations.project(project).forUpdate().add(allow(Permission.SUBMIT).ref("refs/for/refs/heads/master").group(adminGroupUuid())).update();
    TestAccount user = accountCreator.user1();
    String pushSpec = "refs/for/master%reviewer=" + user.email() + ",cc=" + user.email();
    TestAccount user2 = accountCreator.user2();
    sender.clear();
    PushOneCommit.Result result = pushTo(pushSpec + ",submit,notify=" + NotifyHandling.NONE + ",notify-to=" + user2.email());
    result.assertOkStatus();
    assertThatEmailsForChangeCreationAndSubmitWereSent(user2, RecipientType.TO);
    sender.clear();
    result = pushTo(pushSpec + ",submit,notify=" + NotifyHandling.NONE + ",notify-cc=" + user2.email());
    result.assertOkStatus();
    assertThatEmailsForChangeCreationAndSubmitWereSent(user2, RecipientType.CC);
    sender.clear();
    result = pushTo(pushSpec + ",submit,notify=" + NotifyHandling.NONE + ",notify-bcc=" + user2.email());
    result.assertOkStatus();
    assertThatEmailsForChangeCreationAndSubmitWereSent(user2, RecipientType.BCC);
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

TestAccount (com.google.gerrit.acceptance.TestAccount)137 Test (org.junit.Test)122 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)106 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)54 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)19 AbstractNotificationTest (com.google.gerrit.acceptance.AbstractNotificationTest)15 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)14 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)13 ArrayList (java.util.ArrayList)13 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)12 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)10 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)10 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)10 Message (com.google.gerrit.testing.FakeEmailSender.Message)10 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)9 EmailInput (com.google.gerrit.extensions.api.accounts.EmailInput)9 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)9 AuthException (com.google.gerrit.extensions.restapi.AuthException)9 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)8 Change (com.google.gerrit.entities.Change)8