mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Refactor AppEngineConnection
AppEngineConnection can now connect to all services and not just the tools. The default is still the tools. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=218734983
This commit is contained in:
parent
97aa98eb35
commit
b48061b792
31 changed files with 269 additions and 329 deletions
|
@ -24,10 +24,8 @@ import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.net.HostAndPort;
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
import google.registry.config.RegistryConfigSettings.AppEngine.ToolsServiceUrl;
|
|
||||||
import google.registry.util.RandomStringGenerator;
|
import google.registry.util.RandomStringGenerator;
|
||||||
import google.registry.util.StringGenerator;
|
import google.registry.util.StringGenerator;
|
||||||
import google.registry.util.TaskQueueUtils;
|
import google.registry.util.TaskQueueUtils;
|
||||||
|
@ -1275,7 +1273,7 @@ public final class RegistryConfig {
|
||||||
@Config("insecureRandom")
|
@Config("insecureRandom")
|
||||||
public static Random provideInsecureRandom() {
|
public static Random provideInsecureRandom() {
|
||||||
return new Random();
|
return new Random();
|
||||||
};
|
}
|
||||||
|
|
||||||
/** Returns a singleton secure random number generator this is slow. */
|
/** Returns a singleton secure random number generator this is slow. */
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@ -1351,14 +1349,44 @@ public final class RegistryConfig {
|
||||||
return Duration.standardDays(30);
|
return Duration.standardDays(30);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean areServersLocal() {
|
||||||
|
return CONFIG_SETTINGS.get().appEngine.isLocal;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the address of the Nomulus app HTTP server.
|
* Returns the address of the Nomulus app default HTTP server.
|
||||||
*
|
*
|
||||||
* <p>This is used by the {@code nomulus} tool to connect to the App Engine remote API.
|
* <p>This is used by the {@code nomulus} tool to connect to the App Engine remote API.
|
||||||
*/
|
*/
|
||||||
public static HostAndPort getServer() {
|
public static URL getDefaultServer() {
|
||||||
ToolsServiceUrl url = CONFIG_SETTINGS.get().appEngine.toolsServiceUrl;
|
return makeUrl(CONFIG_SETTINGS.get().appEngine.defaultServiceUrl);
|
||||||
return HostAndPort.fromParts(url.hostName, url.port);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the address of the Nomulus app backend HTTP server.
|
||||||
|
*
|
||||||
|
* <p>This is used by the {@code nomulus} tool to connect to the App Engine remote API.
|
||||||
|
*/
|
||||||
|
public static URL getBackendServer() {
|
||||||
|
return makeUrl(CONFIG_SETTINGS.get().appEngine.backendServiceUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the address of the Nomulus app tools HTTP server.
|
||||||
|
*
|
||||||
|
* <p>This is used by the {@code nomulus} tool to connect to the App Engine remote API.
|
||||||
|
*/
|
||||||
|
public static URL getToolsServer() {
|
||||||
|
return makeUrl(CONFIG_SETTINGS.get().appEngine.toolsServiceUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the address of the Nomulus app pubapi HTTP server.
|
||||||
|
*
|
||||||
|
* <p>This is used by the {@code nomulus} tool to connect to the App Engine remote API.
|
||||||
|
*/
|
||||||
|
public static URL getPubapiServer() {
|
||||||
|
return makeUrl(CONFIG_SETTINGS.get().appEngine.pubapiServiceUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the amount of time a singleton should be cached, before expiring. */
|
/** Returns the amount of time a singleton should be cached, before expiring. */
|
||||||
|
@ -1466,7 +1494,7 @@ public final class RegistryConfig {
|
||||||
* change the contents of the YAML config files.
|
* change the contents of the YAML config files.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final Supplier<RegistryConfigSettings> CONFIG_SETTINGS =
|
public static final Supplier<RegistryConfigSettings> CONFIG_SETTINGS =
|
||||||
memoize(YamlUtils::getConfigSettings);
|
memoize(YamlUtils::getConfigSettings);
|
||||||
|
|
||||||
private static String formatComments(String text) {
|
private static String formatComments(String text) {
|
||||||
|
|
|
@ -40,13 +40,11 @@ public class RegistryConfigSettings {
|
||||||
/** Configuration options that apply to the entire App Engine project. */
|
/** Configuration options that apply to the entire App Engine project. */
|
||||||
public static class AppEngine {
|
public static class AppEngine {
|
||||||
public String projectId;
|
public String projectId;
|
||||||
public ToolsServiceUrl toolsServiceUrl;
|
public boolean isLocal;
|
||||||
|
public String defaultServiceUrl;
|
||||||
/** Configuration options for the tools service URL. */
|
public String backendServiceUrl;
|
||||||
public static class ToolsServiceUrl {
|
public String toolsServiceUrl;
|
||||||
public String hostName;
|
public String pubapiServiceUrl;
|
||||||
public int port;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Configuration options for OAuth settings for authenticating users. */
|
/** Configuration options for OAuth settings for authenticating users. */
|
||||||
|
|
|
@ -9,10 +9,13 @@ appEngine:
|
||||||
# Globally unique App Engine project ID
|
# Globally unique App Engine project ID
|
||||||
projectId: registry-project-id
|
projectId: registry-project-id
|
||||||
|
|
||||||
# Hostname and port of the tools service for the project.
|
# whether to use local/test credentials when connecting to the servers
|
||||||
toolsServiceUrl:
|
isLocal: true
|
||||||
hostName: localhost
|
# URLs of the services for the project.
|
||||||
port: 443
|
defaultServiceUrl: https://localhost
|
||||||
|
backendServiceUrl: https://localhost
|
||||||
|
toolsServiceUrl: https://localhost
|
||||||
|
pubapiServiceUrl: https://localhost
|
||||||
|
|
||||||
gSuite:
|
gSuite:
|
||||||
# Publicly accessible domain name of the running G Suite instance.
|
# Publicly accessible domain name of the running G Suite instance.
|
||||||
|
|
|
@ -4,11 +4,14 @@
|
||||||
|
|
||||||
appEngine:
|
appEngine:
|
||||||
projectId: placeholder
|
projectId: placeholder
|
||||||
# The "tools-dot-" prefix is used on the project ID in this URL in order to
|
# Set to true if running against local servers (localhost)
|
||||||
# get around an issue with double-wildcard SSL certs.
|
isLocal: false
|
||||||
toolsServiceUrl:
|
# The "<service>-dot-" prefix is used on the project ID in this URL in order
|
||||||
hostName: tools-dot-placeholder.appspot.com
|
# to get around an issue with double-wildcard SSL certs.
|
||||||
port: 443
|
defaultServiceUrl: https://domain-registry-placeholder.appspot.com
|
||||||
|
backendServiceUrl: https://backend-dot-domain-registry-placeholder.appspot.com
|
||||||
|
toolsServiceUrl: https://tools-dot-domain-registry-placeholder.appspot.com
|
||||||
|
pubapiServiceUrl: https://pubapi-dot-domain-registry-placeholder.appspot.com
|
||||||
|
|
||||||
gSuite:
|
gSuite:
|
||||||
domainName: placeholder
|
domainName: placeholder
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
package google.registry.tools;
|
package google.registry.tools;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Suppliers.memoize;
|
|
||||||
import static com.google.common.net.HttpHeaders.X_REQUESTED_WITH;
|
import static com.google.common.net.HttpHeaders.X_REQUESTED_WITH;
|
||||||
import static com.google.common.net.MediaType.JSON_UTF_8;
|
import static com.google.common.net.MediaType.JSON_UTF_8;
|
||||||
import static google.registry.security.JsonHttp.JSON_SAFETY_PREFIX;
|
import static google.registry.security.JsonHttp.JSON_SAFETY_PREFIX;
|
||||||
|
@ -27,48 +26,55 @@ import com.google.api.client.http.HttpHeaders;
|
||||||
import com.google.api.client.http.HttpRequest;
|
import com.google.api.client.http.HttpRequest;
|
||||||
import com.google.api.client.http.HttpRequestFactory;
|
import com.google.api.client.http.HttpRequestFactory;
|
||||||
import com.google.api.client.http.HttpResponse;
|
import com.google.api.client.http.HttpResponse;
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.io.CharStreams;
|
import com.google.common.io.CharStreams;
|
||||||
import com.google.common.net.HostAndPort;
|
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import com.google.re2j.Matcher;
|
import com.google.re2j.Matcher;
|
||||||
import com.google.re2j.Pattern;
|
import com.google.re2j.Pattern;
|
||||||
import google.registry.security.XsrfTokenManager;
|
import google.registry.config.RegistryConfig;
|
||||||
import google.registry.tools.CommandWithConnection.Connection;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import org.json.simple.JSONValue;
|
import org.json.simple.JSONValue;
|
||||||
|
|
||||||
/** An http connection to the appengine server. */
|
/**
|
||||||
class AppEngineConnection implements Connection {
|
* An http connection to an appengine server.
|
||||||
|
*
|
||||||
|
* <p>By default - connects to the TOOLS service. To create a Connection to another service, call
|
||||||
|
* the {@link #withService} function.
|
||||||
|
*/
|
||||||
|
class AppEngineConnection {
|
||||||
|
|
||||||
/** Pattern to heuristically extract title tag contents in HTML responses. */
|
/** Pattern to heuristically extract title tag contents in HTML responses. */
|
||||||
private static final Pattern HTML_TITLE_TAG_PATTERN = Pattern.compile("<title>(.*?)</title>");
|
private static final Pattern HTML_TITLE_TAG_PATTERN = Pattern.compile("<title>(.*?)</title>");
|
||||||
|
|
||||||
@Inject HttpRequestFactory requestFactory;
|
@Inject HttpRequestFactory requestFactory;
|
||||||
@Inject AppEngineConnectionFlags flags;
|
private final Service service;
|
||||||
@Inject XsrfTokenManager xsrfTokenManager;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AppEngineConnection() {}
|
AppEngineConnection() {
|
||||||
|
service = Service.TOOLS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
private AppEngineConnection(Service service, HttpRequestFactory requestFactory) {
|
||||||
* Memoized XSRF security token.
|
this.service = service;
|
||||||
*
|
this.requestFactory = requestFactory;
|
||||||
* <p>Computing this is expensive since it needs to load {@code ServerSecret} so do it once.
|
}
|
||||||
*/
|
|
||||||
private final Supplier<String> xsrfToken =
|
|
||||||
memoize(() -> xsrfTokenManager.generateToken(getUserId()));
|
|
||||||
|
|
||||||
@Override
|
enum Service {
|
||||||
public void prefetchXsrfToken() {
|
DEFAULT,
|
||||||
// Cause XSRF token to be fetched, and then stay resident in cache (since it's memoized).
|
TOOLS,
|
||||||
xsrfToken.get();
|
BACKEND,
|
||||||
|
PUBAPI
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns a copy of this connection that talks to a different service. */
|
||||||
|
public AppEngineConnection withService(Service service) {
|
||||||
|
return new AppEngineConnection(service, requestFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the contents of the title tag in the given HTML, or null if not found. */
|
/** Returns the contents of the title tag in the given HTML, or null if not found. */
|
||||||
|
@ -85,7 +91,8 @@ class AppEngineConnection implements Connection {
|
||||||
private String internalSend(
|
private String internalSend(
|
||||||
String endpoint, Map<String, ?> params, MediaType contentType, @Nullable byte[] payload)
|
String endpoint, Map<String, ?> params, MediaType contentType, @Nullable byte[] payload)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
GenericUrl url = new GenericUrl(String.format("%s%s", getServerUrl(), endpoint));
|
GenericUrl url = new GenericUrl(getServer());
|
||||||
|
url.setRawPath(endpoint);
|
||||||
url.putAll(params);
|
url.putAll(params);
|
||||||
HttpRequest request =
|
HttpRequest request =
|
||||||
(payload != null)
|
(payload != null)
|
||||||
|
@ -120,23 +127,20 @@ class AppEngineConnection implements Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(b/111123862): Rename this to sendPostRequest()
|
public String sendPostRequest(
|
||||||
@Override
|
String endpoint, Map<String, ?> params, MediaType contentType, byte[] payload)
|
||||||
public String send(String endpoint, Map<String, ?> params, MediaType contentType, byte[] payload)
|
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return internalSend(endpoint, params, contentType, checkNotNull(payload, "payload"));
|
return internalSend(endpoint, params, contentType, checkNotNull(payload, "payload"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String sendGetRequest(String endpoint, Map<String, ?> params) throws IOException {
|
public String sendGetRequest(String endpoint, Map<String, ?> params) throws IOException {
|
||||||
return internalSend(endpoint, params, MediaType.PLAIN_TEXT_UTF_8, null);
|
return internalSend(endpoint, params, MediaType.PLAIN_TEXT_UTF_8, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Map<String, Object> sendJson(String endpoint, Map<String, ?> object) throws IOException {
|
public Map<String, Object> sendJson(String endpoint, Map<String, ?> object) throws IOException {
|
||||||
String response =
|
String response =
|
||||||
send(
|
sendPostRequest(
|
||||||
endpoint,
|
endpoint,
|
||||||
ImmutableMap.of(),
|
ImmutableMap.of(),
|
||||||
JSON_UTF_8,
|
JSON_UTF_8,
|
||||||
|
@ -144,22 +148,17 @@ class AppEngineConnection implements Connection {
|
||||||
return (Map<String, Object>) JSONValue.parse(response.substring(JSON_SAFETY_PREFIX.length()));
|
return (Map<String, Object>) JSONValue.parse(response.substring(JSON_SAFETY_PREFIX.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public URL getServer() {
|
||||||
public String getServerUrl() {
|
switch (service) {
|
||||||
return (isLocalhost() ? "http://" : "https://") + getServer().toString();
|
case DEFAULT:
|
||||||
|
return RegistryConfig.getDefaultServer();
|
||||||
|
case TOOLS:
|
||||||
|
return RegistryConfig.getToolsServer();
|
||||||
|
case BACKEND:
|
||||||
|
return RegistryConfig.getBackendServer();
|
||||||
|
case PUBAPI:
|
||||||
|
return RegistryConfig.getPubapiServer();
|
||||||
}
|
}
|
||||||
|
throw new IllegalStateException("Unknown service: " + service);
|
||||||
HostAndPort getServer() {
|
|
||||||
return flags.getServer().withDefaultPort(443); // Default to HTTPS port if unspecified.
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isLocalhost() {
|
|
||||||
return flags.getServer().getHost().equals("localhost");
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getUserId() {
|
|
||||||
return isLocalhost()
|
|
||||||
? UserIdProvider.getTestUserId()
|
|
||||||
: UserIdProvider.getProdUserId();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
// Copyright 2017 The Nomulus 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.tools;
|
|
||||||
|
|
||||||
import com.beust.jcommander.Parameter;
|
|
||||||
import com.beust.jcommander.Parameters;
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import com.google.common.net.HostAndPort;
|
|
||||||
import dagger.Module;
|
|
||||||
import dagger.Provides;
|
|
||||||
import google.registry.config.RegistryConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class to contain the configuration flags for AppEngineConnection.
|
|
||||||
*
|
|
||||||
* <p>This is broken out into its own class to make it cleaner to extract these from the dagger
|
|
||||||
* module, where these values are injected.
|
|
||||||
*/
|
|
||||||
@Parameters(separators = " =")
|
|
||||||
class AppEngineConnectionFlags {
|
|
||||||
|
|
||||||
@Parameter(names = "--server", description = "HOST[:PORT] to which remote commands are sent.")
|
|
||||||
private HostAndPort server = RegistryConfig.getServer();
|
|
||||||
|
|
||||||
/** Provided for testing. */
|
|
||||||
@VisibleForTesting
|
|
||||||
AppEngineConnectionFlags(HostAndPort server) {
|
|
||||||
this.server = server;
|
|
||||||
}
|
|
||||||
|
|
||||||
AppEngineConnectionFlags() {}
|
|
||||||
|
|
||||||
HostAndPort getServer() {
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Module
|
|
||||||
static class FlagsModule {
|
|
||||||
AppEngineConnectionFlags flags;
|
|
||||||
|
|
||||||
FlagsModule(AppEngineConnectionFlags flags) {
|
|
||||||
this.flags = flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
AppEngineConnectionFlags provideAppEngineConnectionFlags() {
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,30 +14,7 @@
|
||||||
|
|
||||||
package google.registry.tools;
|
package google.registry.tools;
|
||||||
|
|
||||||
import com.google.common.net.MediaType;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/** A command that can send HTTP requests to a backend module. */
|
/** A command that can send HTTP requests to a backend module. */
|
||||||
interface CommandWithConnection extends Command {
|
interface CommandWithConnection extends Command {
|
||||||
|
void setConnection(AppEngineConnection connection);
|
||||||
/** An http connection to AppEngine. */
|
|
||||||
interface Connection {
|
|
||||||
|
|
||||||
void prefetchXsrfToken();
|
|
||||||
|
|
||||||
/** Send a POST request. TODO(mmuller): change to sendPostRequest() */
|
|
||||||
String send(
|
|
||||||
String endpoint, Map<String, ?> params, MediaType contentType, @Nullable byte[] payload)
|
|
||||||
throws IOException;
|
|
||||||
|
|
||||||
String sendGetRequest(String endpoint, Map<String, ?> params) throws IOException;
|
|
||||||
|
|
||||||
Map<String, Object> sendJson(String endpoint, Map<String, ?> object) throws IOException;
|
|
||||||
|
|
||||||
String getServerUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setConnection(Connection connection);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,11 +57,11 @@ abstract class CreateOrUpdatePremiumListCommand extends ConfirmingCommand
|
||||||
required = true)
|
required = true)
|
||||||
Path inputFile;
|
Path inputFile;
|
||||||
|
|
||||||
protected Connection connection;
|
protected AppEngineConnection connection;
|
||||||
protected int inputLineCount;
|
protected int inputLineCount;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setConnection(Connection connection) {
|
public void setConnection(AppEngineConnection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,11 +101,9 @@ abstract class CreateOrUpdatePremiumListCommand extends ConfirmingCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the server and get the response data
|
// Call the server and get the response data
|
||||||
String response = connection.send(
|
String response =
|
||||||
getCommandPath(),
|
connection.sendPostRequest(
|
||||||
params.build(),
|
getCommandPath(), params.build(), MediaType.FORM_DATA, requestBody.getBytes(UTF_8));
|
||||||
MediaType.FORM_DATA,
|
|
||||||
requestBody.getBytes(UTF_8));
|
|
||||||
|
|
||||||
return extractServerResponse(response);
|
return extractServerResponse(response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,10 +50,10 @@ final class CreateRegistrarCommand extends CreateOrUpdateRegistrarCommand
|
||||||
arity = 1)
|
arity = 1)
|
||||||
boolean createGoogleGroups = true;
|
boolean createGoogleGroups = true;
|
||||||
|
|
||||||
private Connection connection;
|
private AppEngineConnection connection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setConnection(Connection connection) {
|
public void setConnection(AppEngineConnection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,10 @@ public class CreateRegistrarGroupsCommand extends ConfirmingCommand
|
||||||
|
|
||||||
private List<Registrar> registrars = new ArrayList<>();
|
private List<Registrar> registrars = new ArrayList<>();
|
||||||
|
|
||||||
private Connection connection;
|
private AppEngineConnection connection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setConnection(Connection connection) {
|
public void setConnection(AppEngineConnection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,8 +66,8 @@ public class CreateRegistrarGroupsCommand extends ConfirmingCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Calls the server endpoint to create groups for the specified registrar client id. */
|
/** Calls the server endpoint to create groups for the specified registrar client id. */
|
||||||
static void executeOnServer(Connection connection, String clientId) throws IOException {
|
static void executeOnServer(AppEngineConnection connection, String clientId) throws IOException {
|
||||||
connection.send(
|
connection.sendPostRequest(
|
||||||
CreateGroupsAction.PATH,
|
CreateGroupsAction.PATH,
|
||||||
ImmutableMap.of(CreateGroupsAction.CLIENT_ID_PARAM, clientId),
|
ImmutableMap.of(CreateGroupsAction.CLIENT_ID_PARAM, clientId),
|
||||||
MediaType.PLAIN_TEXT_UTF_8,
|
MediaType.PLAIN_TEXT_UTF_8,
|
||||||
|
@ -77,7 +77,7 @@ public class CreateRegistrarGroupsCommand extends ConfirmingCommand
|
||||||
@Override
|
@Override
|
||||||
protected String execute() throws IOException {
|
protected String execute() throws IOException {
|
||||||
for (Registrar registrar : registrars) {
|
for (Registrar registrar : registrars) {
|
||||||
connection.send(
|
connection.sendPostRequest(
|
||||||
CreateGroupsAction.PATH,
|
CreateGroupsAction.PATH,
|
||||||
ImmutableMap.of(CreateGroupsAction.CLIENT_ID_PARAM, registrar.getClientId()),
|
ImmutableMap.of(CreateGroupsAction.CLIENT_ID_PARAM, registrar.getClientId()),
|
||||||
MediaType.PLAIN_TEXT_UTF_8,
|
MediaType.PLAIN_TEXT_UTF_8,
|
||||||
|
|
|
@ -22,11 +22,12 @@ import com.google.common.base.Joiner;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
|
import google.registry.tools.AppEngineConnection.Service;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Parameters(separators = " =", commandDescription = "Send an HTTP command to the nomulus server.")
|
@Parameters(separators = " =", commandDescription = "Send an HTTP command to the nomulus server.")
|
||||||
class CurlCommand implements CommandWithConnection {
|
class CurlCommand implements CommandWithConnection {
|
||||||
private Connection connection;
|
private AppEngineConnection connection;
|
||||||
|
|
||||||
// HTTP Methods that are acceptable for use as values for --method.
|
// HTTP Methods that are acceptable for use as values for --method.
|
||||||
public enum Method {
|
public enum Method {
|
||||||
|
@ -62,8 +63,14 @@ class CurlCommand implements CommandWithConnection {
|
||||||
+ "absent, a GET request is sent.")
|
+ "absent, a GET request is sent.")
|
||||||
private List<String> data;
|
private List<String> data;
|
||||||
|
|
||||||
|
@Parameter(
|
||||||
|
names = {"--service"},
|
||||||
|
description = "Which service to connect to",
|
||||||
|
required = true)
|
||||||
|
private Service service;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setConnection(Connection connection) {
|
public void setConnection(AppEngineConnection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,12 +84,14 @@ class CurlCommand implements CommandWithConnection {
|
||||||
throw new IllegalArgumentException("You may not specify a body for a get method.");
|
throw new IllegalArgumentException("You may not specify a body for a get method.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(b/112315418): Make it possible to address any backend.
|
AppEngineConnection connectionToService = connection.withService(service);
|
||||||
String response =
|
String response =
|
||||||
(method == Method.GET)
|
(method == Method.GET)
|
||||||
? connection.sendGetRequest(path, ImmutableMap.<String, String>of())
|
? connectionToService.sendGetRequest(path, ImmutableMap.<String, String>of())
|
||||||
: connection.send(
|
: connectionToService.sendPostRequest(
|
||||||
path, ImmutableMap.<String, String>of(), mimeType,
|
path,
|
||||||
|
ImmutableMap.<String, String>of(),
|
||||||
|
mimeType,
|
||||||
Joiner.on("&").join(data).getBytes(UTF_8));
|
Joiner.on("&").join(data).getBytes(UTF_8));
|
||||||
System.out.println(response);
|
System.out.println(response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import com.google.api.client.http.javanet.NetHttpTransport;
|
||||||
import dagger.Binds;
|
import dagger.Binds;
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
import google.registry.config.RegistryConfig;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
|
||||||
|
@ -43,9 +44,8 @@ class DefaultRequestFactoryModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Named("default")
|
@Named("default")
|
||||||
public HttpRequestFactory provideHttpRequestFactory(
|
public HttpRequestFactory provideHttpRequestFactory(
|
||||||
AppEngineConnectionFlags connectionFlags,
|
|
||||||
Provider<Credential> credentialProvider) {
|
Provider<Credential> credentialProvider) {
|
||||||
if (connectionFlags.getServer().getHost().equals("localhost")) {
|
if (RegistryConfig.areServersLocal()) {
|
||||||
return new NetHttpTransport()
|
return new NetHttpTransport()
|
||||||
.createRequestFactory(
|
.createRequestFactory(
|
||||||
request -> request
|
request -> request
|
||||||
|
|
|
@ -59,7 +59,7 @@ abstract class EppToolCommand extends ConfirmingCommand
|
||||||
|
|
||||||
private List<XmlEppParameters> commands = new ArrayList<>();
|
private List<XmlEppParameters> commands = new ArrayList<>();
|
||||||
|
|
||||||
private Connection connection;
|
private AppEngineConnection connection;
|
||||||
|
|
||||||
static class XmlEppParameters {
|
static class XmlEppParameters {
|
||||||
final String clientId;
|
final String clientId;
|
||||||
|
@ -95,7 +95,7 @@ abstract class EppToolCommand extends ConfirmingCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setConnection(Connection connection) {
|
public void setConnection(AppEngineConnection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,9 @@ abstract class EppToolCommand extends ConfirmingCommand
|
||||||
params.put("xml", URLEncoder.encode(command.xml, UTF_8.toString()));
|
params.put("xml", URLEncoder.encode(command.xml, UTF_8.toString()));
|
||||||
String requestBody =
|
String requestBody =
|
||||||
Joiner.on('&').withKeyValueSeparator("=").join(filterValues(params, Objects::nonNull));
|
Joiner.on('&').withKeyValueSeparator("=").join(filterValues(params, Objects::nonNull));
|
||||||
responses.add(nullToEmpty(connection.send(
|
responses.add(
|
||||||
|
nullToEmpty(
|
||||||
|
connection.sendPostRequest(
|
||||||
"/_dr/epptool",
|
"/_dr/epptool",
|
||||||
ImmutableMap.<String, String>of(),
|
ImmutableMap.<String, String>of(),
|
||||||
MediaType.FORM_DATA,
|
MediaType.FORM_DATA,
|
||||||
|
|
|
@ -45,10 +45,10 @@ final class GenerateZoneFilesCommand implements CommandWithConnection, CommandWi
|
||||||
validateWith = DateParameter.class)
|
validateWith = DateParameter.class)
|
||||||
private DateTime exportDate = DateTime.now(UTC).minus(standardMinutes(2)).withTimeAtStartOfDay();
|
private DateTime exportDate = DateTime.now(UTC).minus(standardMinutes(2)).withTimeAtStartOfDay();
|
||||||
|
|
||||||
private Connection connection;
|
private AppEngineConnection connection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setConnection(Connection connection) {
|
public void setConnection(AppEngineConnection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,10 +59,7 @@ final class GenerateZoneFilesCommand implements CommandWithConnection, CommandWi
|
||||||
"tlds", mainParameters,
|
"tlds", mainParameters,
|
||||||
"exportTime", exportDate.toString());
|
"exportTime", exportDate.toString());
|
||||||
Map<String, Object> response = connection.sendJson(GenerateZoneFilesAction.PATH, params);
|
Map<String, Object> response = connection.sendJson(GenerateZoneFilesAction.PATH, params);
|
||||||
System.out.printf(
|
System.out.printf("Job started at %s %s\n", connection.getServer(), response.get("jobPath"));
|
||||||
"Job started at %s%s\n",
|
|
||||||
connection.getServerUrl(),
|
|
||||||
response.get("jobPath"));
|
|
||||||
System.out.println("Output files:");
|
System.out.println("Output files:");
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<String> filenames = (List<String>) response.get("filenames");
|
List<String> filenames = (List<String>) response.get("filenames");
|
||||||
|
|
|
@ -54,10 +54,10 @@ abstract class ListObjectsCommand implements CommandWithConnection, CommandWithR
|
||||||
description = "Whether to print full field names in header row (as opposed to aliases)")
|
description = "Whether to print full field names in header row (as opposed to aliases)")
|
||||||
private boolean fullFieldNames = false;
|
private boolean fullFieldNames = false;
|
||||||
|
|
||||||
private Connection connection;
|
private AppEngineConnection connection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setConnection(Connection connection) {
|
public void setConnection(AppEngineConnection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,11 +83,9 @@ abstract class ListObjectsCommand implements CommandWithConnection, CommandWithR
|
||||||
}
|
}
|
||||||
params.putAll(getParameterMap());
|
params.putAll(getParameterMap());
|
||||||
// Call the server and get the response data.
|
// Call the server and get the response data.
|
||||||
String response = connection.send(
|
String response =
|
||||||
getCommandPath(),
|
connection.sendPostRequest(
|
||||||
params.build(),
|
getCommandPath(), params.build(), MediaType.PLAIN_TEXT_UTF_8, new byte[0]);
|
||||||
MediaType.PLAIN_TEXT_UTF_8,
|
|
||||||
new byte[0]);
|
|
||||||
// Parse the returned JSON and make sure it's a map.
|
// Parse the returned JSON and make sure it's a map.
|
||||||
Object obj = JSONValue.parse(response.substring(JSON_SAFETY_PREFIX.length()));
|
Object obj = JSONValue.parse(response.substring(JSON_SAFETY_PREFIX.length()));
|
||||||
if (!(obj instanceof Map<?, ?>)) {
|
if (!(obj instanceof Map<?, ?>)) {
|
||||||
|
|
|
@ -77,10 +77,10 @@ class LoadTestCommand extends ConfirmingCommand
|
||||||
description = "Time to run the load test in seconds.")
|
description = "Time to run the load test in seconds.")
|
||||||
int runSeconds = DEFAULT_RUN_SECONDS;
|
int runSeconds = DEFAULT_RUN_SECONDS;
|
||||||
|
|
||||||
private Connection connection;
|
private AppEngineConnection connection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setConnection(Connection connection) {
|
public void setConnection(AppEngineConnection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,10 +127,7 @@ class LoadTestCommand extends ConfirmingCommand
|
||||||
.put("runSeconds", runSeconds)
|
.put("runSeconds", runSeconds)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return connection.send(
|
return connection.sendPostRequest(
|
||||||
LoadTestAction.PATH,
|
LoadTestAction.PATH, params, MediaType.PLAIN_TEXT_UTF_8, new byte[0]);
|
||||||
params,
|
|
||||||
MediaType.PLAIN_TEXT_UTF_8,
|
|
||||||
new byte[0]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.beust.jcommander.Parameters;
|
||||||
import com.beust.jcommander.ParametersDelegate;
|
import com.beust.jcommander.ParametersDelegate;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import google.registry.config.RegistryConfig;
|
||||||
import google.registry.model.ofy.ObjectifyService;
|
import google.registry.model.ofy.ObjectifyService;
|
||||||
import google.registry.tools.params.ParameterFactory;
|
import google.registry.tools.params.ParameterFactory;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
|
@ -53,11 +54,6 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
|
||||||
description = "Returns all command names.")
|
description = "Returns all command names.")
|
||||||
private boolean showAllCommands;
|
private boolean showAllCommands;
|
||||||
|
|
||||||
// Do not make this final - compile-time constant inlining may interfere with JCommander.
|
|
||||||
@ParametersDelegate
|
|
||||||
private AppEngineConnectionFlags appEngineConnectionFlags =
|
|
||||||
new AppEngineConnectionFlags();
|
|
||||||
|
|
||||||
|
|
||||||
// Do not make this final - compile-time constant inlining may interfere with JCommander.
|
// Do not make this final - compile-time constant inlining may interfere with JCommander.
|
||||||
@ParametersDelegate
|
@ParametersDelegate
|
||||||
|
@ -84,7 +80,6 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
|
|
||||||
component = DaggerRegistryToolComponent.builder()
|
component = DaggerRegistryToolComponent.builder()
|
||||||
.flagsModule(new AppEngineConnectionFlags.FlagsModule(appEngineConnectionFlags))
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +192,7 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
|
||||||
RemoteApiOptions options = new RemoteApiOptions();
|
RemoteApiOptions options = new RemoteApiOptions();
|
||||||
options.server(
|
options.server(
|
||||||
getConnection().getServer().getHost(), getConnection().getServer().getPort());
|
getConnection().getServer().getHost(), getConnection().getServer().getPort());
|
||||||
if (getConnection().isLocalhost()) {
|
if (RegistryConfig.areServersLocal()) {
|
||||||
// Use dev credentials for localhost.
|
// Use dev credentials for localhost.
|
||||||
options.useDevelopmentServerCredential();
|
options.useDevelopmentServerCredential();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -46,7 +46,6 @@ import javax.inject.Singleton;
|
||||||
@Singleton
|
@Singleton
|
||||||
@Component(
|
@Component(
|
||||||
modules = {
|
modules = {
|
||||||
AppEngineConnectionFlags.FlagsModule.class,
|
|
||||||
AppEngineServiceUtilsModule.class,
|
AppEngineServiceUtilsModule.class,
|
||||||
// TODO(b/36866706): Find a way to replace this with a command-line friendly version
|
// TODO(b/36866706): Find a way to replace this with a command-line friendly version
|
||||||
AuthModule.class,
|
AuthModule.class,
|
||||||
|
|
|
@ -57,10 +57,10 @@ final class VerifyOteCommand implements CommandWithConnection, CommandWithRemote
|
||||||
description = "Only show a summary of information")
|
description = "Only show a summary of information")
|
||||||
private boolean summarize;
|
private boolean summarize;
|
||||||
|
|
||||||
private Connection connection;
|
private AppEngineConnection connection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setConnection(Connection connection) {
|
public void setConnection(AppEngineConnection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import google.registry.testing.UriParameters;
|
import google.registry.testing.UriParameters;
|
||||||
import google.registry.tools.CommandWithConnection.Connection;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
@ -46,9 +45,10 @@ public abstract class CreateOrUpdatePremiumListCommandTestCase<
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifySentParams(
|
void verifySentParams(
|
||||||
Connection connection, String path, ImmutableMap<String, String> parameterMap)
|
AppEngineConnection connection, String path, ImmutableMap<String, String> parameterMap)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
verify(connection).send(
|
verify(connection)
|
||||||
|
.sendPostRequest(
|
||||||
eq(path),
|
eq(path),
|
||||||
urlParamCaptor.capture(),
|
urlParamCaptor.capture(),
|
||||||
eq(MediaType.FORM_DATA),
|
eq(MediaType.FORM_DATA),
|
||||||
|
|
|
@ -28,7 +28,6 @@ import com.beust.jcommander.ParameterException;
|
||||||
import com.google.common.base.VerifyException;
|
import com.google.common.base.VerifyException;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import google.registry.tools.CommandWithConnection.Connection;
|
|
||||||
import google.registry.tools.server.CreatePremiumListAction;
|
import google.registry.tools.server.CreatePremiumListAction;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -38,8 +37,7 @@ import org.mockito.Mock;
|
||||||
public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
|
public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
|
||||||
extends CreateOrUpdatePremiumListCommandTestCase<C> {
|
extends CreateOrUpdatePremiumListCommandTestCase<C> {
|
||||||
|
|
||||||
@Mock
|
@Mock AppEngineConnection connection;
|
||||||
Connection connection;
|
|
||||||
|
|
||||||
String premiumTermsPath;
|
String premiumTermsPath;
|
||||||
String premiumTermsCsv;
|
String premiumTermsCsv;
|
||||||
|
@ -53,7 +51,7 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
|
||||||
"example_premium_terms.csv",
|
"example_premium_terms.csv",
|
||||||
loadFile(CreatePremiumListCommandTest.class, "example_premium_terms.csv"));
|
loadFile(CreatePremiumListCommandTest.class, "example_premium_terms.csv"));
|
||||||
servletPath = "/_dr/admin/createPremiumList";
|
servletPath = "/_dr/admin/createPremiumList";
|
||||||
when(connection.send(
|
when(connection.sendPostRequest(
|
||||||
eq(CreatePremiumListAction.PATH),
|
eq(CreatePremiumListAction.PATH),
|
||||||
anyMapOf(String.class, String.class),
|
anyMapOf(String.class, String.class),
|
||||||
any(MediaType.class),
|
any(MediaType.class),
|
||||||
|
@ -86,13 +84,12 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
|
||||||
public void testRun_errorResponse() throws Exception {
|
public void testRun_errorResponse() throws Exception {
|
||||||
reset(connection);
|
reset(connection);
|
||||||
command.setConnection(connection);
|
command.setConnection(connection);
|
||||||
when(connection.send(
|
when(connection.sendPostRequest(
|
||||||
eq(CreatePremiumListAction.PATH),
|
eq(CreatePremiumListAction.PATH),
|
||||||
anyMapOf(String.class, String.class),
|
anyMapOf(String.class, String.class),
|
||||||
any(MediaType.class),
|
any(MediaType.class),
|
||||||
any(byte[].class)))
|
any(byte[].class)))
|
||||||
.thenReturn(
|
.thenReturn(JSON_SAFETY_PREFIX + "{\"status\":\"error\",\"error\":\"foo already exists\"}");
|
||||||
JSON_SAFETY_PREFIX + "{\"status\":\"error\",\"error\":\"foo already exists\"}");
|
|
||||||
VerifyException thrown =
|
VerifyException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
VerifyException.class, () -> runCommandForced("-i=" + premiumTermsPath, "-n=foo"));
|
VerifyException.class, () -> runCommandForced("-i=" + premiumTermsPath, "-n=foo"));
|
||||||
|
|
|
@ -34,7 +34,6 @@ import com.google.common.collect.Range;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
import google.registry.testing.CertificateSamples;
|
import google.registry.testing.CertificateSamples;
|
||||||
import google.registry.tools.CommandWithConnection.Connection;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.joda.money.CurrencyUnit;
|
import org.joda.money.CurrencyUnit;
|
||||||
|
@ -47,8 +46,7 @@ import org.mockito.Mockito;
|
||||||
/** Unit tests for {@link CreateRegistrarCommand}. */
|
/** Unit tests for {@link CreateRegistrarCommand}. */
|
||||||
public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarCommand> {
|
public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarCommand> {
|
||||||
|
|
||||||
@Mock
|
@Mock private AppEngineConnection connection;
|
||||||
private Connection connection;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
|
@ -93,7 +91,8 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
|
||||||
assertThat(registrar.getPremiumPriceAckRequired()).isFalse();
|
assertThat(registrar.getPremiumPriceAckRequired()).isFalse();
|
||||||
assertThat(registrar.getPoNumber()).isEmpty();
|
assertThat(registrar.getPoNumber()).isEmpty();
|
||||||
|
|
||||||
verify(connection).send(
|
verify(connection)
|
||||||
|
.sendPostRequest(
|
||||||
eq("/_dr/admin/createGroups"),
|
eq("/_dr/admin/createGroups"),
|
||||||
eq(ImmutableMap.of("clientId", "clientz")),
|
eq(ImmutableMap.of("clientId", "clientz")),
|
||||||
eq(MediaType.PLAIN_TEXT_UTF_8),
|
eq(MediaType.PLAIN_TEXT_UTF_8),
|
||||||
|
@ -210,8 +209,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_groupCreationFails() throws Exception {
|
public void testFailure_groupCreationFails() throws Exception {
|
||||||
when(
|
when(connection.sendPostRequest(
|
||||||
connection.send(
|
|
||||||
Mockito.anyString(),
|
Mockito.anyString(),
|
||||||
Mockito.anyMapOf(String.class, String.class),
|
Mockito.anyMapOf(String.class, String.class),
|
||||||
Mockito.any(MediaType.class),
|
Mockito.any(MediaType.class),
|
||||||
|
|
|
@ -21,7 +21,6 @@ import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import google.registry.tools.CommandWithConnection.Connection;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
@ -30,8 +29,7 @@ import org.mockito.Mock;
|
||||||
public class CreateRegistrarGroupsCommandTest extends
|
public class CreateRegistrarGroupsCommandTest extends
|
||||||
CommandTestCase<CreateRegistrarGroupsCommand> {
|
CommandTestCase<CreateRegistrarGroupsCommand> {
|
||||||
|
|
||||||
@Mock
|
@Mock private AppEngineConnection connection;
|
||||||
private Connection connection;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
|
@ -41,12 +39,14 @@ public class CreateRegistrarGroupsCommandTest extends
|
||||||
@Test
|
@Test
|
||||||
public void test_createGroupsForTwoRegistrars() throws Exception {
|
public void test_createGroupsForTwoRegistrars() throws Exception {
|
||||||
runCommandForced("NewRegistrar", "TheRegistrar");
|
runCommandForced("NewRegistrar", "TheRegistrar");
|
||||||
verify(connection).send(
|
verify(connection)
|
||||||
|
.sendPostRequest(
|
||||||
eq("/_dr/admin/createGroups"),
|
eq("/_dr/admin/createGroups"),
|
||||||
eq(ImmutableMap.of("clientId", "NewRegistrar")),
|
eq(ImmutableMap.of("clientId", "NewRegistrar")),
|
||||||
eq(MediaType.PLAIN_TEXT_UTF_8),
|
eq(MediaType.PLAIN_TEXT_UTF_8),
|
||||||
eq(new byte[0]));
|
eq(new byte[0]));
|
||||||
verify(connection).send(
|
verify(connection)
|
||||||
|
.sendPostRequest(
|
||||||
eq("/_dr/admin/createGroups"),
|
eq("/_dr/admin/createGroups"),
|
||||||
eq(ImmutableMap.of("clientId", "TheRegistrar")),
|
eq(ImmutableMap.of("clientId", "TheRegistrar")),
|
||||||
eq(MediaType.PLAIN_TEXT_UTF_8),
|
eq(MediaType.PLAIN_TEXT_UTF_8),
|
||||||
|
|
|
@ -16,13 +16,19 @@ package google.registry.tools;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
|
import static google.registry.tools.AppEngineConnection.Service.BACKEND;
|
||||||
|
import static google.registry.tools.AppEngineConnection.Service.DEFAULT;
|
||||||
|
import static google.registry.tools.AppEngineConnection.Service.PUBAPI;
|
||||||
|
import static google.registry.tools.AppEngineConnection.Service.TOOLS;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import google.registry.tools.CommandWithConnection.Connection;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
@ -31,34 +37,42 @@ import org.mockito.Mock;
|
||||||
|
|
||||||
/** Unit tests for {@link RefreshDnsForAllDomainsCommand}. */
|
/** Unit tests for {@link RefreshDnsForAllDomainsCommand}. */
|
||||||
public class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
public class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||||
@Mock private Connection connection;
|
@Mock private AppEngineConnection connection;
|
||||||
|
@Mock private AppEngineConnection connectionForService;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
command.setConnection(connection);
|
command.setConnection(connection);
|
||||||
|
when(connection.withService(any())).thenReturn(connectionForService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Captor ArgumentCaptor<ImmutableMap<String, String>> urlParamCaptor;
|
@Captor ArgumentCaptor<ImmutableMap<String, String>> urlParamCaptor;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetInvocation() throws Exception {
|
public void testGetInvocation() throws Exception {
|
||||||
runCommand("--path=/foo/bar?a=1&b=2");
|
runCommand("--path=/foo/bar?a=1&b=2", "--service=TOOLS");
|
||||||
verify(connection)
|
verify(connection).withService(TOOLS);
|
||||||
|
verifyNoMoreInteractions(connection);
|
||||||
|
verify(connectionForService)
|
||||||
.sendGetRequest(eq("/foo/bar?a=1&b=2"), eq(ImmutableMap.<String, String>of()));
|
.sendGetRequest(eq("/foo/bar?a=1&b=2"), eq(ImmutableMap.<String, String>of()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitGetInvocation() throws Exception {
|
public void testExplicitGetInvocation() throws Exception {
|
||||||
runCommand("--path=/foo/bar?a=1&b=2", "--request=GET");
|
runCommand("--path=/foo/bar?a=1&b=2", "--request=GET", "--service=BACKEND");
|
||||||
verify(connection)
|
verify(connection).withService(BACKEND);
|
||||||
|
verifyNoMoreInteractions(connection);
|
||||||
|
verify(connectionForService)
|
||||||
.sendGetRequest(eq("/foo/bar?a=1&b=2"), eq(ImmutableMap.<String, String>of()));
|
.sendGetRequest(eq("/foo/bar?a=1&b=2"), eq(ImmutableMap.<String, String>of()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostInvocation() throws Exception {
|
public void testPostInvocation() throws Exception {
|
||||||
runCommand("--path=/foo/bar?a=1&b=2", "--data=some data");
|
runCommand("--path=/foo/bar?a=1&b=2", "--data=some data", "--service=DEFAULT");
|
||||||
verify(connection)
|
verify(connection).withService(DEFAULT);
|
||||||
.send(
|
verifyNoMoreInteractions(connection);
|
||||||
|
verify(connectionForService)
|
||||||
|
.sendPostRequest(
|
||||||
eq("/foo/bar?a=1&b=2"),
|
eq("/foo/bar?a=1&b=2"),
|
||||||
eq(ImmutableMap.<String, String>of()),
|
eq(ImmutableMap.<String, String>of()),
|
||||||
eq(MediaType.PLAIN_TEXT_UTF_8),
|
eq(MediaType.PLAIN_TEXT_UTF_8),
|
||||||
|
@ -67,9 +81,12 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultiDataPost() throws Exception {
|
public void testMultiDataPost() throws Exception {
|
||||||
runCommand("--path=/foo/bar?a=1&b=2", "--data=first=100", "-d", "second=200");
|
runCommand(
|
||||||
verify(connection)
|
"--path=/foo/bar?a=1&b=2", "--data=first=100", "-d", "second=200", "--service=PUBAPI");
|
||||||
.send(
|
verify(connection).withService(PUBAPI);
|
||||||
|
verifyNoMoreInteractions(connection);
|
||||||
|
verify(connectionForService)
|
||||||
|
.sendPostRequest(
|
||||||
eq("/foo/bar?a=1&b=2"),
|
eq("/foo/bar?a=1&b=2"),
|
||||||
eq(ImmutableMap.<String, String>of()),
|
eq(ImmutableMap.<String, String>of()),
|
||||||
eq(MediaType.PLAIN_TEXT_UTF_8),
|
eq(MediaType.PLAIN_TEXT_UTF_8),
|
||||||
|
@ -78,9 +95,11 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitPostInvocation() throws Exception {
|
public void testExplicitPostInvocation() throws Exception {
|
||||||
runCommand("--path=/foo/bar?a=1&b=2", "--request=POST");
|
runCommand("--path=/foo/bar?a=1&b=2", "--request=POST", "--service=TOOLS");
|
||||||
verify(connection)
|
verify(connection).withService(TOOLS);
|
||||||
.send(
|
verifyNoMoreInteractions(connection);
|
||||||
|
verify(connectionForService)
|
||||||
|
.sendPostRequest(
|
||||||
eq("/foo/bar?a=1&b=2"),
|
eq("/foo/bar?a=1&b=2"),
|
||||||
eq(ImmutableMap.<String, String>of()),
|
eq(ImmutableMap.<String, String>of()),
|
||||||
eq(MediaType.PLAIN_TEXT_UTF_8),
|
eq(MediaType.PLAIN_TEXT_UTF_8),
|
||||||
|
@ -94,7 +113,10 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() ->
|
() ->
|
||||||
runCommand(
|
runCommand(
|
||||||
"--path=/foo/bar?a=1&b=2", "--request=GET", "--data=inappropriate data"));
|
"--path=/foo/bar?a=1&b=2",
|
||||||
|
"--request=GET",
|
||||||
|
"--data=inappropriate data",
|
||||||
|
"--service=TOOLS"));
|
||||||
assertThat(thrown).hasMessageThat().contains("You may not specify a body for a get method.");
|
assertThat(thrown).hasMessageThat().contains("You may not specify a body for a get method.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import com.google.api.client.auth.oauth2.Credential;
|
||||||
import com.google.api.client.http.HttpRequest;
|
import com.google.api.client.http.HttpRequest;
|
||||||
import com.google.api.client.http.HttpRequestFactory;
|
import com.google.api.client.http.HttpRequestFactory;
|
||||||
import com.google.api.client.http.HttpRequestInitializer;
|
import com.google.api.client.http.HttpRequestInitializer;
|
||||||
import com.google.common.net.HostAndPort;
|
import google.registry.config.RegistryConfig;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -50,10 +50,8 @@ public class DefaultRequestFactoryModuleTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_provideHttpRequestFactory_localhost() {
|
public void test_provideHttpRequestFactory_localhost() {
|
||||||
// Make sure that localhost creates a request factory with an initializer.
|
// Make sure that localhost creates a request factory with an initializer.
|
||||||
HttpRequestFactory factory =
|
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = true;
|
||||||
module.provideHttpRequestFactory(
|
HttpRequestFactory factory = module.provideHttpRequestFactory(() -> FAKE_CREDENTIAL);
|
||||||
new AppEngineConnectionFlags(HostAndPort.fromParts("localhost", 1000)),
|
|
||||||
() -> FAKE_CREDENTIAL);
|
|
||||||
HttpRequestInitializer initializer = factory.getInitializer();
|
HttpRequestInitializer initializer = factory.getInitializer();
|
||||||
assertThat(initializer).isNotNull();
|
assertThat(initializer).isNotNull();
|
||||||
assertThat(initializer).isNotSameAs(FAKE_CREDENTIAL);
|
assertThat(initializer).isNotSameAs(FAKE_CREDENTIAL);
|
||||||
|
@ -62,11 +60,8 @@ public class DefaultRequestFactoryModuleTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_provideHttpRequestFactory_remote() {
|
public void test_provideHttpRequestFactory_remote() {
|
||||||
// Make sure that example.com creates a request factory with the UNITTEST client id but no
|
// Make sure that example.com creates a request factory with the UNITTEST client id but no
|
||||||
// initializer.
|
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = false;
|
||||||
HttpRequestFactory factory =
|
HttpRequestFactory factory = module.provideHttpRequestFactory(() -> FAKE_CREDENTIAL);
|
||||||
module.provideHttpRequestFactory(
|
|
||||||
new AppEngineConnectionFlags(HostAndPort.fromParts("example.com", 1000)),
|
|
||||||
() -> FAKE_CREDENTIAL);
|
|
||||||
assertThat(factory.getInitializer()).isSameAs(FAKE_CREDENTIAL);
|
assertThat(factory.getInitializer()).isSameAs(FAKE_CREDENTIAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import google.registry.tools.CommandWithConnection.Connection;
|
|
||||||
import google.registry.tools.server.ToolsTestData;
|
import google.registry.tools.server.ToolsTestData;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -49,7 +48,7 @@ import org.mockito.ArgumentCaptor;
|
||||||
*/
|
*/
|
||||||
public class EppToolVerifier {
|
public class EppToolVerifier {
|
||||||
|
|
||||||
private final Connection connection = mock(Connection.class);
|
private final AppEngineConnection connection = mock(AppEngineConnection.class);
|
||||||
|
|
||||||
private String clientId;
|
private String clientId;
|
||||||
private boolean superuser;
|
private boolean superuser;
|
||||||
|
@ -167,11 +166,9 @@ public class EppToolVerifier {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ArgumentCaptor<byte[]> params = ArgumentCaptor.forClass(byte[].class);
|
ArgumentCaptor<byte[]> params = ArgumentCaptor.forClass(byte[].class);
|
||||||
verify(connection, atLeast(0)).send(
|
verify(connection, atLeast(0))
|
||||||
eq("/_dr/epptool"),
|
.sendPostRequest(
|
||||||
eq(ImmutableMap.of()),
|
eq("/_dr/epptool"), eq(ImmutableMap.of()), eq(MediaType.FORM_DATA), params.capture());
|
||||||
eq(MediaType.FORM_DATA),
|
|
||||||
params.capture());
|
|
||||||
capturedParams = ImmutableList.copyOf(params.getAllValues());
|
capturedParams = ImmutableList.copyOf(params.getAllValues());
|
||||||
paramIndex = 0;
|
paramIndex = 0;
|
||||||
}
|
}
|
||||||
|
@ -198,7 +195,7 @@ public class EppToolVerifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the (mock) Connection that is being monitored by this verifier. */
|
/** Returns the (mock) Connection that is being monitored by this verifier. */
|
||||||
private Connection getConnection() {
|
private AppEngineConnection getConnection() {
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase<ListDomai
|
||||||
public void test_bothParamsSpecified() throws Exception {
|
public void test_bothParamsSpecified() throws Exception {
|
||||||
runCommand("--tlds=foo,bar", "--limit=100");
|
runCommand("--tlds=foo,bar", "--limit=100");
|
||||||
verify(connection)
|
verify(connection)
|
||||||
.send(
|
.sendPostRequest(
|
||||||
eq(getTaskPath()),
|
eq(getTaskPath()),
|
||||||
eq(ImmutableMap.of("tlds", "foo,bar", "limit", 100)),
|
eq(ImmutableMap.of("tlds", "foo,bar", "limit", 100)),
|
||||||
eq(MediaType.PLAIN_TEXT_UTF_8),
|
eq(MediaType.PLAIN_TEXT_UTF_8),
|
||||||
|
@ -73,7 +73,7 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase<ListDomai
|
||||||
persistResource(newRegistry("fake", "FAKE").asBuilder().setTldType(TldType.TEST).build());
|
persistResource(newRegistry("fake", "FAKE").asBuilder().setTldType(TldType.TEST).build());
|
||||||
runCommand();
|
runCommand();
|
||||||
verify(connection)
|
verify(connection)
|
||||||
.send(
|
.sendPostRequest(
|
||||||
eq(getTaskPath()),
|
eq(getTaskPath()),
|
||||||
eq(ImmutableMap.of("tlds", "tldone,tldtwo", "limit", Integer.MAX_VALUE)),
|
eq(ImmutableMap.of("tlds", "tldone,tldtwo", "limit", Integer.MAX_VALUE)),
|
||||||
eq(MediaType.PLAIN_TEXT_UTF_8),
|
eq(MediaType.PLAIN_TEXT_UTF_8),
|
||||||
|
|
|
@ -28,7 +28,6 @@ import static org.mockito.Mockito.when;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import google.registry.tools.CommandWithConnection.Connection;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -38,7 +37,7 @@ import org.mockito.Mock;
|
||||||
public abstract class ListObjectsCommandTestCase<C extends ListObjectsCommand>
|
public abstract class ListObjectsCommandTestCase<C extends ListObjectsCommand>
|
||||||
extends CommandTestCase<C> {
|
extends CommandTestCase<C> {
|
||||||
|
|
||||||
@Mock Connection connection;
|
@Mock AppEngineConnection connection;
|
||||||
|
|
||||||
/** Where to find the servlet task; set by the subclass. */
|
/** Where to find the servlet task; set by the subclass. */
|
||||||
abstract String getTaskPath();
|
abstract String getTaskPath();
|
||||||
|
@ -62,7 +61,7 @@ public abstract class ListObjectsCommandTestCase<C extends ListObjectsCommand>
|
||||||
.collect(toImmutableList());
|
.collect(toImmutableList());
|
||||||
}
|
}
|
||||||
command.setConnection(connection);
|
command.setConnection(connection);
|
||||||
when(connection.send(
|
when(connection.sendPostRequest(
|
||||||
eq(getTaskPath()),
|
eq(getTaskPath()),
|
||||||
anyMapOf(String.class, Object.class),
|
anyMapOf(String.class, Object.class),
|
||||||
eq(MediaType.PLAIN_TEXT_UTF_8),
|
eq(MediaType.PLAIN_TEXT_UTF_8),
|
||||||
|
@ -82,7 +81,7 @@ public abstract class ListObjectsCommandTestCase<C extends ListObjectsCommand>
|
||||||
fullFieldNames.ifPresent(aBoolean -> params.put(FULL_FIELD_NAMES_PARAM, aBoolean));
|
fullFieldNames.ifPresent(aBoolean -> params.put(FULL_FIELD_NAMES_PARAM, aBoolean));
|
||||||
params.putAll(getOtherParameters());
|
params.putAll(getOtherParameters());
|
||||||
verify(connection)
|
verify(connection)
|
||||||
.send(
|
.sendPostRequest(
|
||||||
eq(getTaskPath()), eq(params.build()), eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0]));
|
eq(getTaskPath()), eq(params.build()), eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
import google.registry.tools.CommandWithConnection.Connection;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -32,7 +31,7 @@ import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class LoadTestCommandTest extends CommandTestCase<LoadTestCommand> {
|
public class LoadTestCommandTest extends CommandTestCase<LoadTestCommand> {
|
||||||
Connection connection = mock(Connection.class);
|
AppEngineConnection connection = mock(AppEngineConnection.class);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
@ -55,11 +54,9 @@ public class LoadTestCommandTest extends CommandTestCase<LoadTestCommand> {
|
||||||
.put("contactInfos", 1)
|
.put("contactInfos", 1)
|
||||||
.put("runSeconds", 4600)
|
.put("runSeconds", 4600)
|
||||||
.build();
|
.build();
|
||||||
verify(connection).send(
|
verify(connection)
|
||||||
eq("/_dr/loadtest"),
|
.sendPostRequest(
|
||||||
eq(parms),
|
eq("/_dr/loadtest"), eq(parms), eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0]));
|
||||||
eq(MediaType.PLAIN_TEXT_UTF_8),
|
|
||||||
eq(new byte[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -86,11 +83,9 @@ public class LoadTestCommandTest extends CommandTestCase<LoadTestCommand> {
|
||||||
.put("contactInfos", 15)
|
.put("contactInfos", 15)
|
||||||
.put("runSeconds", 16)
|
.put("runSeconds", 16)
|
||||||
.build();
|
.build();
|
||||||
verify(connection).send(
|
verify(connection)
|
||||||
eq("/_dr/loadtest"),
|
.sendPostRequest(
|
||||||
eq(parms),
|
eq("/_dr/loadtest"), eq(parms), eq(MediaType.PLAIN_TEXT_UTF_8), eq(new byte[0]));
|
||||||
eq(MediaType.PLAIN_TEXT_UTF_8),
|
|
||||||
eq(new byte[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -23,7 +23,6 @@ import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import google.registry.tools.CommandWithConnection.Connection;
|
|
||||||
import google.registry.tools.server.UpdatePremiumListAction;
|
import google.registry.tools.server.UpdatePremiumListAction;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -33,8 +32,7 @@ import org.mockito.Mock;
|
||||||
public class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
|
public class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
|
||||||
extends CreateOrUpdatePremiumListCommandTestCase<C> {
|
extends CreateOrUpdatePremiumListCommandTestCase<C> {
|
||||||
|
|
||||||
@Mock
|
@Mock AppEngineConnection connection;
|
||||||
Connection connection;
|
|
||||||
|
|
||||||
String premiumTermsPath;
|
String premiumTermsPath;
|
||||||
String premiumTermsCsv;
|
String premiumTermsCsv;
|
||||||
|
@ -48,7 +46,7 @@ public class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
|
||||||
writeToNamedTmpFile(
|
writeToNamedTmpFile(
|
||||||
"example_premium_terms.csv",
|
"example_premium_terms.csv",
|
||||||
loadFile(UpdatePremiumListCommandTest.class, "example_premium_terms.csv"));
|
loadFile(UpdatePremiumListCommandTest.class, "example_premium_terms.csv"));
|
||||||
when(connection.send(
|
when(connection.sendPostRequest(
|
||||||
eq(UpdatePremiumListAction.PATH),
|
eq(UpdatePremiumListAction.PATH),
|
||||||
anyMapOf(String.class, String.class),
|
anyMapOf(String.class, String.class),
|
||||||
any(MediaType.class),
|
any(MediaType.class),
|
||||||
|
|
|
@ -27,7 +27,6 @@ import static org.mockito.Mockito.when;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
import google.registry.tools.CommandWithConnection.Connection;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
@ -35,7 +34,7 @@ import org.mockito.Mock;
|
||||||
/** Unit tests for {@link VerifyOteCommand}. */
|
/** Unit tests for {@link VerifyOteCommand}. */
|
||||||
public class VerifyOteCommandTest extends CommandTestCase<VerifyOteCommand> {
|
public class VerifyOteCommandTest extends CommandTestCase<VerifyOteCommand> {
|
||||||
|
|
||||||
@Mock private Connection connection;
|
@Mock private AppEngineConnection connection;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue