mirror of
https://github.com/google/nomulus.git
synced 2025-08-05 17:28:25 +02:00
Turn CheckApiAction into a standard-ish epp endpoint
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=125335634
This commit is contained in:
parent
bb82f5bc05
commit
2b2fb958f6
15 changed files with 76 additions and 182 deletions
|
@ -1,33 +0,0 @@
|
|||
package(
|
||||
default_testonly = 1,
|
||||
default_visibility = ["//java/google/registry:registry_project"],
|
||||
)
|
||||
|
||||
licenses(["notice"]) # Apache 2.0
|
||||
|
||||
load("//java/com/google/testing/builddefs:GenTestRules.bzl", "GenTestRules")
|
||||
|
||||
|
||||
java_library(
|
||||
name = "api",
|
||||
srcs = glob(["*.java"]),
|
||||
deps = [
|
||||
"//java/com/google/common/collect",
|
||||
"//third_party/java/appengine:appengine-api-testonly",
|
||||
"//third_party/java/json_simple",
|
||||
"//third_party/java/junit",
|
||||
"//third_party/java/mockito",
|
||||
"//third_party/java/servlet/servlet_api",
|
||||
"//third_party/java/truth",
|
||||
"//java/google/registry/model",
|
||||
"//java/google/registry/ui/server/api",
|
||||
"//java/google/registry/util",
|
||||
"//javatests/google/registry/testing",
|
||||
],
|
||||
)
|
||||
|
||||
GenTestRules(
|
||||
name = "GeneratedTestRules",
|
||||
test_files = glob(["*Test.java"]),
|
||||
deps = [":api"],
|
||||
)
|
|
@ -1,174 +0,0 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.ui.server.api;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
|
||||
import static google.registry.testing.DatastoreHelper.persistReservedList;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import google.registry.util.SystemClock;
|
||||
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/** Tests for {@link CheckApiAction}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class CheckApiActionTest {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.build();
|
||||
|
||||
final CheckApiAction action = new CheckApiAction();
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
createTld("example");
|
||||
persistResource(
|
||||
Registry.get("example")
|
||||
.asBuilder()
|
||||
.setReservedLists(persistReservedList("example-reserved", "foo,FULLY_BLOCKED"))
|
||||
.build());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> getCheckResponse(String domain) {
|
||||
action.domain = domain;
|
||||
action.response = new FakeResponse();
|
||||
action.clock = new SystemClock();
|
||||
action.run();
|
||||
return (Map<String, Object>) JSONValue.parse(((FakeResponse) action.response).getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_nullDomain() throws Exception {
|
||||
assertThat(getCheckResponse(null)).containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_emptyDomain() throws Exception {
|
||||
assertThat(getCheckResponse("")).containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_invalidDomain() throws Exception {
|
||||
assertThat(getCheckResponse("@#$%^")).containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_singlePartDomain() throws Exception {
|
||||
assertThat(getCheckResponse("foo")).containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_nonExistentTld() throws Exception {
|
||||
assertThat(getCheckResponse("foo.bar")).containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Must supply a valid domain name on an authoritative TLD");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_unauthorizedTld() throws Exception {
|
||||
createTld("foo");
|
||||
persistResource(
|
||||
Registrar.loadByClientId("TheRegistrar")
|
||||
.asBuilder()
|
||||
.setAllowedTlds(ImmutableSet.of("foo"))
|
||||
.build());
|
||||
assertThat(getCheckResponse("timmy.example")).containsExactly(
|
||||
"status", "error",
|
||||
"reason", "Registrar is not authorized to access the TLD example");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_availableStandard() throws Exception {
|
||||
assertThat(getCheckResponse("somedomain.example")).containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "standard");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_availableCapital() throws Exception {
|
||||
assertThat(getCheckResponse("SOMEDOMAIN.EXAMPLE")).containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "standard");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_availableUnicode() throws Exception {
|
||||
assertThat(getCheckResponse("ééé.example")).containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "standard");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_availablePunycode() throws Exception {
|
||||
assertThat(getCheckResponse("xn--9caaa.example")).containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "standard");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_availablePremium() throws Exception {
|
||||
assertThat(getCheckResponse("rich.example")).containsExactly(
|
||||
"status", "success",
|
||||
"available", true,
|
||||
"tier", "premium");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_alreadyRegistered() throws Exception {
|
||||
persistActiveDomain("somedomain.example");
|
||||
assertThat(getCheckResponse("somedomain.example")).containsExactly(
|
||||
"status", "success",
|
||||
"available", false,
|
||||
"reason", "In use");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_reserved() throws Exception {
|
||||
assertThat(getCheckResponse("foo.example")).containsExactly(
|
||||
"status", "success",
|
||||
"available", false,
|
||||
"reason", "Reserved");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue