Filter out empty dsData objects, not just null ones (#1449)

* Filter out empty dsData objects, not just null ones

Hibernate/SQL will get mad if the digest is null or empty, and
previously we only check for null. We should filter out empty digests as
well.
This commit is contained in:
gbrodman 2021-12-03 13:54:18 -05:00 committed by GitHub
parent 0ceebc1d8b
commit d663437cf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 2 deletions

View file

@ -170,7 +170,10 @@ public class DomainBase extends DomainContent
@Override
public void beforeSqlSaveOnReplay() {
fullyQualifiedDomainName = DomainNameUtils.canonicalizeDomainName(fullyQualifiedDomainName);
dsData = dsData.stream().filter(datum -> datum.getDigest() != null).collect(toImmutableSet());
dsData =
dsData.stream()
.filter(datum -> datum.getDigest() != null && datum.getDigest().length > 0)
.collect(toImmutableSet());
}
@Override

View file

@ -318,7 +318,7 @@ public class DomainHistory extends HistoryEntry implements SqlEntity {
domainHistory.nsHosts = nullToEmptyImmutableCopy(domainHistory.domainContent.nsHosts);
domainHistory.dsDataHistories =
nullToEmptyImmutableCopy(domainHistory.domainContent.getDsData()).stream()
.filter(dsData -> dsData.getDigest() != null)
.filter(dsData -> dsData.getDigest() != null && dsData.getDigest().length > 0)
.map(dsData -> DomainDsDataHistory.createFrom(domainHistory.id, dsData))
.collect(toImmutableSet());
domainHistory.gracePeriodHistories =

View file

@ -291,6 +291,37 @@ public class DomainHistoryTest extends EntityTestCase {
.isEqualTo("xn--kittyat-yxa.tld");
}
@TestSqlOnly
void testFillingHistory_missingDigest() {
createTld("tld");
DomainBase baseDomain = createDomainWithContactsAndHosts();
DomainBase domain =
baseDomain
.asBuilder()
.setDsData(
ImmutableSet.of(
DelegationSignerData.create(0, 1, 2, new byte[] {}, baseDomain.getRepoId()),
DelegationSignerData.create(3, 4, 5, null, baseDomain.getRepoId())))
.build();
DomainHistory domainHistory =
new DomainHistory.Builder()
.setDomainRepoId(domain.getRepoId())
.setRegistrarId(domain.getCurrentSponsorRegistrarId())
.setModificationTime(fakeClock.nowUtc())
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.build();
jpaTm()
.transact(
() -> {
domain.beforeSqlSaveOnReplay();
jpaTm().put(domain);
domainHistory.beforeSqlSaveOnReplay();
jpaTm().put(domainHistory);
});
assertThat(DatabaseHelper.loadByEntity(domain).getDsData()).isEmpty();
assertThat(DatabaseHelper.loadByEntity(domainHistory).getDsDataHistories()).isEmpty();
}
static DomainBase createDomainWithContactsAndHosts() {
createTld("tld");
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");