use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class AccountsUpdate method createExternalIdNotes.
private ExternalIdNotes createExternalIdNotes(Repository allUsersRepo, Optional<ObjectId> rev, Account.Id accountId, AccountDelta update) throws IOException, ConfigInvalidException, DuplicateKeyException {
ExternalIdNotes.checkSameAccount(Iterables.concat(update.getCreatedExternalIds(), update.getUpdatedExternalIds(), update.getDeletedExternalIds()), accountId);
ExternalIdNotes extIdNotes = extIdNotesLoader.load(allUsersRepo, rev.orElse(ObjectId.zeroId()));
extIdNotes.replace(update.getDeletedExternalIds(), update.getCreatedExternalIds());
extIdNotes.upsert(update.getUpdatedExternalIds());
return extIdNotes;
}
use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class ExternalIdIT method shouldTolerateDuplicateExternalIdsWhenInMigrationMode.
@Test
@GerritConfig(name = "auth.userNameCaseInsensitive", value = "true")
@GerritConfig(name = "auth.userNameCaseInsensitiveMigrationMode", value = "true")
public void shouldTolerateDuplicateExternalIdsWhenInMigrationMode() throws Exception {
Account.Id firstAccountId = Account.id(1);
Account.Id secondAccountId = Account.id(2);
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
createExternalId(md, extIdNotes, SCHEME_GERRIT, "janedoe", firstAccountId, CASE_SENSITIVE_USERNAME);
createExternalId(md, extIdNotes, SCHEME_GERRIT, "JaneDoe", secondAccountId, CASE_SENSITIVE_USERNAME);
ExternalId.Key firstAccountExternalId = externalIdKeyFactory.create(SCHEME_GERRIT, "janedoe", CASE_INSENSITIVE_USERNAME);
assertThat(externalIds.get(firstAccountExternalId).get().accountId()).isEqualTo(firstAccountId);
ExternalId.Key secondAccountExternalId = externalIdKeyFactory.create(SCHEME_GERRIT, "JaneDoe", CASE_INSENSITIVE_USERNAME);
assertThat(externalIds.get(secondAccountExternalId).get().accountId()).isEqualTo(secondAccountId);
}
}
use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class ExternalIdIT method createCaseSensitiveExternalId_SchemeWithoutUsername.
@Test
@GerritConfig(name = "auth.userNameCaseInsensitive", value = "true")
public void createCaseSensitiveExternalId_SchemeWithoutUsername() throws Exception {
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
testCaseSensitiveExternalIdKey(md, extIdNotes, SCHEME_MAILTO, "Jane@doe.com", Account.id(66));
testCaseSensitiveExternalIdKey(md, extIdNotes, SCHEME_UUID, "1234ABCD", Account.id(66));
testCaseSensitiveExternalIdKey(md, extIdNotes, SCHEME_GPGKEY, "1234ABCD", Account.id(66));
}
}
use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class ExternalIdIT method insertExtIdForNonExistingAccount.
private void insertExtIdForNonExistingAccount(ExternalId extId) throws Exception {
// Cannot use AccountsUpdate to insert an external ID for a non-existing account.
try (Repository repo = repoManager.openRepository(allUsers);
MetaDataUpdate update = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(repo);
extIdNotes.insert(extId);
extIdNotes.commit(update);
externalIdNotesFactory.updateExternalIdCacheAndMaybeReindexAccounts(extIdNotes, ImmutableList.of());
}
}
use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.
the class ExternalIdIT method createCaseInsensitiveExternalId_DuplicateKey.
@Test
@GerritConfig(name = "auth.userNameCaseInsensitive", value = "true")
public void createCaseInsensitiveExternalId_DuplicateKey() throws Exception {
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
testCaseInsensitiveExternalIdKey(md, extIdNotes, SCHEME_USERNAME, "JohnDoe", Account.id(42));
assertThrows(DuplicateExternalIdKeyException.class, () -> extIdNotes.insert(externalIdFactory.create(SCHEME_USERNAME, "johndoe", Account.id(23))));
}
}
Aggregations