use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class ExternalIdIT method addExtId.
private void addExtId(TestRepository<?> testRepo, ExternalId... extIds) throws IOException, DuplicateKeyException, ConfigInvalidException {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(testRepo.getRepository());
extIdNotes.insert(Arrays.asList(extIds));
try (MetaDataUpdate metaDataUpdate = new MetaDataUpdate(GitReferenceUpdated.DISABLED, null, testRepo.getRepository())) {
metaDataUpdate.getCommitBuilder().setAuthor(admin.newIdent());
metaDataUpdate.getCommitBuilder().setCommitter(admin.newIdent());
extIdNotes.commit(metaDataUpdate);
externalIdNotesFactory.updateExternalIdCacheAndMaybeReindexAccounts(extIdNotes, ImmutableList.of());
}
}
use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class ExternalIdIT method insertExtIdBehindGerritsBack.
private void insertExtIdBehindGerritsBack(ExternalId extId) throws Exception {
try (Repository repo = repoManager.openRepository(allUsers)) {
// Inserting an external ID "behind Gerrit's back" means that the caches are not updated.
ExternalIdNotes extIdNotes = ExternalIdNotes.load(allUsers, repo, externalIdFactory, IS_USER_NAME_CASE_INSENSITIVE_MIGRATION_MODE);
extIdNotes.insert(extId);
try (MetaDataUpdate metaDataUpdate = new MetaDataUpdate(GitReferenceUpdated.DISABLED, null, repo)) {
metaDataUpdate.getCommitBuilder().setAuthor(admin.newIdent());
metaDataUpdate.getCommitBuilder().setCommitter(admin.newIdent());
extIdNotes.commit(metaDataUpdate);
}
}
}
use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class ExternalIdIT method unsetHttpPassword.
@Test
public void unsetHttpPassword() throws Exception {
ExternalId extId = externalIdFactory.createWithPassword(externalIdKeyFactory.create("y", "1"), user.id(), null, "secret");
insertExtId(extId);
ExternalId extIdWithoutPassword = externalIdFactory.create("y", "1", user.id());
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
extIdNotes.upsert(extIdWithoutPassword);
extIdNotes.commit(md);
assertThat(extIdNotes.get(extId.key())).hasValue(extIdWithoutPassword);
}
}
use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class ExternalIdNotesUpsertPreprocessorIT method insert.
@Test
public void insert() throws Exception {
Account.Id id = Account.id(sequences.nextAccountId());
ExternalId extId = extIdFactory.create("foo", "bar", id);
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = extIdNotesFactory.load(allUsersRepo);
extIdNotes.insert(extId);
extIdNotes.commit(md);
}
assertThat(testPreprocessor.upserted).containsExactly(extId);
}
use of com.google.gerrit.server.account.externalids.ExternalIdNotes 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