From b96de0e32f7f9008e78bb5adf04ce9af694d567e Mon Sep 17 00:00:00 2001 From: Ben McIlwain Date: Thu, 14 Oct 2021 14:53:28 -0400 Subject: [PATCH] Add tests for obscure hostname canonicalization rule (#1388) Also correctly configures Gradle for the util subproject (it wasn't possible to run tests in IntelliJ without these changes). --- util/build.gradle | 8 +++++++ .../dependency-locks/testCompile.lockfile | 14 +++++++++++ .../testCompileClasspath.lockfile | 24 +++++++++++++++---- .../dependency-locks/testRuntime.lockfile | 14 +++++++++++ .../testRuntimeClasspath.lockfile | 14 +++++++++++ .../registry/util/DomainNameUtilsTest.java | 17 ++++++++++++- 6 files changed, 85 insertions(+), 6 deletions(-) diff --git a/util/build.gradle b/util/build.gradle index 4934b8d88..7f9fa8ee5 100644 --- a/util/build.gradle +++ b/util/build.gradle @@ -43,12 +43,16 @@ dependencies { testCompile deps['com.google.appengine:appengine-api-stubs'] testCompile deps['com.google.guava:guava-testlib'] testCompile deps['com.google.truth:truth'] + testCompile deps['junit:junit'] testCompile deps['org.junit.jupiter:junit-jupiter-api'] testCompile deps['org.junit.jupiter:junit-jupiter-engine'] + testCompile deps['org.junit.platform:junit-platform-runner'] + testCompile deps['org.junit.platform:junit-platform-suite-api'] testCompile deps['org.hamcrest:hamcrest'] testCompile deps['org.hamcrest:hamcrest-core'] testCompile deps['org.mockito:mockito-core'] testCompile deps['org.mockito:mockito-junit-jupiter'] + testCompile deps['org.testcontainers:junit-jupiter'] testCompile files("${rootDir}/third_party/objectify/v4_1/objectify-4.1.3.jar") testCompile project(path: ':common', configuration: 'testing') testRuntime deps['com.google.flogger:flogger-system-backend'] @@ -57,3 +61,7 @@ dependencies { testAnnotationProcessor deps['com.google.auto.value:auto-value'] testAnnotationProcessor deps['com.google.dagger:dagger-compiler'] } + +test { + useJUnitPlatform() +} diff --git a/util/gradle/dependency-locks/testCompile.lockfile b/util/gradle/dependency-locks/testCompile.lockfile index fe63b1e4b..5b9f31fa9 100644 --- a/util/gradle/dependency-locks/testCompile.lockfile +++ b/util/gradle/dependency-locks/testCompile.lockfile @@ -1,6 +1,10 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. +com.fasterxml.jackson.core:jackson-annotations:2.10.3 +com.github.docker-java:docker-java-api:3.2.7 +com.github.docker-java:docker-java-transport-zerodep:3.2.7 +com.github.docker-java:docker-java-transport:3.2.7 com.google.android:annotations:4.1.1.4 com.google.api-client:google-api-client:1.31.3 com.google.api.grpc:proto-google-cloud-tasks-v2:1.33.2 @@ -61,6 +65,8 @@ joda-time:joda-time:2.9.2 junit:junit:4.13.2 net.bytebuddy:byte-buddy-agent:1.10.19 net.bytebuddy:byte-buddy:1.10.19 +net.java.dev.jna:jna:5.5.0 +org.apache.commons:commons-compress:1.20 org.apache.httpcomponents:httpclient:4.5.13 org.apache.httpcomponents:httpcore:4.4.14 org.apiguardian:apiguardian-api:1.1.0 @@ -76,11 +82,19 @@ org.junit.jupiter:junit-jupiter-api:5.7.0 org.junit.jupiter:junit-jupiter-engine:5.7.0 org.junit.platform:junit-platform-commons:1.7.0 org.junit.platform:junit-platform-engine:1.7.0 +org.junit.platform:junit-platform-launcher:1.7.0 +org.junit.platform:junit-platform-runner:1.7.0 +org.junit.platform:junit-platform-suite-api:1.7.0 org.junit:junit-bom:5.7.0 org.mockito:mockito-core:3.7.7 org.mockito:mockito-junit-jupiter:3.7.7 org.objenesis:objenesis:3.1 org.opentest4j:opentest4j:1.2.0 org.ow2.asm:asm:9.0 +org.rnorth.duct-tape:duct-tape:1.0.8 +org.rnorth.visible-assertions:visible-assertions:2.1.2 +org.slf4j:slf4j-api:1.7.30 +org.testcontainers:junit-jupiter:1.15.2 +org.testcontainers:testcontainers:1.15.2 org.threeten:threetenbp:1.5.1 org.yaml:snakeyaml:1.17 diff --git a/util/gradle/dependency-locks/testCompileClasspath.lockfile b/util/gradle/dependency-locks/testCompileClasspath.lockfile index e8fd715b1..945587bed 100644 --- a/util/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/util/gradle/dependency-locks/testCompileClasspath.lockfile @@ -1,6 +1,10 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. +com.fasterxml.jackson.core:jackson-annotations:2.10.3 +com.github.docker-java:docker-java-api:3.2.7 +com.github.docker-java:docker-java-transport-zerodep:3.2.7 +com.github.docker-java:docker-java-transport:3.2.7 com.google.api-client:google-api-client:1.31.3 com.google.api.grpc:proto-google-cloud-tasks-v2:1.33.2 com.google.api.grpc:proto-google-cloud-tasks-v2beta2:0.89.2 @@ -58,6 +62,8 @@ joda-time:joda-time:2.9.2 junit:junit:4.13.2 net.bytebuddy:byte-buddy-agent:1.10.19 net.bytebuddy:byte-buddy:1.10.19 +net.java.dev.jna:jna:5.5.0 +org.apache.commons:commons-compress:1.20 org.apache.httpcomponents:httpclient:4.5.13 org.apache.httpcomponents:httpcore:4.4.14 org.apiguardian:apiguardian-api:1.1.0 @@ -68,15 +74,23 @@ org.checkerframework:checker-qual:3.9.1 org.conscrypt:conscrypt-openjdk-uber:2.5.1 org.hamcrest:hamcrest-core:2.2 org.hamcrest:hamcrest:2.2 -org.junit.jupiter:junit-jupiter-api:5.6.2 -org.junit.jupiter:junit-jupiter-engine:5.6.2 -org.junit.platform:junit-platform-commons:1.6.2 -org.junit.platform:junit-platform-engine:1.6.2 -org.junit:junit-bom:5.6.2 +org.junit.jupiter:junit-jupiter-api:5.7.0 +org.junit.jupiter:junit-jupiter-engine:5.7.0 +org.junit.platform:junit-platform-commons:1.7.0 +org.junit.platform:junit-platform-engine:1.7.0 +org.junit.platform:junit-platform-launcher:1.7.0 +org.junit.platform:junit-platform-runner:1.7.0 +org.junit.platform:junit-platform-suite-api:1.7.0 +org.junit:junit-bom:5.7.0 org.mockito:mockito-core:3.7.7 org.mockito:mockito-junit-jupiter:3.7.7 org.objenesis:objenesis:3.1 org.opentest4j:opentest4j:1.2.0 org.ow2.asm:asm:9.0 +org.rnorth.duct-tape:duct-tape:1.0.8 +org.rnorth.visible-assertions:visible-assertions:2.1.2 +org.slf4j:slf4j-api:1.7.30 +org.testcontainers:junit-jupiter:1.15.2 +org.testcontainers:testcontainers:1.15.2 org.threeten:threetenbp:1.5.1 org.yaml:snakeyaml:1.17 diff --git a/util/gradle/dependency-locks/testRuntime.lockfile b/util/gradle/dependency-locks/testRuntime.lockfile index e198885cd..ea9d9168c 100644 --- a/util/gradle/dependency-locks/testRuntime.lockfile +++ b/util/gradle/dependency-locks/testRuntime.lockfile @@ -1,6 +1,10 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. +com.fasterxml.jackson.core:jackson-annotations:2.10.3 +com.github.docker-java:docker-java-api:3.2.7 +com.github.docker-java:docker-java-transport-zerodep:3.2.7 +com.github.docker-java:docker-java-transport:3.2.7 com.google.android:annotations:4.1.1.4 com.google.api-client:google-api-client:1.31.3 com.google.api.grpc:proto-google-cloud-tasks-v2:1.33.2 @@ -63,6 +67,8 @@ joda-time:joda-time:2.9.2 junit:junit:4.13.2 net.bytebuddy:byte-buddy-agent:1.10.19 net.bytebuddy:byte-buddy:1.10.19 +net.java.dev.jna:jna:5.5.0 +org.apache.commons:commons-compress:1.20 org.apache.httpcomponents:httpclient:4.5.13 org.apache.httpcomponents:httpcore:4.4.14 org.apiguardian:apiguardian-api:1.1.0 @@ -78,11 +84,19 @@ org.junit.jupiter:junit-jupiter-api:5.7.0 org.junit.jupiter:junit-jupiter-engine:5.7.0 org.junit.platform:junit-platform-commons:1.7.0 org.junit.platform:junit-platform-engine:1.7.0 +org.junit.platform:junit-platform-launcher:1.7.0 +org.junit.platform:junit-platform-runner:1.7.0 +org.junit.platform:junit-platform-suite-api:1.7.0 org.junit:junit-bom:5.7.0 org.mockito:mockito-core:3.7.7 org.mockito:mockito-junit-jupiter:3.7.7 org.objenesis:objenesis:3.1 org.opentest4j:opentest4j:1.2.0 org.ow2.asm:asm:9.0 +org.rnorth.duct-tape:duct-tape:1.0.8 +org.rnorth.visible-assertions:visible-assertions:2.1.2 +org.slf4j:slf4j-api:1.7.30 +org.testcontainers:junit-jupiter:1.15.2 +org.testcontainers:testcontainers:1.15.2 org.threeten:threetenbp:1.5.1 org.yaml:snakeyaml:1.17 diff --git a/util/gradle/dependency-locks/testRuntimeClasspath.lockfile b/util/gradle/dependency-locks/testRuntimeClasspath.lockfile index e198885cd..ea9d9168c 100644 --- a/util/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/util/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -1,6 +1,10 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. +com.fasterxml.jackson.core:jackson-annotations:2.10.3 +com.github.docker-java:docker-java-api:3.2.7 +com.github.docker-java:docker-java-transport-zerodep:3.2.7 +com.github.docker-java:docker-java-transport:3.2.7 com.google.android:annotations:4.1.1.4 com.google.api-client:google-api-client:1.31.3 com.google.api.grpc:proto-google-cloud-tasks-v2:1.33.2 @@ -63,6 +67,8 @@ joda-time:joda-time:2.9.2 junit:junit:4.13.2 net.bytebuddy:byte-buddy-agent:1.10.19 net.bytebuddy:byte-buddy:1.10.19 +net.java.dev.jna:jna:5.5.0 +org.apache.commons:commons-compress:1.20 org.apache.httpcomponents:httpclient:4.5.13 org.apache.httpcomponents:httpcore:4.4.14 org.apiguardian:apiguardian-api:1.1.0 @@ -78,11 +84,19 @@ org.junit.jupiter:junit-jupiter-api:5.7.0 org.junit.jupiter:junit-jupiter-engine:5.7.0 org.junit.platform:junit-platform-commons:1.7.0 org.junit.platform:junit-platform-engine:1.7.0 +org.junit.platform:junit-platform-launcher:1.7.0 +org.junit.platform:junit-platform-runner:1.7.0 +org.junit.platform:junit-platform-suite-api:1.7.0 org.junit:junit-bom:5.7.0 org.mockito:mockito-core:3.7.7 org.mockito:mockito-junit-jupiter:3.7.7 org.objenesis:objenesis:3.1 org.opentest4j:opentest4j:1.2.0 org.ow2.asm:asm:9.0 +org.rnorth.duct-tape:duct-tape:1.0.8 +org.rnorth.visible-assertions:visible-assertions:2.1.2 +org.slf4j:slf4j-api:1.7.30 +org.testcontainers:junit-jupiter:1.15.2 +org.testcontainers:testcontainers:1.15.2 org.threeten:threetenbp:1.5.1 org.yaml:snakeyaml:1.17 diff --git a/util/src/test/java/google/registry/util/DomainNameUtilsTest.java b/util/src/test/java/google/registry/util/DomainNameUtilsTest.java index d562bccb1..e51bab700 100644 --- a/util/src/test/java/google/registry/util/DomainNameUtilsTest.java +++ b/util/src/test/java/google/registry/util/DomainNameUtilsTest.java @@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test; class DomainNameUtilsTest { @Test - void testCanonicalizeDomainName() { + void testCanonicalizeDomainName_succeeds() { assertThat(canonicalizeDomainName("foo")).isEqualTo("foo"); assertThat(canonicalizeDomainName("FOO")).isEqualTo("foo"); assertThat(canonicalizeDomainName("foo.tld")).isEqualTo("foo.tld"); @@ -38,6 +38,21 @@ class DomainNameUtilsTest { assertThat(canonicalizeDomainName("ħ")).isEqualTo("xn--1ea"); } + @Test + void testCanonicalizeDomainName_allowsRdnsNames() { + assertThat(canonicalizeDomainName("119.63.227.45-ns1.jhz-tt.uk")) + .isEqualTo("119.63.227.45-ns1.jhz-tt.uk"); + } + + @Test + void testCanonicalizeDomainName_throwsOn34HyphenRule() { + IllegalArgumentException thrown = + assertThrows( + IllegalArgumentException.class, + () -> canonicalizeDomainName("119.63.227.45--ns1.jhz-tt.uk")); + assertThat(thrown).hasCauseThat().hasMessageThat().contains("HYPHEN_3_4"); + } + @Test void testCanonicalizeDomainName_acePrefixUnicodeChars() { assertThrows(IllegalArgumentException.class, () -> canonicalizeDomainName("xn--みんな"));