Search in sources :

Example 1 with Result

use of com.google.gerrit.server.account.AccountResolver.Result in project gerrit by GerritCodeReview.

the class AccountResolverTest method shortCircuitAfterFilteringInactiveCandidatesResultsInEmptyList.

@Test
public void shortCircuitAfterFilteringInactiveCandidatesResultsInEmptyList() throws Exception {
    AccountState account1 = newAccount(1);
    AccountState account2 = newInactiveAccount(2);
    TestSearcher searcher1 = new TestSearcher("foo", true, account2);
    searcher1.setCallerShouldFilterOutInactiveCandidates();
    TestSearcher searcher2 = new TestSearcher("foo", false, account1, account2);
    ImmutableList<Searcher<?>> searchers = ImmutableList.of(searcher1, searcher2);
    // searcher1 matched and then filtered out all candidates because account2 is inactive, but
    // still short-circuited.
    Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
    assertThat(result.asIdSet()).isEmpty();
    assertThat(filteredInactiveIds(result)).containsExactlyElementsIn(ids(2));
}
Also used : Searcher(com.google.gerrit.server.account.AccountResolver.Searcher) StringSearcher(com.google.gerrit.server.account.AccountResolver.StringSearcher) Result(com.google.gerrit.server.account.AccountResolver.Result) Test(org.junit.Test)

Example 2 with Result

use of com.google.gerrit.server.account.AccountResolver.Result in project gerrit by GerritCodeReview.

the class AccountResolverTest method filterInactiveEventuallyFindingNoResults.

@Test
public void filterInactiveEventuallyFindingNoResults() throws Exception {
    TestSearcher searcher1 = new TestSearcher("foo", false, newInactiveAccount(1));
    searcher1.setCallerShouldFilterOutInactiveCandidates();
    TestSearcher searcher2 = new TestSearcher("f.*", false, newInactiveAccount(2));
    searcher2.setCallerShouldFilterOutInactiveCandidates();
    ImmutableList<Searcher<?>> searchers = ImmutableList.of(searcher1, searcher2);
    Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
    assertThat(result.asIdSet()).isEmpty();
    assertThat(filteredInactiveIds(result)).containsExactlyElementsIn(ids(1, 2));
}
Also used : Searcher(com.google.gerrit.server.account.AccountResolver.Searcher) StringSearcher(com.google.gerrit.server.account.AccountResolver.StringSearcher) Result(com.google.gerrit.server.account.AccountResolver.Result) Test(org.junit.Test)

Example 3 with Result

use of com.google.gerrit.server.account.AccountResolver.Result in project gerrit by GerritCodeReview.

the class AccountResolverTest method filterInactiveEventuallyFindingResults.

@Test
public void filterInactiveEventuallyFindingResults() throws Exception {
    TestSearcher searcher1 = new TestSearcher("foo", false, newInactiveAccount(1));
    searcher1.setCallerShouldFilterOutInactiveCandidates();
    TestSearcher searcher2 = new TestSearcher("f.*", false, newAccount(2));
    searcher2.setCallerShouldFilterOutInactiveCandidates();
    ImmutableList<Searcher<?>> searchers = ImmutableList.of(searcher1, searcher2);
    Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
    assertThat(search("foo", searchers, AccountResolverTest::allVisiblePredicate).asIdSet()).containsExactlyElementsIn(ids(2));
    // No info about inactive results exposed if there was at least one active result.
    assertThat(filteredInactiveIds(result)).isEmpty();
}
Also used : Searcher(com.google.gerrit.server.account.AccountResolver.Searcher) StringSearcher(com.google.gerrit.server.account.AccountResolver.StringSearcher) Result(com.google.gerrit.server.account.AccountResolver.Result) Test(org.junit.Test)

Example 4 with Result

use of com.google.gerrit.server.account.AccountResolver.Result in project gerrit by GerritCodeReview.

the class AccountResolverTest method dontShortCircuitAfterFilteringInactiveCandidatesResultsInEmptyList.

@Test
public void dontShortCircuitAfterFilteringInactiveCandidatesResultsInEmptyList() throws Exception {
    AccountState account1 = newAccount(1);
    AccountState account2 = newInactiveAccount(2);
    TestSearcher searcher1 = new TestSearcher("foo", false, account2);
    searcher1.setCallerShouldFilterOutInactiveCandidates();
    TestSearcher searcher2 = new TestSearcher("foo", false, account1, account2);
    ImmutableList<Searcher<?>> searchers = ImmutableList.of(searcher1, searcher2);
    // searcher1 matched, but filtered out all candidates because account2 is inactive. Actual
    // result came from searcher2 instead.
    Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
    assertThat(result.asIdSet()).containsExactlyElementsIn(ids(1, 2));
}
Also used : Searcher(com.google.gerrit.server.account.AccountResolver.Searcher) StringSearcher(com.google.gerrit.server.account.AccountResolver.StringSearcher) Result(com.google.gerrit.server.account.AccountResolver.Result) Test(org.junit.Test)

Example 5 with Result

use of com.google.gerrit.server.account.AccountResolver.Result in project gerrit by GerritCodeReview.

the class AccountResolverIT method bySelf.

@Test
public void bySelf() throws Exception {
    assertThat(resolve("Self")).isEmpty();
    accountOperations.newAccount().fullname("self").create();
    Result result = resolveAsResult("self");
    assertThat(result.asIdSet()).containsExactly(admin.id());
    assertThat(result.isSelf()).isTrue();
    assertThat(result.asUniqueUser()).isSameInstanceAs(self.get());
    result = resolveAsResult("me");
    assertThat(result.asIdSet()).containsExactly(admin.id());
    assertThat(result.isSelf()).isTrue();
    assertThat(result.asUniqueUser()).isSameInstanceAs(self.get());
    requestScopeOperations.setApiUserAnonymous();
    checkBySelfFails();
    requestScopeOperations.setApiUserInternal();
    checkBySelfFails();
}
Also used : Result(com.google.gerrit.server.account.AccountResolver.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

Result (com.google.gerrit.server.account.AccountResolver.Result)17 Test (org.junit.Test)16 Searcher (com.google.gerrit.server.account.AccountResolver.Searcher)8 StringSearcher (com.google.gerrit.server.account.AccountResolver.StringSearcher)8 UnresolvableAccountException (com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 TestAccount (com.google.gerrit.acceptance.testsuite.account.TestAccount)1 Account (com.google.gerrit.entities.Account)1