Merge "Fix removal of email/password on external ID update" into stable-2.15
This commit is contained in:
@@ -873,6 +873,29 @@ public class ExternalIdIT extends AbstractDaemonTest {
|
||||
assertThat(externalIds.byAccount(admin.id)).containsExactlyElementsIn(expectedExternalIds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsetEmail() throws Exception {
|
||||
ExternalId extId = ExternalId.createWithEmail("x", "1", user.id, "x@example.com");
|
||||
extIdsUpdate.create().insert(extId);
|
||||
|
||||
ExternalId extIdWithoutEmail = ExternalId.create("x", "1", user.id);
|
||||
extIdsUpdate.create().upsert(extIdWithoutEmail);
|
||||
|
||||
assertThat(externalIds.get(extId.key())).isEqualTo(extIdWithoutEmail);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsetHttpPassword() throws Exception {
|
||||
ExternalId extId =
|
||||
ExternalId.createWithPassword(ExternalId.Key.create("y", "1"), user.id, null, "secret");
|
||||
extIdsUpdate.create().insert(extId);
|
||||
|
||||
ExternalId extIdWithoutPassword = ExternalId.create("y", "1", user.id);
|
||||
extIdsUpdate.create().upsert(extIdWithoutPassword);
|
||||
|
||||
assertThat(externalIds.get(extId.key())).isEqualTo(extIdWithoutPassword);
|
||||
}
|
||||
|
||||
private void insertExtIdBehindGerritsBack(ExternalId extId) throws Exception {
|
||||
try (Repository repo = repoManager.openRepository(allUsers);
|
||||
RevWalk rw = new RevWalk(repo);
|
||||
|
@@ -366,11 +366,17 @@ public abstract class ExternalId implements Serializable {
|
||||
// c.setString(...) ensures that account IDs are human readable.
|
||||
c.setString(
|
||||
EXTERNAL_ID_SECTION, externalIdKey, ACCOUNT_ID_KEY, Integer.toString(accountId().get()));
|
||||
|
||||
if (email() != null) {
|
||||
c.setString(EXTERNAL_ID_SECTION, externalIdKey, EMAIL_KEY, email());
|
||||
} else {
|
||||
c.unset(EXTERNAL_ID_SECTION, externalIdKey, EMAIL_KEY);
|
||||
}
|
||||
|
||||
if (password() != null) {
|
||||
c.setString(EXTERNAL_ID_SECTION, externalIdKey, PASSWORD_KEY, password());
|
||||
} else {
|
||||
c.unset(EXTERNAL_ID_SECTION, externalIdKey, PASSWORD_KEY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user