mirror of
https://github.com/google/nomulus
synced 2026-04-29 20:37:13 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user