mirror of
https://github.com/google/nomulus
synced 2026-08-19 05:36:11 +00:00
Reimplement the RDAP Json creation using Jsonables
Currently we try to reimplemnet the same behavior of the existing code as much as possible. We only fix issues that go against the RFC7483, but we don't yet update the code to follow the latest (15feb19) RDAP Response Profile. That will require a much bigger change especially for the test files, so it'll wait for a followup CL. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=246948018
This commit is contained in:
@@ -15,16 +15,13 @@
|
||||
package google.registry.rdap;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.TestDataHelper.loadFile;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.rdap.RdapMetrics.EndpointType;
|
||||
import google.registry.rdap.RdapMetrics.SearchType;
|
||||
import google.registry.rdap.RdapMetrics.WildcardType;
|
||||
import google.registry.rdap.RdapSearchResults.IncompletenessWarningType;
|
||||
import google.registry.request.Action;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Test;
|
||||
|
||||
/** Unit tests for {@link RdapHelpAction}. */
|
||||
@@ -34,44 +31,38 @@ public class RdapHelpActionTest extends RdapActionBaseTestCase<RdapHelpAction> {
|
||||
super(RdapHelpAction.class);
|
||||
}
|
||||
|
||||
private Object generateExpectedJson(String name, String expectedOutputFile) {
|
||||
return JSONValue.parse(
|
||||
loadFile(this.getClass(), expectedOutputFile, ImmutableMap.of("NAME", name)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHelpActionMaliciousPath_notFound() {
|
||||
assertThat(generateActualJson("../passwd")).isEqualTo(
|
||||
generateExpectedJson(
|
||||
"no help found for ../passwd", "rdap_error_404.json"));
|
||||
assertThat(generateActualJson("../passwd"))
|
||||
.isEqualTo(generateExpectedJsonError("no help found for ../passwd", 404));
|
||||
assertThat(response.getStatus()).isEqualTo(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHelpActionUnknownPath_notFound() {
|
||||
assertThat(generateActualJson("hlarg")).isEqualTo(
|
||||
generateExpectedJson("no help found for hlarg", "rdap_error_404.json"));
|
||||
generateExpectedJsonError("no help found for hlarg", 404));
|
||||
assertThat(response.getStatus()).isEqualTo(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHelpActionDefault_getsIndex() {
|
||||
assertThat(generateActualJson(""))
|
||||
.isEqualTo(generateExpectedJson("", "rdap_help_index.json"));
|
||||
.isEqualTo(loadJsonFile("rdap_help_index.json"));
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHelpActionSlash_getsIndex() {
|
||||
assertThat(generateActualJson("/"))
|
||||
.isEqualTo(generateExpectedJson("", "rdap_help_index.json"));
|
||||
.isEqualTo(loadJsonFile("rdap_help_index.json"));
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHelpActionTos_works() {
|
||||
assertThat(generateActualJson("/tos"))
|
||||
.isEqualTo(generateExpectedJson("", "rdap_help_tos.json"));
|
||||
.isEqualTo(loadJsonFile("rdap_help_tos.json"));
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user