use of com.google.gerrit.server.account.AuthRequest in project gerrit by GerritCodeReview.
the class AccountManagerIT method allowLinkingExistingExternalIdEmailAsPreferred.
@Test
public void allowLinkingExistingExternalIdEmailAsPreferred() throws Exception {
String email = "foo@example.com";
// Create an account with an SCHEME_EXTERNAL external ID that occupies the email.
String username = "foo";
Account.Id accountId = Account.id(seq.nextAccountId());
ExternalId.Key externalExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_EXTERNAL, username);
accountsUpdate.insert("Create Test Account", accountId, u -> u.addExternalId(externalIdFactory.createWithEmail(externalExtIdKey, accountId, email)));
AuthRequest who = authRequestFactory.createForEmail(email);
AuthResult result = accountManager.link(accountId, who);
assertThat(result.isNew()).isFalse();
assertThat(result.getAccountId().get()).isEqualTo(accountId.get());
}
use of com.google.gerrit.server.account.AuthRequest in project gerrit by GerritCodeReview.
the class AccountManagerIT method authenticateNewAccountWithUsername.
@Test
public void authenticateNewAccountWithUsername() throws Exception {
String username = "foo";
ExternalId.Key gerritExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_GERRIT, username);
ExternalId.Key usernameExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_USERNAME, username);
assertNoSuchExternalIds(gerritExtIdKey, usernameExtIdKey);
AuthRequest who = authRequestFactory.createForUser(username);
AuthResult authResult = accountManager.authenticate(who);
assertAuthResultForNewAccount(authResult, gerritExtIdKey);
assertExternalIdsWithoutEmail(gerritExtIdKey, usernameExtIdKey);
}
use of com.google.gerrit.server.account.AuthRequest 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.AuthRequest in project gerrit by GerritCodeReview.
the class AccountManagerIT method authenticateNewAccountWithExternalUserAndEmail.
@Test
public void authenticateNewAccountWithExternalUserAndEmail() throws Exception {
String username = "foo";
ExternalId.Key externalExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_EXTERNAL, username);
ExternalId.Key usernameExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_USERNAME, username);
ExternalId.Key gerritExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_GERRIT, username);
assertNoSuchExternalIds(externalExtIdKey, usernameExtIdKey, gerritExtIdKey);
AuthRequest who = authRequestFactory.createForExternalUser(username);
String email = "foo@example.com";
who.setEmailAddress(email);
AuthResult authResult = accountManager.authenticate(who);
assertAuthResultForNewAccount(authResult, externalExtIdKey);
assertExternalId(externalExtIdKey, email);
assertExternalIdsWithoutEmail(usernameExtIdKey);
assertNoSuchExternalIds(gerritExtIdKey);
}
use of com.google.gerrit.server.account.AuthRequest in project gerrit by GerritCodeReview.
the class AccountManagerIT method cannotAuthenticateNewAccountWithEmailThatIsAlreadyUsed.
@Test
public void cannotAuthenticateNewAccountWithEmailThatIsAlreadyUsed() throws Exception {
String email = "foo@example.com";
// Create an account with an SCHEME_EXTERNAL external ID that occupies the email.
String username = "foo";
Account.Id accountId = Account.id(seq.nextAccountId());
ExternalId.Key externalExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_EXTERNAL, username);
accountsUpdate.insert("Create Test Account", accountId, u -> u.addExternalId(externalIdFactory.createWithEmail(externalExtIdKey, accountId, email)));
// Try to authenticate with this email to create a new account with a SCHEME_MAILTO external ID.
// Expect that this fails because the email is already assigned to the other account.
AuthRequest who = authRequestFactory.createForEmail(email);
AccountException thrown = assertThrows(AccountException.class, () -> accountManager.authenticate(who));
assertThat(thrown).hasMessageThat().contains("Email 'foo@example.com' in use by another account");
}
Aggregations