use of com.google.gerrit.server.account.AuthRequest in project gerrit by GerritCodeReview.
the class AccountManagerIT method cannotAuthenticateWithInactiveAccount.
@Test
public void cannotAuthenticateWithInactiveAccount() 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.setActive(false).addExternalId(externalIdFactory.create(gerritExtIdKey, accountId)));
AuthRequest who = authRequestFactory.createForUser(username);
AccountException thrown = assertThrows(AccountException.class, () -> accountManager.authenticate(who));
assertThat(thrown).hasMessageThat().contains("Authentication error, account inactive");
}
use of com.google.gerrit.server.account.AuthRequest in project gerrit by GerritCodeReview.
the class AccountManagerIT method authenticateWithUsernameAndUpdateDisplayName.
private void authenticateWithUsernameAndUpdateDisplayName(AccountManager am) throws Exception {
String username = "foo";
String email = "foo@example.com";
Account.Id accountId = Account.id(seq.nextAccountId());
ExternalId.Key gerritExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_GERRIT, username);
accountsUpdate.insert("Create Test Account", accountId, u -> u.setFullName("Initial Name").setPreferredEmail(email).addExternalId(externalIdFactory.createWithEmail(gerritExtIdKey, accountId, email)));
AuthRequest who = authRequestFactory.createForUser(username);
String newName = "Updated Name";
who.setDisplayName(newName);
AuthResult authResult = am.authenticate(who);
assertAuthResultForExistingAccount(authResult, accountId, gerritExtIdKey);
Optional<AccountState> accountState = accounts.get(accountId);
assertThat(accountState).isPresent();
assertThat(accountState.get().account().fullName()).isEqualTo(newName);
}
use of com.google.gerrit.server.account.AuthRequest in project gerrit by GerritCodeReview.
the class AccountManagerIT method authenticateWithUsername.
@Test
public void authenticateWithUsername() 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);
AuthResult authResult = accountManager.authenticate(who);
assertAuthResultForExistingAccount(authResult, accountId, gerritExtIdKey);
}
use of com.google.gerrit.server.account.AuthRequest in project gerrit by GerritCodeReview.
the class AccountManagerIT method authenticateWithExternalUser.
@Test
public void authenticateWithExternalUser() throws Exception {
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.create(externalExtIdKey, accountId)));
AuthRequest who = authRequestFactory.createForExternalUser(username);
AuthResult authResult = accountManager.authenticate(who);
assertAuthResultForExistingAccount(authResult, accountId, externalExtIdKey);
}
use of com.google.gerrit.server.account.AuthRequest in project gerrit by GerritCodeReview.
the class AccountManagerIT method cannotAuthenticateWithOrphanedExtId.
@Test
public void cannotAuthenticateWithOrphanedExtId() throws Exception {
String username = "foo";
ExternalId.Key gerritExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_GERRIT, username);
assertNoSuchExternalIds(gerritExtIdKey);
// Create orphaned SCHEME_GERRIT external ID.
Account.Id accountId = Account.id(seq.nextAccountId());
ExternalId gerritExtId = externalIdFactory.create(gerritExtIdKey, accountId);
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = extIdNotesFactory.load(allUsersRepo);
extIdNotes.insert(gerritExtId);
extIdNotes.commit(md);
}
AuthRequest who = authRequestFactory.createForUser(username);
AccountException thrown = assertThrows(AccountException.class, () -> accountManager.authenticate(who));
assertThat(thrown).hasMessageThat().contains("Authentication error, account not found");
}
Aggregations