use of com.google.gerrit.server.account.AccountState in project gerrit by GerritCodeReview.
the class AccountManagerIT method cannotDeactivateAccountOnAuthenticationWhenAutoUpdateAccountActiveStatusIsDisabled.
@Test
public void cannotDeactivateAccountOnAuthenticationWhenAutoUpdateAccountActiveStatusIsDisabled() throws Exception {
String username = "foo";
Account.Id accountId = Account.id(seq.nextAccountId());
ExternalId.Key gerritExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_GERRIT, username);
accountsUpdate.insert("Create Test Account", accountId, u -> u.addExternalId(externalIdFactory.create(gerritExtIdKey, accountId)));
AuthRequest who = authRequestFactory.createForUser(username);
who.setActive(false);
who.setAuthProvidesAccountActiveStatus(true);
AuthResult authResult = accountManager.authenticate(who);
assertAuthResultForExistingAccount(authResult, accountId, gerritExtIdKey);
Optional<AccountState> accountState = accounts.get(accountId);
assertThat(accountState).isPresent();
assertThat(accountState.get().account().isActive()).isTrue();
}
use of com.google.gerrit.server.account.AccountState in project gerrit by GerritCodeReview.
the class AccountManagerIT method deactivateAccountOnAuthenticationWhenAutoUpdateAccountActiveStatusIsEnabled.
@Test
@GerritConfig(name = "auth.autoUpdateAccountActiveStatus", value = "true")
public void deactivateAccountOnAuthenticationWhenAutoUpdateAccountActiveStatusIsEnabled() throws Exception {
String username = "foo";
Account.Id accountId = Account.id(seq.nextAccountId());
ExternalId.Key gerritExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_GERRIT, username);
accountsUpdate.insert("Create Test Account", accountId, u -> u.addExternalId(externalIdFactory.create(gerritExtIdKey, accountId)));
AuthRequest who = authRequestFactory.createForUser(username);
who.setActive(false);
who.setAuthProvidesAccountActiveStatus(true);
AccountException thrown = assertThrows(AccountException.class, () -> accountManager.authenticate(who));
assertThat(thrown).hasMessageThat().isEqualTo("Authentication error, account inactive");
Optional<AccountState> accountState = accounts.get(accountId);
assertThat(accountState).isPresent();
assertThat(accountState.get().account().isActive()).isFalse();
}
use of com.google.gerrit.server.account.AccountState in project gerrit by GerritCodeReview.
the class FromAddressGeneratorProviderTest method user.
private Account.Id user(String name, String email) {
final AccountState s = makeUser(name, email);
when(accountCache.get(eq(s.account().id()))).thenReturn(Optional.of(s));
return s.account().id();
}
Aggregations