From 36633646d6868884def94c9b8831f6a62e195cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Denis?= Date: Fri, 25 Oct 2019 17:09:04 +0200 Subject: [PATCH 01/12] Update Gradle to latest 5.x - Fix shadow plugin version and remove apt --- endpoints-framework-all/build.gradle | 2 +- endpoints-framework/build.gradle | 6 +----- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/endpoints-framework-all/build.gradle b/endpoints-framework-all/build.gradle index 134bfedf..ab78cf04 100644 --- a/endpoints-framework-all/build.gradle +++ b/endpoints-framework-all/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'com.github.johnrengelman.shadow' version '1.2.3' + id 'com.github.johnrengelman.shadow' version '5.1.0' } configurations { diff --git a/endpoints-framework/build.gradle b/endpoints-framework/build.gradle index ecf82073..9cbc2c57 100644 --- a/endpoints-framework/build.gradle +++ b/endpoints-framework/build.gradle @@ -14,10 +14,6 @@ * limitations under the License. */ -plugins { - id 'net.ltgt.apt' version '0.8' -} - configurations { include compile.extendsFrom include @@ -105,7 +101,7 @@ dependencies { compileOnly group: 'javax.servlet', name: 'servlet-api', version: servletVersion compileOnly "com.google.auto.value:auto-value:1.2" - apt "com.google.auto.value:auto-value:1.2" + annotationProcessor "com.google.auto.value:auto-value:1.2" testCompile project(':test-utils') testCompile group: 'junit', name: 'junit', version: junitVersion diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fedb654a..6286ac36 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ #Wed Aug 21 16:54:33 CEST 2019 -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists From 96c53b1d6e4fd6c66331e146db3c61fc32b2330b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Denis?= Date: Fri, 25 Oct 2019 17:09:58 +0200 Subject: [PATCH 02/12] Update compile dependencies - Separate httpClient and apiClient versions --- endpoints-framework/build.gradle | 2 +- gradle.properties | 17 +++++++++-------- test-compat/build.gradle | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/endpoints-framework/build.gradle b/endpoints-framework/build.gradle index 9cbc2c57..7757ea9c 100644 --- a/endpoints-framework/build.gradle +++ b/endpoints-framework/build.gradle @@ -83,7 +83,7 @@ dependencies { compile group: 'com.google.appengine', name: 'appengine-api-1.0-sdk', version: appengineVersion compile group: 'com.google.flogger', name: 'flogger', version: floggerVersion runtime group: 'com.google.flogger', name: 'flogger-system-backend', version: floggerVersion - compile(group: 'com.google.http-client', name: 'google-http-client-jackson2', version: apiclientVersion) { + compile(group: 'com.google.http-client', name: 'google-http-client-jackson2', version: httpClientVersion) { exclude group: 'com.google.guava', module: 'guava-jdk5' exclude group: 'com.fasterxml.jackson.core', module: 'jackson-core' } diff --git a/gradle.properties b/gradle.properties index 0127f8c9..4b6c9b55 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,17 +6,18 @@ group=com.aodocs.endpoints servletVersion=2.5 javaxinjectVersion=1 -guavaVersion=27.1-jre -jacksonVersion=2.9.8 +guavaVersion=28.1-jre +jacksonVersion=2.10.0 gradleAppenginePluginVersion=1.9.59 -appengineVersion=1.9.71 -apiclientVersion=1.27.0 -fileUploadVersion=1.3.3 +appengineVersion=1.9.76 +httpClientVersion=1.32.1 +apiclientVersion=1.30.4 +fileUploadVersion=1.4 findbugsVersion=3.0.1 -swaggerVersion=1.5.22 -slf4jVersion=1.7.26 +swaggerVersion=1.5.24 +slf4jVersion=1.7.28 guiceVersion=4.0 -objectifyVersion=5.1.22 +objectifyVersion=5.1.24 floggerVersion=0.4 junitVersion=4.12 diff --git a/test-compat/build.gradle b/test-compat/build.gradle index 819725cb..035d81a7 100644 --- a/test-compat/build.gradle +++ b/test-compat/build.gradle @@ -136,7 +136,7 @@ dependencies { testlibCompile group: 'junit', name: 'junit', version: junitVersion testlibCompile group: 'com.google.truth', name: 'truth', version: truthVersion testlibCompile group: 'javax.servlet', name: 'servlet-api', version: servletVersion - testlibCompile(group: 'com.google.http-client', name: 'google-http-client-jackson', version: apiclientVersion) { + testlibCompile(group: 'com.google.http-client', name: 'google-http-client-jackson', version: httpClientVersion) { exclude group: 'com.google.guava', module: 'guava-jdk5' } testlibCompile(group: 'com.google.api-client', name: 'google-api-client', version: apiclientVersion) { From 1dfe28c1544967a15cd745cf1abaf89f4d0ee2d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Denis?= Date: Fri, 25 Oct 2019 17:10:18 +0200 Subject: [PATCH 03/12] Update Mockito and fix tests --- .../api/server/spi/BackendPropertiesTest.java | 2 -- .../auth/GoogleAppEngineAuthenticatorTest.java | 1 - .../spi/auth/GoogleJwtAuthenticatorTest.java | 1 - .../spi/auth/GoogleOAuth2AuthenticatorTest.java | 1 - .../spi/config/model/ApiMethodConfigTest.java | 1 - .../ProxyingDiscoveryProviderTest.java | 17 ++++++++--------- .../api/server/spi/request/AttributeTest.java | 1 - gradle.properties | 4 ++-- .../api/server/spi/BaseSystemServiceTest.java | 8 ++++---- 9 files changed, 14 insertions(+), 22 deletions(-) diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/BackendPropertiesTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/BackendPropertiesTest.java index 69b1e925..5dfec76b 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/BackendPropertiesTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/BackendPropertiesTest.java @@ -97,8 +97,6 @@ public void testGetApplicationId_appEngine() { @Test public void testGetApplicationId_flex() { System.clearProperty(BackendProperties.APP_ID_PROPERTY); - Mockito.when(envReader.getenv(BackendProperties.GCLOUD_PROJECT_PROPERTY)) - .thenReturn(APPLICATION_ID); assertNull(properties.getApplicationId()); } } diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleAppEngineAuthenticatorTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleAppEngineAuthenticatorTest.java index 3265bb83..857b4e52 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleAppEngineAuthenticatorTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleAppEngineAuthenticatorTest.java @@ -147,7 +147,6 @@ public void testGetOAuth2UserSkipClientIdCheck() throws Exception { when(config.getScopeExpression()).thenReturn(AuthScopeExpressions.interpret(SCOPES)); when(oauthService.getAuthorizedScopes(SCOPES)).thenReturn(SCOPES); when(oauthService.getClientId(SCOPES)).thenReturn(CLIENT_ID); - when(config.getClientIds()).thenReturn(ImmutableList.of("clienId2")); when(oauthService.getCurrentUser(SCOPES)).thenReturn(APP_ENGINE_USER); assertEquals(APP_ENGINE_USER, authenticator.getOAuth2User(request, config)); } diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleJwtAuthenticatorTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleJwtAuthenticatorTest.java index e67140d7..7b462456 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleJwtAuthenticatorTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleJwtAuthenticatorTest.java @@ -129,7 +129,6 @@ public void testAuthenticate_audienceNotAllowed() throws Exception { public void testAuthenticate_skipClientIdCheck() throws Exception { request.removeAttribute(Attribute.ENABLE_CLIENT_ID_WHITELIST); when(verifier.verify(TOKEN)).thenReturn(token); - when(config.getClientIds()).thenReturn(ImmutableList.of("clientId2")); when(config.getAudiences()).thenReturn(ImmutableList.of(AUDIENCE)); User user = authenticator.authenticate(request); assertEquals(EMAIL, user.getEmail()); diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleOAuth2AuthenticatorTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleOAuth2AuthenticatorTest.java index b05839fa..e052c7a9 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleOAuth2AuthenticatorTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleOAuth2AuthenticatorTest.java @@ -106,7 +106,6 @@ public void testAuthenticate_clientIdNotAllowed() throws ServiceUnavailableExcep public void testAuthenticate_skipClientIdCheck() throws ServiceUnavailableException { request.removeAttribute(Attribute.ENABLE_CLIENT_ID_WHITELIST); when(config.getScopeExpression()).thenReturn(AuthScopeExpressions.interpret("scope1")); - when(config.getClientIds()).thenReturn(ImmutableList.of("clientId2")); User user = authenticator.authenticate(request); assertEquals(EMAIL, user.getEmail()); assertEquals(USER_ID, user.getId()); diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiMethodConfigTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiMethodConfigTest.java index fc401d44..b71a8ec1 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiMethodConfigTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiMethodConfigTest.java @@ -71,7 +71,6 @@ public void setUp() throws Exception { Mockito.when(apiClassConfig.getApiConfig()).thenReturn(apiConfig); Mockito.when(method.getMethod()).thenReturn(TestEndpoint.class.getMethod("getResultNoParams")); - Mockito.doReturn(TestEndpoint.class).when(method).getEndpointClass(); methodConfig = new ApiMethodConfig(method, new TypeLoader(), apiClassConfig); } diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProviderTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProviderTest.java index aec77a9e..bb8288ff 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProviderTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProviderTest.java @@ -215,18 +215,17 @@ private static Iterable withConfigs(ApiConfig... configs) { return argThat(new ConfigMatcher(Sets.newHashSet(configs))); } - private static class ConfigMatcher extends ArgumentMatcher> { + private static class ConfigMatcher implements ArgumentMatcher> { private final Set configs; ConfigMatcher(Set configs) { this.configs = configs; } - @SuppressWarnings("unchecked") @Override - public boolean matches(Object argument) { - return argument instanceof Iterable - && configs.equals(Sets.newHashSet((Iterable) argument)); + public boolean matches(Iterable argument) { + return argument != null + && configs.equals(Sets.newHashSet(argument)); } } @@ -234,7 +233,7 @@ private static ApiConfigs withConfigs(String... jsonConfigs) { return argThat(new ApiConfigsMatcher(Sets.newHashSet(jsonConfigs))); } - private static class ApiConfigsMatcher extends ArgumentMatcher { + private static class ApiConfigsMatcher implements ArgumentMatcher { private final Set configs; ApiConfigsMatcher(Set configs) { @@ -242,9 +241,9 @@ private static class ApiConfigsMatcher extends ArgumentMatcher { } @Override - public boolean matches(Object argument) { - return argument instanceof ApiConfigs - && configs.equals(Sets.newHashSet(((ApiConfigs) argument).getConfigs())); + public boolean matches(ApiConfigs argument) { + return argument != null + && configs.equals(Sets.newHashSet(argument.getConfigs())); } } diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/request/AttributeTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/request/AttributeTest.java index bd6f69ce..b87b1bc2 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/request/AttributeTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/request/AttributeTest.java @@ -97,7 +97,6 @@ public void bindStandardRequestAttributes_skipTokenAuth() throws Exception { attr.remove(Attribute.SKIP_TOKEN_AUTH); initParams = createInitParams(true /* restricted */, false /* clientIdWhitelistEnabled */); - when(methodConfig.getClientIds()).thenReturn(ImmutableList.of("clientId")); attr = Attribute.bindStandardRequestAttributes(request, methodConfig, initParams); assertFalse(attr.isEnabled(Attribute.SKIP_TOKEN_AUTH)); } diff --git a/gradle.properties b/gradle.properties index 4b6c9b55..cb815639 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ objectifyVersion=5.1.24 floggerVersion=0.4 junitVersion=4.12 -mockitoVersion=1.10.19 +mockitoVersion=3.1.0 jsonassertVersion=1.5.0 truthVersion=1.0 -springtestVersion=3.2.16.RELEASE +springtestVersion=3.2.18.RELEASE diff --git a/test-utils/src/main/java/com/google/api/server/spi/BaseSystemServiceTest.java b/test-utils/src/main/java/com/google/api/server/spi/BaseSystemServiceTest.java index d4c61670..0fb795fe 100644 --- a/test-utils/src/main/java/com/google/api/server/spi/BaseSystemServiceTest.java +++ b/test-utils/src/main/java/com/google/api/server/spi/BaseSystemServiceTest.java @@ -263,7 +263,7 @@ private static Iterable setOf(ApiConfig... configs) { return argThat(new ConfigListMatcher(configs)); } - private static class ConfigListMatcher extends ArgumentMatcher> { + private static class ConfigListMatcher implements ArgumentMatcher> { private Set expectedConfigs; public ConfigListMatcher(ApiConfig... expectedConfigs) { @@ -271,9 +271,9 @@ public ConfigListMatcher(ApiConfig... expectedConfigs) { } @Override - public boolean matches(Object argument) { - return argument instanceof Iterable - && expectedConfigs.equals(Sets.newHashSet((Iterable) argument)); + public boolean matches(Iterable argument) { + return argument != null + && expectedConfigs.equals(Sets.newHashSet(argument)); } } } From 1afbd9a69a149a839586e2a7b40778599bc497bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Denis?= Date: Fri, 25 Oct 2019 18:28:41 +0200 Subject: [PATCH 04/12] Update deps in discovery-client --- discovery-client/build.gradle | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/discovery-client/build.gradle b/discovery-client/build.gradle index 194bacce..ab11e4c7 100644 --- a/discovery-client/build.gradle +++ b/discovery-client/build.gradle @@ -19,12 +19,12 @@ apply plugin: 'maven' group = 'com.google.apis' archivesBaseName = 'google-api-services-discovery' -version = 'v1-rev20151119-1.20.0' +version = 'v1-rev20190129-1.30.1' -sourceCompatibility = 1.6 -targetCompatibility = 1.6 +sourceCompatibility = 1.8 +targetCompatibility = 1.8 jar.manifest.attributes("Built-By": "Google") -jar.manifest.attributes("Build-Jdk": "1.6.x") +jar.manifest.attributes("Build-Jdk": "1.8.x") task sourceJar(type: Jar) { classifier = 'sources' @@ -40,11 +40,11 @@ repositories { } dependencies { - compile module(group: 'com.google.api-client', name: 'google-api-client', version: '1.21.0') { - module(group: 'com.google.http-client', name: 'google-http-client-jackson2', version: '1.21.0') { - dependency('com.fasterxml.jackson.core:jackson-core:2.6.4') - dependency('com.google.http-client:google-http-client:1.21.0') + compile module(group: 'com.google.api-client', name: 'google-api-client', version: "1.30.4") { + module(group: 'com.google.http-client', name: 'google-http-client-jackson2', version: "1.32.1") { + dependency("com.fasterxml.jackson.core:jackson-core:2.10.0") + dependency("com.google.http-client:google-http-client:1.32.1") } - dependency('com.google.oauth-client:google-oauth-client:1.21.0') + dependency("com.google.oauth-client:google-oauth-client:1.30.4") } } From 57550edcb554910114371bbb2d63f5e8d4f81ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Denis?= Date: Fri, 25 Oct 2019 18:28:59 +0200 Subject: [PATCH 05/12] Remove all code related to RPC (not supported) --- .../api/services/discovery/Discovery.java | 206 +---- .../discovery/model/RpcDescription.java | 869 ------------------ .../services/discovery/model/RpcMethod.java | 507 ---------- .../discovery/CachingDiscoveryProvider.java | 17 - .../spi/discovery/DiscoveryProvider.java | 10 - .../spi/discovery/LocalDiscoveryProvider.java | 7 - .../discovery/ProxyingDiscoveryProvider.java | 14 - .../discovery/ProxyingDiscoveryService.java | 11 - .../CachingDiscoveryProviderTest.java | 71 -- .../discovery/LocalDiscoveryProviderTest.java | 10 - .../ProxyingDiscoveryProviderTest.java | 41 - .../ProxyingDiscoveryServiceTest.java | 56 -- 12 files changed, 2 insertions(+), 1817 deletions(-) delete mode 100644 discovery-client/src/main/java/com/google/api/services/discovery/model/RpcDescription.java delete mode 100644 discovery-client/src/main/java/com/google/api/services/discovery/model/RpcMethod.java diff --git a/discovery-client/src/main/java/com/google/api/services/discovery/Discovery.java b/discovery-client/src/main/java/com/google/api/services/discovery/Discovery.java index 1a4e8d19..fca627d4 100644 --- a/discovery-client/src/main/java/com/google/api/services/discovery/Discovery.java +++ b/discovery-client/src/main/java/com/google/api/services/discovery/Discovery.java @@ -295,85 +295,7 @@ public GenerateRest set(String parameterName, Object value) { return (GenerateRest) super.set(parameterName, value); } } - /** - * Generates the Discovery Document of an API given its configuration. - * - * Create a request for the method "apis.generateRpc". - * - * This request holds the parameters needed by the discovery server. After setting any optional - * parameters, call the {@link GenerateRpc#execute()} method to invoke the remote operation. - * - * @param content the {@link com.google.api.services.discovery.model.ApiConfig} - * @return the request - */ - public GenerateRpc generateRpc(com.google.api.services.discovery.model.ApiConfig content) throws java.io.IOException { - GenerateRpc result = new GenerateRpc(content); - initialize(result); - return result; - } - - public class GenerateRpc extends DiscoveryRequest { - - private static final String REST_PATH = "apis/generate/rpc"; - - /** - * Generates the Discovery Document of an API given its configuration. - * - * Create a request for the method "apis.generateRpc". - * - * This request holds the parameters needed by the the discovery server. After setting any - * optional parameters, call the {@link GenerateRpc#execute()} method to invoke the remote - * operation.

{@link - * GenerateRpc#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} - * must be called to initialize this instance immediately after invoking the constructor.

- * - * @param content the {@link com.google.api.services.discovery.model.ApiConfig} - * @since 1.13 - */ - protected GenerateRpc(com.google.api.services.discovery.model.ApiConfig content) { - super(Discovery.this, "POST", REST_PATH, content, com.google.api.services.discovery.model.RpcDescription.class); - } - - @Override - public GenerateRpc setAlt(java.lang.String alt) { - return (GenerateRpc) super.setAlt(alt); - } - - @Override - public GenerateRpc setFields(java.lang.String fields) { - return (GenerateRpc) super.setFields(fields); - } - - @Override - public GenerateRpc setKey(java.lang.String key) { - return (GenerateRpc) super.setKey(key); - } - - @Override - public GenerateRpc setOauthToken(java.lang.String oauthToken) { - return (GenerateRpc) super.setOauthToken(oauthToken); - } - - @Override - public GenerateRpc setPrettyPrint(java.lang.Boolean prettyPrint) { - return (GenerateRpc) super.setPrettyPrint(prettyPrint); - } - - @Override - public GenerateRpc setQuotaUser(java.lang.String quotaUser) { - return (GenerateRpc) super.setQuotaUser(quotaUser); - } - - @Override - public GenerateRpc setUserIp(java.lang.String userIp) { - return (GenerateRpc) super.setUserIp(userIp); - } - - @Override - public GenerateRpc set(String parameterName, Object value) { - return (GenerateRpc) super.set(parameterName, value); - } - } + /** * Retrieve the description of a particular version of an api. * @@ -499,131 +421,7 @@ public GetRest set(String parameterName, Object value) { return (GetRest) super.set(parameterName, value); } } - /** - * Retrieve the description of a particular version of an api. - * - * Create a request for the method "apis.getRpc". - * - * This request holds the parameters needed by the discovery server. After setting any optional - * parameters, call the {@link GetRpc#execute()} method to invoke the remote operation. - * - * @param api The name of the API. - * @param version The version of the API. - * @return the request - */ - public GetRpc getRpc(java.lang.String api, java.lang.String version) throws java.io.IOException { - GetRpc result = new GetRpc(api, version); - initialize(result); - return result; - } - - public class GetRpc extends DiscoveryRequest { - - private static final String REST_PATH = "apis/{api}/{version}/rpc"; - - /** - * Retrieve the description of a particular version of an api. - * - * Create a request for the method "apis.getRpc". - * - * This request holds the parameters needed by the the discovery server. After setting any - * optional parameters, call the {@link GetRpc#execute()} method to invoke the remote operation. - *

{@link - * GetRpc#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} must - * be called to initialize this instance immediately after invoking the constructor.

- * - * @param api The name of the API. - * @param version The version of the API. - * @since 1.13 - */ - protected GetRpc(java.lang.String api, java.lang.String version) { - super(Discovery.this, "GET", REST_PATH, null, com.google.api.services.discovery.model.RpcDescription.class); - this.api = com.google.api.client.util.Preconditions.checkNotNull(api, "Required parameter api must be specified."); - this.version = com.google.api.client.util.Preconditions.checkNotNull(version, "Required parameter version must be specified."); - } - - @Override - public com.google.api.client.http.HttpResponse executeUsingHead() throws java.io.IOException { - return super.executeUsingHead(); - } - - @Override - public com.google.api.client.http.HttpRequest buildHttpRequestUsingHead() throws java.io.IOException { - return super.buildHttpRequestUsingHead(); - } - - @Override - public GetRpc setAlt(java.lang.String alt) { - return (GetRpc) super.setAlt(alt); - } - - @Override - public GetRpc setFields(java.lang.String fields) { - return (GetRpc) super.setFields(fields); - } - - @Override - public GetRpc setKey(java.lang.String key) { - return (GetRpc) super.setKey(key); - } - - @Override - public GetRpc setOauthToken(java.lang.String oauthToken) { - return (GetRpc) super.setOauthToken(oauthToken); - } - - @Override - public GetRpc setPrettyPrint(java.lang.Boolean prettyPrint) { - return (GetRpc) super.setPrettyPrint(prettyPrint); - } - - @Override - public GetRpc setQuotaUser(java.lang.String quotaUser) { - return (GetRpc) super.setQuotaUser(quotaUser); - } - - @Override - public GetRpc setUserIp(java.lang.String userIp) { - return (GetRpc) super.setUserIp(userIp); - } - - /** The name of the API. */ - @com.google.api.client.util.Key - private java.lang.String api; - - /** The name of the API. - */ - public java.lang.String getApi() { - return api; - } - - /** The name of the API. */ - public GetRpc setApi(java.lang.String api) { - this.api = api; - return this; - } - - /** The version of the API. */ - @com.google.api.client.util.Key - private java.lang.String version; - - /** The version of the API. - */ - public java.lang.String getVersion() { - return version; - } - - /** The version of the API. */ - public GetRpc setVersion(java.lang.String version) { - this.version = version; - return this; - } - - @Override - public GetRpc set(String parameterName, Object value) { - return (GetRpc) super.set(parameterName, value); - } - } + /** * Retrieve the list of APIs supported at this endpoint. * diff --git a/discovery-client/src/main/java/com/google/api/services/discovery/model/RpcDescription.java b/discovery-client/src/main/java/com/google/api/services/discovery/model/RpcDescription.java deleted file mode 100644 index 74765187..00000000 --- a/discovery-client/src/main/java/com/google/api/services/discovery/model/RpcDescription.java +++ /dev/null @@ -1,869 +0,0 @@ -/* - * Copyright 2010 Google Inc. - * - * 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. - */ -/* - * This code was generated by https://code.google.com/p/google-apis-client-generator/ - * (build: 2015-11-16 19:10:01 UTC) - * on 2015-11-19 at 17:34:48 UTC - * Modify at your own risk. - */ - -package com.google.api.services.discovery.model; - -/** - * Model definition for RpcDescription. - * - *

This is the Java data model class that specifies how to parse/serialize into the JSON that is - * transmitted over HTTP when working with the APIs Discovery Service. For a detailed explanation - * see: - * http://code.google.com/p/google-http-java-client/wiki/JSON - *

- * - * @author Google, Inc. - */ -@SuppressWarnings("javadoc") -public final class RpcDescription extends com.google.api.client.json.GenericJson { - - /** - * Authentication information. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private Auth auth; - - /** - * Indicates how the API name should be capitalized and split into various parts. Useful for - * generating pretty class names. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String canonicalName; - - /** - * The description of the API. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String description; - - /** - * Indicate the version of the Discovery API used to generate this doc. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String discoveryVersion; - - /** - * A link to human readable documentation for the API. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String documentationLink; - - /** - * The ETag for this response. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String etag; - - /** - * Enable exponential backoff for suitable methods in the generated clients. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.Boolean exponentialBackoffDefault; - - /** - * A list of supported features for this API. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.util.List features; - - /** - * Links to 16x16 and 32x32 icons representing the API. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private Icons icons; - - /** - * The ID of this API. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String id; - - /** - * The kind for this response. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String kind; - - /** - * Labels for the status of this API, such as labs or deprecated. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.util.List labels; - - /** - * API-level methods for this API. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.util.Map methods; - - /** - * The name of this API. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String name; - - /** - * The domain of the owner of the API. Together with the ownerName and a packagePath values, this - * can be used to generate a library for the API which would have a unique fully qualified name. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String ownerDomain; - - /** - * The name of the owner of the API. See ownerDomain - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String ownerName; - - /** - * The package of the owner of the API. See ownerDomain - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String packagePath; - - /** - * Common parameters that apply across all apis. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.util.Map parameters; - - /** - * The protocol described by this document. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String protocol; - - /** - * The version of the API. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String revision; - - /** - * The root URL under which all API services live. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String rootUrl; - - /** - * The path for JSON-RPC requests. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String rpcPath; - - /** - * [DEPRECATED] The URL for JSON-RPC requests. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String rpcUrl; - - /** - * The schemas for this API. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.util.Map schemas; - - /** - * The title of the API. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String title; - - /** - * The version of the API. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String version; - - /** - * Authentication information. - * @return value or {@code null} for none - */ - public Auth getAuth() { - return auth; - } - - /** - * Authentication information. - * @param auth auth or {@code null} for none - */ - public RpcDescription setAuth(Auth auth) { - this.auth = auth; - return this; - } - - /** - * Indicates how the API name should be capitalized and split into various parts. Useful for - * generating pretty class names. - * @return value or {@code null} for none - */ - public java.lang.String getCanonicalName() { - return canonicalName; - } - - /** - * Indicates how the API name should be capitalized and split into various parts. Useful for - * generating pretty class names. - * @param canonicalName canonicalName or {@code null} for none - */ - public RpcDescription setCanonicalName(java.lang.String canonicalName) { - this.canonicalName = canonicalName; - return this; - } - - /** - * The description of the API. - * @return value or {@code null} for none - */ - public java.lang.String getDescription() { - return description; - } - - /** - * The description of the API. - * @param description description or {@code null} for none - */ - public RpcDescription setDescription(java.lang.String description) { - this.description = description; - return this; - } - - /** - * Indicate the version of the Discovery API used to generate this doc. - * @return value or {@code null} for none - */ - public java.lang.String getDiscoveryVersion() { - return discoveryVersion; - } - - /** - * Indicate the version of the Discovery API used to generate this doc. - * @param discoveryVersion discoveryVersion or {@code null} for none - */ - public RpcDescription setDiscoveryVersion(java.lang.String discoveryVersion) { - this.discoveryVersion = discoveryVersion; - return this; - } - - /** - * A link to human readable documentation for the API. - * @return value or {@code null} for none - */ - public java.lang.String getDocumentationLink() { - return documentationLink; - } - - /** - * A link to human readable documentation for the API. - * @param documentationLink documentationLink or {@code null} for none - */ - public RpcDescription setDocumentationLink(java.lang.String documentationLink) { - this.documentationLink = documentationLink; - return this; - } - - /** - * The ETag for this response. - * @return value or {@code null} for none - */ - public java.lang.String getEtag() { - return etag; - } - - /** - * The ETag for this response. - * @param etag etag or {@code null} for none - */ - public RpcDescription setEtag(java.lang.String etag) { - this.etag = etag; - return this; - } - - /** - * Enable exponential backoff for suitable methods in the generated clients. - * @return value or {@code null} for none - */ - public java.lang.Boolean getExponentialBackoffDefault() { - return exponentialBackoffDefault; - } - - /** - * Enable exponential backoff for suitable methods in the generated clients. - * @param exponentialBackoffDefault exponentialBackoffDefault or {@code null} for none - */ - public RpcDescription setExponentialBackoffDefault(java.lang.Boolean exponentialBackoffDefault) { - this.exponentialBackoffDefault = exponentialBackoffDefault; - return this; - } - - /** - * A list of supported features for this API. - * @return value or {@code null} for none - */ - public java.util.List getFeatures() { - return features; - } - - /** - * A list of supported features for this API. - * @param features features or {@code null} for none - */ - public RpcDescription setFeatures(java.util.List features) { - this.features = features; - return this; - } - - /** - * Links to 16x16 and 32x32 icons representing the API. - * @return value or {@code null} for none - */ - public Icons getIcons() { - return icons; - } - - /** - * Links to 16x16 and 32x32 icons representing the API. - * @param icons icons or {@code null} for none - */ - public RpcDescription setIcons(Icons icons) { - this.icons = icons; - return this; - } - - /** - * The ID of this API. - * @return value or {@code null} for none - */ - public java.lang.String getId() { - return id; - } - - /** - * The ID of this API. - * @param id id or {@code null} for none - */ - public RpcDescription setId(java.lang.String id) { - this.id = id; - return this; - } - - /** - * The kind for this response. - * @return value or {@code null} for none - */ - public java.lang.String getKind() { - return kind; - } - - /** - * The kind for this response. - * @param kind kind or {@code null} for none - */ - public RpcDescription setKind(java.lang.String kind) { - this.kind = kind; - return this; - } - - /** - * Labels for the status of this API, such as labs or deprecated. - * @return value or {@code null} for none - */ - public java.util.List getLabels() { - return labels; - } - - /** - * Labels for the status of this API, such as labs or deprecated. - * @param labels labels or {@code null} for none - */ - public RpcDescription setLabels(java.util.List labels) { - this.labels = labels; - return this; - } - - /** - * API-level methods for this API. - * @return value or {@code null} for none - */ - public java.util.Map getMethods() { - return methods; - } - - /** - * API-level methods for this API. - * @param methods methods or {@code null} for none - */ - public RpcDescription setMethods(java.util.Map methods) { - this.methods = methods; - return this; - } - - /** - * The name of this API. - * @return value or {@code null} for none - */ - public java.lang.String getName() { - return name; - } - - /** - * The name of this API. - * @param name name or {@code null} for none - */ - public RpcDescription setName(java.lang.String name) { - this.name = name; - return this; - } - - /** - * The domain of the owner of the API. Together with the ownerName and a packagePath values, this - * can be used to generate a library for the API which would have a unique fully qualified name. - * @return value or {@code null} for none - */ - public java.lang.String getOwnerDomain() { - return ownerDomain; - } - - /** - * The domain of the owner of the API. Together with the ownerName and a packagePath values, this - * can be used to generate a library for the API which would have a unique fully qualified name. - * @param ownerDomain ownerDomain or {@code null} for none - */ - public RpcDescription setOwnerDomain(java.lang.String ownerDomain) { - this.ownerDomain = ownerDomain; - return this; - } - - /** - * The name of the owner of the API. See ownerDomain - * @return value or {@code null} for none - */ - public java.lang.String getOwnerName() { - return ownerName; - } - - /** - * The name of the owner of the API. See ownerDomain - * @param ownerName ownerName or {@code null} for none - */ - public RpcDescription setOwnerName(java.lang.String ownerName) { - this.ownerName = ownerName; - return this; - } - - /** - * The package of the owner of the API. See ownerDomain - * @return value or {@code null} for none - */ - public java.lang.String getPackagePath() { - return packagePath; - } - - /** - * The package of the owner of the API. See ownerDomain - * @param packagePath packagePath or {@code null} for none - */ - public RpcDescription setPackagePath(java.lang.String packagePath) { - this.packagePath = packagePath; - return this; - } - - /** - * Common parameters that apply across all apis. - * @return value or {@code null} for none - */ - public java.util.Map getParameters() { - return parameters; - } - - /** - * Common parameters that apply across all apis. - * @param parameters parameters or {@code null} for none - */ - public RpcDescription setParameters(java.util.Map parameters) { - this.parameters = parameters; - return this; - } - - /** - * The protocol described by this document. - * @return value or {@code null} for none - */ - public java.lang.String getProtocol() { - return protocol; - } - - /** - * The protocol described by this document. - * @param protocol protocol or {@code null} for none - */ - public RpcDescription setProtocol(java.lang.String protocol) { - this.protocol = protocol; - return this; - } - - /** - * The version of the API. - * @return value or {@code null} for none - */ - public java.lang.String getRevision() { - return revision; - } - - /** - * The version of the API. - * @param revision revision or {@code null} for none - */ - public RpcDescription setRevision(java.lang.String revision) { - this.revision = revision; - return this; - } - - /** - * The root URL under which all API services live. - * @return value or {@code null} for none - */ - public java.lang.String getRootUrl() { - return rootUrl; - } - - /** - * The root URL under which all API services live. - * @param rootUrl rootUrl or {@code null} for none - */ - public RpcDescription setRootUrl(java.lang.String rootUrl) { - this.rootUrl = rootUrl; - return this; - } - - /** - * The path for JSON-RPC requests. - * @return value or {@code null} for none - */ - public java.lang.String getRpcPath() { - return rpcPath; - } - - /** - * The path for JSON-RPC requests. - * @param rpcPath rpcPath or {@code null} for none - */ - public RpcDescription setRpcPath(java.lang.String rpcPath) { - this.rpcPath = rpcPath; - return this; - } - - /** - * [DEPRECATED] The URL for JSON-RPC requests. - * @return value or {@code null} for none - */ - public java.lang.String getRpcUrl() { - return rpcUrl; - } - - /** - * [DEPRECATED] The URL for JSON-RPC requests. - * @param rpcUrl rpcUrl or {@code null} for none - */ - public RpcDescription setRpcUrl(java.lang.String rpcUrl) { - this.rpcUrl = rpcUrl; - return this; - } - - /** - * The schemas for this API. - * @return value or {@code null} for none - */ - public java.util.Map getSchemas() { - return schemas; - } - - /** - * The schemas for this API. - * @param schemas schemas or {@code null} for none - */ - public RpcDescription setSchemas(java.util.Map schemas) { - this.schemas = schemas; - return this; - } - - /** - * The title of the API. - * @return value or {@code null} for none - */ - public java.lang.String getTitle() { - return title; - } - - /** - * The title of the API. - * @param title title or {@code null} for none - */ - public RpcDescription setTitle(java.lang.String title) { - this.title = title; - return this; - } - - /** - * The version of the API. - * @return value or {@code null} for none - */ - public java.lang.String getVersion() { - return version; - } - - /** - * The version of the API. - * @param version version or {@code null} for none - */ - public RpcDescription setVersion(java.lang.String version) { - this.version = version; - return this; - } - - @Override - public RpcDescription set(String fieldName, Object value) { - return (RpcDescription) super.set(fieldName, value); - } - - @Override - public RpcDescription clone() { - return (RpcDescription) super.clone(); - } - - /** - * Authentication information. - */ - public static final class Auth extends com.google.api.client.json.GenericJson { - - /** - * OAuth 2.0 authentication information. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private Oauth2 oauth2; - - /** - * OAuth 2.0 authentication information. - * @return value or {@code null} for none - */ - public Oauth2 getOauth2() { - return oauth2; - } - - /** - * OAuth 2.0 authentication information. - * @param oauth2 oauth2 or {@code null} for none - */ - public Auth setOauth2(Oauth2 oauth2) { - this.oauth2 = oauth2; - return this; - } - - @Override - public Auth set(String fieldName, Object value) { - return (Auth) super.set(fieldName, value); - } - - @Override - public Auth clone() { - return (Auth) super.clone(); - } - - /** - * OAuth 2.0 authentication information. - */ - public static final class Oauth2 extends com.google.api.client.json.GenericJson { - - /** - * Available OAuth 2.0 scopes. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.util.Map scopes; - - static { - // hack to force ProGuard to consider ScopesElement used, since otherwise it would be stripped out - // see http://code.google.com/p/google-api-java-client/issues/detail?id=528 - com.google.api.client.util.Data.nullOf(ScopesElement.class); - } - - /** - * Available OAuth 2.0 scopes. - * @return value or {@code null} for none - */ - public java.util.Map getScopes() { - return scopes; - } - - /** - * Available OAuth 2.0 scopes. - * @param scopes scopes or {@code null} for none - */ - public Oauth2 setScopes(java.util.Map scopes) { - this.scopes = scopes; - return this; - } - - @Override - public Oauth2 set(String fieldName, Object value) { - return (Oauth2) super.set(fieldName, value); - } - - @Override - public Oauth2 clone() { - return (Oauth2) super.clone(); - } - - /** - * The scope value. - */ - public static final class ScopesElement extends com.google.api.client.json.GenericJson { - - /** - * Description of scope. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String description; - - /** - * Description of scope. - * @return value or {@code null} for none - */ - public java.lang.String getDescription() { - return description; - } - - /** - * Description of scope. - * @param description description or {@code null} for none - */ - public ScopesElement setDescription(java.lang.String description) { - this.description = description; - return this; - } - - @Override - public ScopesElement set(String fieldName, Object value) { - return (ScopesElement) super.set(fieldName, value); - } - - @Override - public ScopesElement clone() { - return (ScopesElement) super.clone(); - } - - } - } - } - - /** - * Links to 16x16 and 32x32 icons representing the API. - */ - public static final class Icons extends com.google.api.client.json.GenericJson { - - /** - * The URL of the 16x16 icon. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String x16; - - /** - * The URL of the 32x32 icon. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String x32; - - /** - * The URL of the 16x16 icon. - * @return value or {@code null} for none - */ - public java.lang.String getX16() { - return x16; - } - - /** - * The URL of the 16x16 icon. - * @param x16 x16 or {@code null} for none - */ - public Icons setX16(java.lang.String x16) { - this.x16 = x16; - return this; - } - - /** - * The URL of the 32x32 icon. - * @return value or {@code null} for none - */ - public java.lang.String getX32() { - return x32; - } - - /** - * The URL of the 32x32 icon. - * @param x32 x32 or {@code null} for none - */ - public Icons setX32(java.lang.String x32) { - this.x32 = x32; - return this; - } - - @Override - public Icons set(String fieldName, Object value) { - return (Icons) super.set(fieldName, value); - } - - @Override - public Icons clone() { - return (Icons) super.clone(); - } - - } - -} diff --git a/discovery-client/src/main/java/com/google/api/services/discovery/model/RpcMethod.java b/discovery-client/src/main/java/com/google/api/services/discovery/model/RpcMethod.java deleted file mode 100644 index f8259217..00000000 --- a/discovery-client/src/main/java/com/google/api/services/discovery/model/RpcMethod.java +++ /dev/null @@ -1,507 +0,0 @@ -/* - * Copyright 2010 Google Inc. - * - * 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. - */ -/* - * This code was generated by https://code.google.com/p/google-apis-client-generator/ - * (build: 2015-11-16 19:10:01 UTC) - * on 2015-11-19 at 17:34:48 UTC - * Modify at your own risk. - */ - -package com.google.api.services.discovery.model; - -/** - * Model definition for RpcMethod. - * - *

This is the Java data model class that specifies how to parse/serialize into the JSON that is - * transmitted over HTTP when working with the APIs Discovery Service. For a detailed explanation - * see: - * http://code.google.com/p/google-http-java-client/wiki/JSON - *

- * - * @author Google, Inc. - */ -@SuppressWarnings("javadoc") -public final class RpcMethod extends com.google.api.client.json.GenericJson { - - /** - * Whether the method can be made using an HTTP GET JSON-RPC request. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.Boolean allowGet; - - /** - * Description of this method. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String description; - - /** - * Does this method require sending the ETag along with the request. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.Boolean etagRequired; - - /** - * A unique ID for this method. This property can be used to match methods between different - * versions of Discovery. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String id; - - /** - * Media upload parameters. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private MediaUpload mediaUpload; - - /** - * Ordered list of required parameters, serves as a hint to clients on how to structure their - * method signatures. The array is ordered such that the "most-significant" parameter appears - * first. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.util.List parameterOrder; - - /** - * Description for all parameters in this method. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.util.Map parameters; - - static { - // hack to force ProGuard to consider JsonSchema used, since otherwise it would be stripped out - // see http://code.google.com/p/google-api-java-client/issues/detail?id=528 - com.google.api.client.util.Data.nullOf(JsonSchema.class); - } - - /** - * The schema for the response. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private Returns returns; - - /** - * OAuth 2.0 scopes applicable to this method. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.util.List scopes; - - /** - * Whether this method supports media download. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.Boolean supportsMediaDownload; - - /** - * Whether this method supports media upload. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.Boolean supportsMediaUpload; - - /** - * Whether this method supports patch semantics. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.Boolean supportsPatch; - - /** - * Whether this method supports subscriptions. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.Boolean supportsSubscription; - - /** - * Indicates that downloads from this method should use the download service URL (i.e. - * "/download"). Only applies if the method supports media download. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.Boolean useMediaDownloadService; - - /** - * Whether the method can be made using an HTTP GET JSON-RPC request. - * @return value or {@code null} for none - */ - public java.lang.Boolean getAllowGet() { - return allowGet; - } - - /** - * Whether the method can be made using an HTTP GET JSON-RPC request. - * @param allowGet allowGet or {@code null} for none - */ - public RpcMethod setAllowGet(java.lang.Boolean allowGet) { - this.allowGet = allowGet; - return this; - } - - /** - * Description of this method. - * @return value or {@code null} for none - */ - public java.lang.String getDescription() { - return description; - } - - /** - * Description of this method. - * @param description description or {@code null} for none - */ - public RpcMethod setDescription(java.lang.String description) { - this.description = description; - return this; - } - - /** - * Does this method require sending the ETag along with the request. - * @return value or {@code null} for none - */ - public java.lang.Boolean getEtagRequired() { - return etagRequired; - } - - /** - * Does this method require sending the ETag along with the request. - * @param etagRequired etagRequired or {@code null} for none - */ - public RpcMethod setEtagRequired(java.lang.Boolean etagRequired) { - this.etagRequired = etagRequired; - return this; - } - - /** - * A unique ID for this method. This property can be used to match methods between different - * versions of Discovery. - * @return value or {@code null} for none - */ - public java.lang.String getId() { - return id; - } - - /** - * A unique ID for this method. This property can be used to match methods between different - * versions of Discovery. - * @param id id or {@code null} for none - */ - public RpcMethod setId(java.lang.String id) { - this.id = id; - return this; - } - - /** - * Media upload parameters. - * @return value or {@code null} for none - */ - public MediaUpload getMediaUpload() { - return mediaUpload; - } - - /** - * Media upload parameters. - * @param mediaUpload mediaUpload or {@code null} for none - */ - public RpcMethod setMediaUpload(MediaUpload mediaUpload) { - this.mediaUpload = mediaUpload; - return this; - } - - /** - * Ordered list of required parameters, serves as a hint to clients on how to structure their - * method signatures. The array is ordered such that the "most-significant" parameter appears - * first. - * @return value or {@code null} for none - */ - public java.util.List getParameterOrder() { - return parameterOrder; - } - - /** - * Ordered list of required parameters, serves as a hint to clients on how to structure their - * method signatures. The array is ordered such that the "most-significant" parameter appears - * first. - * @param parameterOrder parameterOrder or {@code null} for none - */ - public RpcMethod setParameterOrder(java.util.List parameterOrder) { - this.parameterOrder = parameterOrder; - return this; - } - - /** - * Description for all parameters in this method. - * @return value or {@code null} for none - */ - public java.util.Map getParameters() { - return parameters; - } - - /** - * Description for all parameters in this method. - * @param parameters parameters or {@code null} for none - */ - public RpcMethod setParameters(java.util.Map parameters) { - this.parameters = parameters; - return this; - } - - /** - * The schema for the response. - * @return value or {@code null} for none - */ - public Returns getReturns() { - return returns; - } - - /** - * The schema for the response. - * @param returns returns or {@code null} for none - */ - public RpcMethod setReturns(Returns returns) { - this.returns = returns; - return this; - } - - /** - * OAuth 2.0 scopes applicable to this method. - * @return value or {@code null} for none - */ - public java.util.List getScopes() { - return scopes; - } - - /** - * OAuth 2.0 scopes applicable to this method. - * @param scopes scopes or {@code null} for none - */ - public RpcMethod setScopes(java.util.List scopes) { - this.scopes = scopes; - return this; - } - - /** - * Whether this method supports media download. - * @return value or {@code null} for none - */ - public java.lang.Boolean getSupportsMediaDownload() { - return supportsMediaDownload; - } - - /** - * Whether this method supports media download. - * @param supportsMediaDownload supportsMediaDownload or {@code null} for none - */ - public RpcMethod setSupportsMediaDownload(java.lang.Boolean supportsMediaDownload) { - this.supportsMediaDownload = supportsMediaDownload; - return this; - } - - /** - * Whether this method supports media upload. - * @return value or {@code null} for none - */ - public java.lang.Boolean getSupportsMediaUpload() { - return supportsMediaUpload; - } - - /** - * Whether this method supports media upload. - * @param supportsMediaUpload supportsMediaUpload or {@code null} for none - */ - public RpcMethod setSupportsMediaUpload(java.lang.Boolean supportsMediaUpload) { - this.supportsMediaUpload = supportsMediaUpload; - return this; - } - - /** - * Whether this method supports patch semantics. - * @return value or {@code null} for none - */ - public java.lang.Boolean getSupportsPatch() { - return supportsPatch; - } - - /** - * Whether this method supports patch semantics. - * @param supportsPatch supportsPatch or {@code null} for none - */ - public RpcMethod setSupportsPatch(java.lang.Boolean supportsPatch) { - this.supportsPatch = supportsPatch; - return this; - } - - /** - * Whether this method supports subscriptions. - * @return value or {@code null} for none - */ - public java.lang.Boolean getSupportsSubscription() { - return supportsSubscription; - } - - /** - * Whether this method supports subscriptions. - * @param supportsSubscription supportsSubscription or {@code null} for none - */ - public RpcMethod setSupportsSubscription(java.lang.Boolean supportsSubscription) { - this.supportsSubscription = supportsSubscription; - return this; - } - - /** - * Indicates that downloads from this method should use the download service URL (i.e. - * "/download"). Only applies if the method supports media download. - * @return value or {@code null} for none - */ - public java.lang.Boolean getUseMediaDownloadService() { - return useMediaDownloadService; - } - - /** - * Indicates that downloads from this method should use the download service URL (i.e. - * "/download"). Only applies if the method supports media download. - * @param useMediaDownloadService useMediaDownloadService or {@code null} for none - */ - public RpcMethod setUseMediaDownloadService(java.lang.Boolean useMediaDownloadService) { - this.useMediaDownloadService = useMediaDownloadService; - return this; - } - - @Override - public RpcMethod set(String fieldName, Object value) { - return (RpcMethod) super.set(fieldName, value); - } - - @Override - public RpcMethod clone() { - return (RpcMethod) super.clone(); - } - - /** - * Media upload parameters. - */ - public static final class MediaUpload extends com.google.api.client.json.GenericJson { - - /** - * MIME Media Ranges for acceptable media uploads to this method. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.util.List accept; - - /** - * Maximum size of a media upload, such as "1MB", "2GB" or "3TB". - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String maxSize; - - /** - * MIME Media Ranges for acceptable media uploads to this method. - * @return value or {@code null} for none - */ - public java.util.List getAccept() { - return accept; - } - - /** - * MIME Media Ranges for acceptable media uploads to this method. - * @param accept accept or {@code null} for none - */ - public MediaUpload setAccept(java.util.List accept) { - this.accept = accept; - return this; - } - - /** - * Maximum size of a media upload, such as "1MB", "2GB" or "3TB". - * @return value or {@code null} for none - */ - public java.lang.String getMaxSize() { - return maxSize; - } - - /** - * Maximum size of a media upload, such as "1MB", "2GB" or "3TB". - * @param maxSize maxSize or {@code null} for none - */ - public MediaUpload setMaxSize(java.lang.String maxSize) { - this.maxSize = maxSize; - return this; - } - - @Override - public MediaUpload set(String fieldName, Object value) { - return (MediaUpload) super.set(fieldName, value); - } - - @Override - public MediaUpload clone() { - return (MediaUpload) super.clone(); - } - - } - - /** - * The schema for the response. - */ - public static final class Returns extends com.google.api.client.json.GenericJson { - - /** - * Schema ID for the response schema. - * The value may be {@code null}. - */ - @com.google.api.client.util.Key - private java.lang.String $ref; - - /** - * Schema ID for the response schema. - * @return value or {@code null} for none - */ - public java.lang.String get$ref() { - return $ref; - } - - /** - * Schema ID for the response schema. - * @param $ref $ref or {@code null} for none - */ - public Returns set$ref(java.lang.String $ref) { - this.$ref = $ref; - return this; - } - - @Override - public Returns set(String fieldName, Object value) { - return (Returns) super.set(fieldName, value); - } - - @Override - public Returns clone() { - return (Returns) super.clone(); - } - - } - -} diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/CachingDiscoveryProvider.java b/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/CachingDiscoveryProvider.java index 47ffa6d3..8d8b2c5b 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/CachingDiscoveryProvider.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/CachingDiscoveryProvider.java @@ -20,7 +20,6 @@ import com.google.api.server.spi.response.NotFoundException; import com.google.api.services.discovery.model.DirectoryList; import com.google.api.services.discovery.model.RestDescription; -import com.google.api.services.discovery.model.RpcDescription; import com.google.common.annotations.VisibleForTesting; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; @@ -42,7 +41,6 @@ public class CachingDiscoveryProvider implements DiscoveryProvider { private static final int CACHE_EXPIRY_MINS = 10; private final Cache restDocuments; - private final Cache rpcDocuments; private final Cache directoryByRoot; private final DiscoveryProvider delegate; @@ -56,9 +54,6 @@ public CachingDiscoveryProvider( restDocuments = CacheBuilder.newBuilder() .expireAfterAccess(cacheExpiry, cacheExpiryUnit) .build(); - rpcDocuments = CacheBuilder.newBuilder() - .expireAfterAccess(cacheExpiry, cacheExpiryUnit) - .build(); directoryByRoot = CacheBuilder.newBuilder() .expireAfterAccess(cacheExpiry, cacheExpiryUnit) .build(); @@ -75,17 +70,6 @@ public RestDescription call() throws NotFoundException, InternalServerErrorExcep }); } - @Override - public RpcDescription getRpcDocument(final String root, final String name, final String version) - throws NotFoundException, InternalServerErrorException { - return getDiscoveryDoc(rpcDocuments, root, name, version, new Callable() { - @Override - public RpcDescription call() throws NotFoundException, InternalServerErrorException { - return delegate.getRpcDocument(root, name, version); - } - }); - } - @Override public DirectoryList getDirectory(final String root) throws InternalServerErrorException { try { @@ -109,7 +93,6 @@ public DirectoryList call() throws Exception { @VisibleForTesting void cleanUp() { restDocuments.cleanUp(); - rpcDocuments.cleanUp(); directoryByRoot.cleanUp(); } diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/DiscoveryProvider.java b/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/DiscoveryProvider.java index 1d48cf50..ec5ead69 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/DiscoveryProvider.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/DiscoveryProvider.java @@ -19,7 +19,6 @@ import com.google.api.server.spi.response.NotFoundException; import com.google.api.services.discovery.model.DirectoryList; import com.google.api.services.discovery.model.RestDescription; -import com.google.api.services.discovery.model.RpcDescription; /** * An interface for generating discovery documents from API configurations. @@ -34,15 +33,6 @@ public interface DiscoveryProvider { RestDescription getRestDocument(String root, String name, String version) throws NotFoundException, InternalServerErrorException; - /** - * Gets an RPC discovery document for an API. - * - * @throws NotFoundException if the API doesn't exist - * @throws InternalServerErrorException an error takes place when getting the document - */ - RpcDescription getRpcDocument(String root, String name, String version) - throws NotFoundException, InternalServerErrorException; - /** * Gets a list of REST discovery documents hosted by the current server. This method will never * return RPC discovery documents, as everything that uses online discovery uses the REST diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/LocalDiscoveryProvider.java b/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/LocalDiscoveryProvider.java index 5f949932..fa39a9ef 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/LocalDiscoveryProvider.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/LocalDiscoveryProvider.java @@ -9,7 +9,6 @@ import com.google.api.services.discovery.model.DirectoryList; import com.google.api.services.discovery.model.DirectoryList.Items; import com.google.api.services.discovery.model.RestDescription; -import com.google.api.services.discovery.model.RpcDescription; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -43,12 +42,6 @@ public RestDescription getRestDocument(String root, String name, String version) return replaceRoot(doc, root); } - @Override - public RpcDescription getRpcDocument(String root, String name, String version) - throws NotFoundException { - throw new NotFoundException("RPC discovery is no longer supported."); - } - @Override public DirectoryList getDirectory(String root) { ensureDiscoveryResult(); diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProvider.java b/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProvider.java index 3fb84c77..f5c64037 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProvider.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProvider.java @@ -26,7 +26,6 @@ import com.google.api.services.discovery.model.ApiConfigs; import com.google.api.services.discovery.model.DirectoryList; import com.google.api.services.discovery.model.RestDescription; -import com.google.api.services.discovery.model.RpcDescription; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -67,19 +66,6 @@ public RestDescription getRestDocument(String root, String name, String version) } } - @Override - public RpcDescription getRpcDocument(String root, String name, String version) - throws NotFoundException, InternalServerErrorException { - try { - return discovery.apis() - .generateRpc(new com.google.api.services.discovery.model.ApiConfig().setConfig( - getApiConfigStringWithRoot(getApiConfigs(name, version), root))).execute(); - } catch (IOException | ApiConfigException e) { - logger.atSevere().withCause(e).log("Could not generate or cache discovery doc"); - throw new InternalServerErrorException("Internal Server Error", e); - } - } - @Override public DirectoryList getDirectory(String root) throws InternalServerErrorException { try { diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/ProxyingDiscoveryService.java b/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/ProxyingDiscoveryService.java index 1923a90f..8444b6a2 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/ProxyingDiscoveryService.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/discovery/ProxyingDiscoveryService.java @@ -23,7 +23,6 @@ import com.google.api.server.spi.response.NotFoundException; import com.google.api.services.discovery.model.DirectoryList; import com.google.api.services.discovery.model.RestDescription; -import com.google.api.services.discovery.model.RpcDescription; import com.google.common.annotations.VisibleForTesting; import com.google.common.flogger.FluentLogger; import javax.servlet.http.HttpServletRequest; @@ -64,16 +63,6 @@ public RestDescription getRestDocument(HttpServletRequest request, @Named("api") return discoveryProvider.getRestDocument(getActualRoot(request), name, version); } - @ApiMethod( - name = "apis.getRpc", - path = "apis/{api}/{version}/rpc" - ) - public RpcDescription getRpcDocument(HttpServletRequest request, @Named("api") String name, - @Named("version") String version) throws NotFoundException, InternalServerErrorException { - checkIsInitialized(); - return discoveryProvider.getRpcDocument(getActualRoot(request), name, version); - } - @ApiMethod( name = "apis.list", path = "apis" diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/CachingDiscoveryProviderTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/CachingDiscoveryProviderTest.java index 61b8b66c..4f6f39da 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/CachingDiscoveryProviderTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/CachingDiscoveryProviderTest.java @@ -25,7 +25,6 @@ import com.google.api.server.spi.response.NotFoundException; import com.google.api.services.discovery.model.DirectoryList; import com.google.api.services.discovery.model.RestDescription; -import com.google.api.services.discovery.model.RpcDescription; import com.google.common.collect.ImmutableList; import org.junit.Test; @@ -46,9 +45,6 @@ public class CachingDiscoveryProviderTest { private static final RestDescription REST_DOC = new RestDescription() .setName(NAME) .setVersion(VERSION); - private static final RpcDescription RPC_DOC = new RpcDescription() - .setName(NAME) - .setVersion(VERSION); private static final DirectoryList DIRECTORY = new DirectoryList() .setItems(ImmutableList.of(new DirectoryList.Items() .setName(NAME) @@ -122,72 +118,6 @@ public void getRestDocument_runtimeException() throws Exception { } } - @Test - public void getRpcDocument() throws Exception { - CachingDiscoveryProvider provider = createNonExpiringProvider(); - setupNormalMockDelegate(); - - // Make the same call twice and ensure that the delegate is only called once. - assertThat(provider.getRpcDocument(ROOT, NAME, VERSION)).isEqualTo(RPC_DOC); - assertThat(provider.getRpcDocument(ROOT, NAME, VERSION)).isEqualTo(RPC_DOC); - verify(delegate, times(1)).getRpcDocument(ROOT, NAME, VERSION); - } - - @Test - public void getRpcDocument_cacheExpiry() throws Exception { - CachingDiscoveryProvider provider = createShortExpiringProvider(); - setupNormalMockDelegate(); - - assertThat(provider.getRpcDocument(ROOT, NAME, VERSION)).isEqualTo(RPC_DOC); - - Thread.sleep(1000); - provider.cleanUp(); - - assertThat(provider.getRpcDocument(ROOT, NAME, VERSION)).isEqualTo(RPC_DOC); - verify(delegate, times(2)).getRpcDocument(ROOT, NAME, VERSION); - } - - @Test - public void getRpcDocument_notFound() throws Exception { - CachingDiscoveryProvider provider = createNonExpiringProvider(); - when(delegate.getRpcDocument(ROOT, NAME, VERSION)).thenThrow(new NotFoundException("")); - - try { - provider.getRpcDocument(ROOT, NAME, VERSION); - fail("expected NotFoundException"); - } catch (NotFoundException e) { - // expected - } - } - - @Test - public void getRpcDocument_internalServerError() throws Exception { - CachingDiscoveryProvider provider = createNonExpiringProvider(); - when(delegate.getRpcDocument(ROOT, NAME, VERSION)) - .thenThrow(new InternalServerErrorException("")); - - try { - provider.getRpcDocument(ROOT, NAME, VERSION); - fail("expected InternalServerErrorException"); - } catch (InternalServerErrorException e) { - // expected - } - } - - @Test - public void getRpcDocument_runtimeException() throws Exception { - CachingDiscoveryProvider provider = createNonExpiringProvider(); - when(delegate.getRpcDocument(ROOT, NAME, VERSION)) - .thenThrow(new RuntimeException("")); - - try { - provider.getRpcDocument(ROOT, NAME, VERSION); - fail("expected InternalServerErrorException"); - } catch (InternalServerErrorException e) { - // expected - } - } - @Test public void getDirectory() throws Exception { CachingDiscoveryProvider provider = createNonExpiringProvider(); @@ -253,7 +183,6 @@ private CachingDiscoveryProvider createProvider(long cacheExpiry, TimeUnit cache private void setupNormalMockDelegate() throws Exception { when(delegate.getRestDocument(ROOT, NAME, VERSION)).thenReturn(REST_DOC); - when(delegate.getRpcDocument(ROOT, NAME, VERSION)).thenReturn(RPC_DOC); when(delegate.getDirectory(ROOT)).thenReturn(DIRECTORY); } } diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/LocalDiscoveryProviderTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/LocalDiscoveryProviderTest.java index 1b05ccd4..9beeb4e3 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/LocalDiscoveryProviderTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/LocalDiscoveryProviderTest.java @@ -67,16 +67,6 @@ public void getRestDocument_NotFoundException() { } } - @Test - public void getRpcDocument() { - try { - provider.getRpcDocument(ROOT, NAME, VERSION); - fail("expected NotFoundException"); - } catch (NotFoundException expected) { - // expected - } - } - @Test public void getDirectory() throws Exception { DirectoryList directory = provider.getDirectory(ROOT); diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProviderTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProviderTest.java index bb8288ff..3788d51c 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProviderTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProviderTest.java @@ -34,11 +34,9 @@ import com.google.api.services.discovery.Discovery.Apis; import com.google.api.services.discovery.Discovery.Apis.GenerateDirectory; import com.google.api.services.discovery.Discovery.Apis.GenerateRest; -import com.google.api.services.discovery.Discovery.Apis.GenerateRpc; import com.google.api.services.discovery.model.ApiConfigs; import com.google.api.services.discovery.model.DirectoryList; import com.google.api.services.discovery.model.RestDescription; -import com.google.api.services.discovery.model.RpcDescription; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; @@ -66,9 +64,6 @@ public class ProxyingDiscoveryProviderTest { private static final RestDescription REST_DOC = new RestDescription() .setName(NAME) .setVersion(V1); - private static final RpcDescription RPC_DOC = new RpcDescription() - .setName(NAME) - .setVersion(V1); private static final DirectoryList DIRECTORY = new DirectoryList() .setItems(ImmutableList.of(new DirectoryList.Items() .setName(NAME) @@ -81,7 +76,6 @@ public class ProxyingDiscoveryProviderTest { @Mock private Discovery discovery; @Mock private Apis apis; @Mock private GenerateRest restRequest; - @Mock private GenerateRpc rpcRequest; @Mock private GenerateDirectory directoryRequest; @Mock private ApiConfigWriter configWriter; @@ -106,8 +100,6 @@ public void setUp() throws Exception { when(discovery.apis()).thenReturn(apis); when(apis.generateRest(any(com.google.api.services.discovery.model.ApiConfig.class))) .thenReturn(restRequest); - when(apis.generateRpc(any(com.google.api.services.discovery.model.ApiConfig.class))) - .thenReturn(rpcRequest); when(apis.generateDirectory(any(ApiConfigs.class))) .thenReturn(directoryRequest); // Used by individual document tests @@ -156,39 +148,6 @@ public void getRestDocument_internalServerError() throws Exception { } } - @Test - public void getRpcDocument() throws Exception { - when(rpcRequest.execute()).thenReturn(RPC_DOC); - - RpcDescription actual = provider.getRpcDocument(REWRITTEN_ROOT, NAME, V1); - - assertThat(actual).isEqualTo(RPC_DOC); - verify(apis).generateRpc( - new com.google.api.services.discovery.model.ApiConfig().setConfig(V1_JSON_API_CONFIG)); - } - - @Test - public void getRpcDocument_notFound() throws Exception { - try { - provider.getRpcDocument(REWRITTEN_ROOT, WRONG_NAME, V1); - fail("expected NotFoundException"); - } catch (NotFoundException e) { - // expected - } - } - - @Test - public void getRpcDocument_internalServerError() throws Exception { - when(rpcRequest.execute()).thenThrow(new IOException()); - - try { - provider.getRpcDocument(REWRITTEN_ROOT, NAME, V1); - fail("expected InternalServerErrorException"); - } catch (InternalServerErrorException e) { - // expected - } - } - @Test public void getDirectory() throws Exception { when(directoryRequest.execute()).thenReturn(DIRECTORY); diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryServiceTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryServiceTest.java index 058c7537..0f150d5a 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryServiceTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryServiceTest.java @@ -23,7 +23,6 @@ import com.google.api.server.spi.response.NotFoundException; import com.google.api.services.discovery.model.DirectoryList; import com.google.api.services.discovery.model.RestDescription; -import com.google.api.services.discovery.model.RpcDescription; import com.google.common.collect.ImmutableList; import org.junit.Test; @@ -46,9 +45,6 @@ public class ProxyingDiscoveryServiceTest { private static final RestDescription REST_DOC = new RestDescription() .setName(API_NAME) .setVersion(API_VERSION); - private static final RpcDescription RPC_DOC = new RpcDescription() - .setName(API_NAME) - .setVersion(API_VERSION); private static final DirectoryList DIRECTORY = new DirectoryList() .setItems(ImmutableList.of(new DirectoryList.Items() .setName(API_NAME) @@ -108,58 +104,6 @@ public void getRestDocument_uninitialized() throws Exception { } } - @Test - public void getRpcDocument() throws Exception { - ProxyingDiscoveryService discoveryService = createDiscoveryService(true); - when(provider.getRpcDocument(SERVER_ROOT, API_NAME, API_VERSION)).thenReturn(RPC_DOC); - - RpcDescription actual = discoveryService.getRpcDocument( - createRequest("discovery/v1/apis/tictactoe/v1/rpc"), API_NAME, API_VERSION); - - assertThat(actual).isEqualTo(RPC_DOC); - } - - @Test - public void getRpcDocument_notFound() throws Exception { - ProxyingDiscoveryService discoveryService = createDiscoveryService(true); - when(provider.getRpcDocument(SERVER_ROOT, API_NAME, API_VERSION)) - .thenThrow(new NotFoundException("")); - - try { - discoveryService.getRpcDocument( - createRequest("discovery/v1/apis/tictactoe/v1/rpc"), API_NAME, API_VERSION); - fail("expected NotFoundException"); - } catch (NotFoundException e) { - // expected - } - } - - @Test - public void getRpcDocument_internalServerError() throws Exception { - ProxyingDiscoveryService discoveryService = createDiscoveryService(true); - when(provider.getRpcDocument(SERVER_ROOT, API_NAME, API_VERSION)) - .thenThrow(new InternalServerErrorException("")); - - try { - discoveryService.getRpcDocument( - createRequest("discovery/v1/apis/tictactoe/v1/rest"), API_NAME, API_VERSION); - fail("expected InternalServerErrorException"); - } catch (InternalServerErrorException e) { - // expected - } - } - - @Test - public void getRpcDocument_uninitialized() throws Exception { - try { - ProxyingDiscoveryService discoveryService = createDiscoveryService(false); - discoveryService.getRpcDocument(null /* request */, null /* name */, null /* verson */); - fail("expected InternalServerErrorException"); - } catch (InternalServerErrorException e) { - // expected - } - } - @Test public void getApiList() throws Exception { ProxyingDiscoveryService discoveryService = createDiscoveryService(true); From 262a156cf18580f4ecc334ee52b9f031d433ccc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Denis?= Date: Fri, 25 Oct 2019 19:10:06 +0200 Subject: [PATCH 06/12] Update Mockito calls for deprecations --- .../api/server/spi/BackendPropertiesTest.java | 2 +- .../server/spi/ConfiguredObjectMapperTest.java | 10 +++++----- .../spi/auth/EndpointsAuthenticatorTest.java | 2 +- .../auth/GoogleAppEngineAuthenticatorTest.java | 2 +- .../spi/auth/GoogleJwtAuthenticatorTest.java | 2 +- .../auth/GoogleOAuth2AuthenticatorTest.java | 2 +- .../server/spi/config/ApiConfigLoaderTest.java | 2 +- .../ApiClassAnnotationConfigTest.java | 18 +++++++++--------- .../ApiMethodAnnotationConfigTest.java | 2 +- .../spi/config/model/ApiClassConfigTest.java | 2 +- .../config/model/ApiParameterConfigTest.java | 2 +- .../CachingDiscoveryProviderTest.java | 2 +- .../discovery/LocalDiscoveryProviderTest.java | 10 +++++----- .../ProxyingDiscoveryProviderTest.java | 10 +++++----- .../ProxyingDiscoveryServiceTest.java | 2 +- .../spi/dispatcher/PathDispatcherTest.java | 2 +- .../api/server/spi/request/AttributeTest.java | 2 +- .../api/server/spi/request/AuthTest.java | 2 +- .../request/ServletRequestParamReaderTest.java | 2 +- .../api/server/spi/BaseSystemServiceTest.java | 2 +- 20 files changed, 40 insertions(+), 40 deletions(-) diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/BackendPropertiesTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/BackendPropertiesTest.java index 5dfec76b..5fe7d65d 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/BackendPropertiesTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/BackendPropertiesTest.java @@ -23,7 +23,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; /** * Tests for {@link BackendProperties}. diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/ConfiguredObjectMapperTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/ConfiguredObjectMapperTest.java index 1200fec0..7b3ac00d 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/ConfiguredObjectMapperTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/ConfiguredObjectMapperTest.java @@ -19,7 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.when; @@ -38,7 +38,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.Map; @@ -119,9 +119,9 @@ public void testBuildWithModules_oneWithAll() { doModuleSetup(moduleB, "moduleB"); doModuleSetup(moduleC, "moduleC"); builder.addRegisteredModules(ImmutableList.of(moduleA, moduleB, moduleC)).build(); - Mockito.verify(moduleA, atLeastOnce()).setupModule(any(SetupContext.class)); - Mockito.verify(moduleB, atLeastOnce()).setupModule(any(SetupContext.class)); - Mockito.verify(moduleC, atLeastOnce()).setupModule(any(SetupContext.class)); + Mockito.verify(moduleA, atLeastOnce()).setupModule(any()); + Mockito.verify(moduleB, atLeastOnce()).setupModule(any()); + Mockito.verify(moduleC, atLeastOnce()).setupModule(any()); assertEquals(1, cache.size()); } diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/EndpointsAuthenticatorTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/EndpointsAuthenticatorTest.java index f9ce9db5..ec22cc2a 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/EndpointsAuthenticatorTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/EndpointsAuthenticatorTest.java @@ -27,7 +27,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.mock.web.MockHttpServletRequest; /** diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleAppEngineAuthenticatorTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleAppEngineAuthenticatorTest.java index 857b4e52..6eec4554 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleAppEngineAuthenticatorTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleAppEngineAuthenticatorTest.java @@ -34,7 +34,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.mock.web.MockHttpServletRequest; import javax.servlet.http.HttpServletRequest; diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleJwtAuthenticatorTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleJwtAuthenticatorTest.java index 7b462456..a7d8bad4 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleJwtAuthenticatorTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleJwtAuthenticatorTest.java @@ -32,7 +32,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.mock.web.MockHttpServletRequest; import java.io.IOException; diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleOAuth2AuthenticatorTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleOAuth2AuthenticatorTest.java index e052c7a9..a82420ad 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleOAuth2AuthenticatorTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/GoogleOAuth2AuthenticatorTest.java @@ -32,7 +32,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.mock.web.MockHttpServletRequest; /** diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/ApiConfigLoaderTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/ApiConfigLoaderTest.java index 700251c7..bb88ac90 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/ApiConfigLoaderTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/ApiConfigLoaderTest.java @@ -34,7 +34,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; /** * Tests for {@link ApiConfigLoader}. diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiClassAnnotationConfigTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiClassAnnotationConfigTest.java index f5305aae..266913d8 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiClassAnnotationConfigTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiClassAnnotationConfigTest.java @@ -31,7 +31,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.Arrays; @@ -58,7 +58,7 @@ public void testSetResourceIfNotEmpty() { @Test public void testSetResourceIfNotEmpty_empty() { annotationConfig.setResourceIfNotEmpty(""); - Mockito.verifyZeroInteractions(config); + Mockito.verifyNoInteractions(config); annotationConfig.setResourceIfNotEmpty("bleh"); annotationConfig.setResourceIfNotEmpty(""); @@ -80,7 +80,7 @@ public void testSetAuthLevelIfSpecified() throws Exception { @Test public void testSetAuthLevelIfSpecified_unspecified() throws Exception { annotationConfig.setAuthLevelIfSpecified(AuthLevel.UNSPECIFIED); - Mockito.verifyZeroInteractions(config); + Mockito.verifyNoInteractions(config); } @Test @@ -100,11 +100,11 @@ public void testSetScopesIfSpecified_empty() throws Exception { @Test public void testSetScopesIfSpecified_unspecified() throws Exception { annotationConfig.setScopesIfSpecified(null); - Mockito.verifyZeroInteractions(config); + Mockito.verifyNoInteractions(config); String[] unspecified = {Api.UNSPECIFIED_STRING_FOR_LIST}; annotationConfig.setScopesIfSpecified(unspecified); - Mockito.verifyZeroInteractions(config); + Mockito.verifyNoInteractions(config); String[] scopes = { "bleh", "more bleh" }; annotationConfig.setScopesIfSpecified(scopes); @@ -130,11 +130,11 @@ public void testSetAudiencesIfSpecified_empty() throws Exception { @Test public void testSetAudiencesIfSpecified_unspecified() throws Exception { annotationConfig.setAudiencesIfSpecified(null); - Mockito.verifyZeroInteractions(config); + Mockito.verifyNoInteractions(config); String[] unspecified = {Api.UNSPECIFIED_STRING_FOR_LIST}; annotationConfig.setAudiencesIfSpecified(unspecified); - Mockito.verifyZeroInteractions(config); + Mockito.verifyNoInteractions(config); String[] audiences = {"bleh", "more bleh"}; annotationConfig.setAudiencesIfSpecified(audiences); @@ -160,11 +160,11 @@ public void testSetClientIdsIfSpecified_empty() throws Exception { @Test public void testSetClientIdsIfSpecified_unspecified() throws Exception { annotationConfig.setClientIdsIfSpecified(null); - Mockito.verifyZeroInteractions(config); + Mockito.verifyNoInteractions(config); String[] unspecified = {Api.UNSPECIFIED_STRING_FOR_LIST}; annotationConfig.setClientIdsIfSpecified(unspecified); - Mockito.verifyZeroInteractions(config); + Mockito.verifyNoInteractions(config); String[] clientIds = {"bleh", "more bleh"}; annotationConfig.setClientIdsIfSpecified(clientIds); diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiMethodAnnotationConfigTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiMethodAnnotationConfigTest.java index 1e9101cd..c97dfff1 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiMethodAnnotationConfigTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiMethodAnnotationConfigTest.java @@ -44,7 +44,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.Arrays; import java.util.Collections; diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiClassConfigTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiClassConfigTest.java index be11d584..adbb3bd3 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiClassConfigTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiClassConfigTest.java @@ -32,7 +32,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Method; import java.util.Date; diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiParameterConfigTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiParameterConfigTest.java index be1d1344..4c64c5f3 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiParameterConfigTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiParameterConfigTest.java @@ -31,7 +31,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.Collections; diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/CachingDiscoveryProviderTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/CachingDiscoveryProviderTest.java index 4f6f39da..26151eab 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/CachingDiscoveryProviderTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/CachingDiscoveryProviderTest.java @@ -30,7 +30,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.concurrent.TimeUnit; diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/LocalDiscoveryProviderTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/LocalDiscoveryProviderTest.java index 9beeb4e3..0e067796 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/LocalDiscoveryProviderTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/LocalDiscoveryProviderTest.java @@ -2,9 +2,9 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyListOf; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import com.google.api.server.spi.config.model.ApiConfig; @@ -24,7 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; /** * Tests for {@link LocalDiscoveryProvider}. @@ -43,7 +43,7 @@ public class LocalDiscoveryProviderTest { public void setUp() { provider = new LocalDiscoveryProvider(ImmutableList.of(), generator, repository); when(generator.writeDiscovery( - anyListOf(ApiConfig.class), any(DiscoveryContext.class), eq(repository))) + anyList(), any(), eq(repository))) .thenReturn(Result.builder().setDiscoveryDocs( ImmutableMap.of(new ApiKey(NAME, VERSION, null /* root */), getPlaceholderDoc())) .setDirectory(getPlaceholderDirectory()) diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProviderTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProviderTest.java index 3788d51c..4cd968c8 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProviderTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryProviderTest.java @@ -17,8 +17,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -46,7 +46,7 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentMatcher; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.io.IOException; import java.util.Set; @@ -98,9 +98,9 @@ public void setUp() throws Exception { // Setup standard mocks on our discovery API. when(discovery.apis()).thenReturn(apis); - when(apis.generateRest(any(com.google.api.services.discovery.model.ApiConfig.class))) + when(apis.generateRest(any())) .thenReturn(restRequest); - when(apis.generateDirectory(any(ApiConfigs.class))) + when(apis.generateDirectory(any())) .thenReturn(directoryRequest); // Used by individual document tests when(configWriter.writeConfig(withConfigs(rewrittenApiConfig1, rewrittenApiConfig2))) diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryServiceTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryServiceTest.java index 0f150d5a..0a3be544 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryServiceTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/discovery/ProxyingDiscoveryServiceTest.java @@ -28,7 +28,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.mock.web.MockHttpServletRequest; /** diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/dispatcher/PathDispatcherTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/dispatcher/PathDispatcherTest.java index 90562830..de293842 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/dispatcher/PathDispatcherTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/dispatcher/PathDispatcherTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.io.IOException; diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/request/AttributeTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/request/AttributeTest.java index b87b1bc2..7e107833 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/request/AttributeTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/request/AttributeTest.java @@ -29,7 +29,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.mock.web.MockHttpServletRequest; import javax.servlet.ServletConfig; diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/request/AuthTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/request/AuthTest.java index e1741447..55d17869 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/request/AuthTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/request/AuthTest.java @@ -37,7 +37,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.mock.web.MockHttpServletRequest; import java.util.List; diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/request/ServletRequestParamReaderTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/request/ServletRequestParamReaderTest.java index 3ff35b06..ea814782 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/request/ServletRequestParamReaderTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/request/ServletRequestParamReaderTest.java @@ -63,7 +63,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; /** * Tests for {@link ServletRequestParamReader}. diff --git a/test-utils/src/main/java/com/google/api/server/spi/BaseSystemServiceTest.java b/test-utils/src/main/java/com/google/api/server/spi/BaseSystemServiceTest.java index 0fb795fe..fd0e2d4c 100644 --- a/test-utils/src/main/java/com/google/api/server/spi/BaseSystemServiceTest.java +++ b/test-utils/src/main/java/com/google/api/server/spi/BaseSystemServiceTest.java @@ -18,7 +18,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.argThat; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.times; import com.google.api.server.spi.config.Api; From 1d8e7226749f1583c4483335c54dfa04bb7fda85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Denis?= Date: Fri, 25 Oct 2019 19:15:36 +0200 Subject: [PATCH 07/12] Remove restricted servlet init param and related peer authenticators --- .../server/spi/guice/EndpointsModuleTest.java | 7 - endpoints-framework/build.gradle | 1 - .../com/google/api/server/spi/PeerAuth.java | 79 -------- .../spi/ServletInitializationParameters.java | 32 --- .../spi/auth/EndpointsPeerAuthenticator.java | 140 ------------- .../com/google/api/server/spi/config/Api.java | 7 - .../api/server/spi/config/ApiClass.java | 6 - .../api/server/spi/config/ApiMethod.java | 5 - .../server/spi/config/PeerAuthenticator.java | 33 ---- .../api/server/spi/config/Singleton.java | 2 +- .../annotationreader/AnnotationUtil.java | 6 - .../annotationreader/ApiAnnotationConfig.java | 8 - .../ApiClassAnnotationConfig.java | 8 - .../ApiConfigAnnotationReader.java | 8 - .../ApiMethodAnnotationConfig.java | 8 - .../spi/config/model/ApiClassConfig.java | 18 +- .../server/spi/config/model/ApiConfig.java | 15 +- .../spi/config/model/ApiMethodConfig.java | 17 +- .../config/validation/ApiConfigValidator.java | 1 - .../api/server/spi/request/Attribute.java | 5 - .../google/api/server/spi/PeerAuthTest.java | 142 -------------- .../ServletInitializationParametersTest.java | 43 ++-- .../auth/EndpointsPeerAuthenticatorTest.java | 184 ------------------ .../ApiAnnotationConfigTest.java | 17 -- .../ApiClassAnnotationConfigTest.java | 19 +- .../ApiConfigAnnotationReaderTest.java | 53 ++--- .../ApiMethodAnnotationConfigTest.java | 31 --- .../spi/config/model/ApiConfigTest.java | 4 - .../spi/config/model/ApiMethodConfigTest.java | 2 +- .../validation/ApiConfigValidatorTest.java | 68 ------- .../api/server/spi/request/AttributeTest.java | 30 +-- .../api/server/spi/testing/Endpoint1.java | 4 +- .../spi/testing/FailPeerAuthenticator.java | 39 ---- .../spi/testing/PassPeerAuthenticator.java | 41 ---- 34 files changed, 45 insertions(+), 1038 deletions(-) delete mode 100644 endpoints-framework/src/main/java/com/google/api/server/spi/PeerAuth.java delete mode 100644 endpoints-framework/src/main/java/com/google/api/server/spi/auth/EndpointsPeerAuthenticator.java delete mode 100644 endpoints-framework/src/main/java/com/google/api/server/spi/config/PeerAuthenticator.java delete mode 100644 endpoints-framework/src/test/java/com/google/api/server/spi/PeerAuthTest.java delete mode 100644 endpoints-framework/src/test/java/com/google/api/server/spi/auth/EndpointsPeerAuthenticatorTest.java delete mode 100644 test-utils/src/main/java/com/google/api/server/spi/testing/FailPeerAuthenticator.java delete mode 100644 test-utils/src/main/java/com/google/api/server/spi/testing/PassPeerAuthenticator.java diff --git a/endpoints-framework-guice/src/test/java/com/google/api/server/spi/guice/EndpointsModuleTest.java b/endpoints-framework-guice/src/test/java/com/google/api/server/spi/guice/EndpointsModuleTest.java index 79f18087..83353df4 100644 --- a/endpoints-framework-guice/src/test/java/com/google/api/server/spi/guice/EndpointsModuleTest.java +++ b/endpoints-framework-guice/src/test/java/com/google/api/server/spi/guice/EndpointsModuleTest.java @@ -54,7 +54,6 @@ public class EndpointsModuleTest { private static final ServletInitializationParameters INIT_PARAMETERS = ServletInitializationParameters.builder() .addServiceClasses(SERVICES) - .setRestricted(false) .build(); private EndpointsModule module; @@ -82,8 +81,6 @@ public void testConfigureEndpoints_withInterceptor() { assertEquals("Servlet not bound.", 1, visitor.linkedServlets.size()); LinkedServletBinding servletBinding = visitor.linkedServlets.get(0); assertEquals("URL pattern does not match", URL_PATTERN, servletBinding.getPattern()); - assertEquals("Wrong initialization parameter provided", "false", - servletBinding.getInitParams().get("restricted")); assertNotNull("SystemService named provider not found.", visitor.systemServiceProvider); ServiceMap serviceMap = (ServiceMap) visitor.systemServiceProvider.getProvider().get(); @@ -105,8 +102,6 @@ public void testConfigureEndpoints_withoutInterceptor() { assertEquals("Servlet not bound.", 1, visitor.linkedServlets.size()); LinkedServletBinding servletBinding = visitor.linkedServlets.get(0); assertEquals("URL pattern does not match", URL_PATTERN, servletBinding.getPattern()); - assertEquals("Wrong initialization parameter provided", "false", - servletBinding.getInitParams().get("restricted")); assertNotNull("SystemService named provider not found.", visitor.systemServiceProvider); ServiceMap serviceMap = (ServiceMap) visitor.systemServiceProvider.getProvider().get(); @@ -212,8 +207,6 @@ protected void configureServlets() { assertEquals("Servlet not bound.", 1, visitor.linkedServlets.size()); LinkedServletBinding servletBinding = visitor.linkedServlets.get(0); assertEquals("URL pattern does not match", URL_PATTERN, servletBinding.getPattern()); - assertEquals("Wrong initialization parameter provided", "true", - servletBinding.getInitParams().get("restricted")); assertNotNull("SystemService named provider not found.", visitor.systemServiceProvider); ServiceMap serviceMap = (ServiceMap) visitor.systemServiceProvider.getProvider().get(); diff --git a/endpoints-framework/build.gradle b/endpoints-framework/build.gradle index 7757ea9c..7cf58f8b 100644 --- a/endpoints-framework/build.gradle +++ b/endpoints-framework/build.gradle @@ -43,7 +43,6 @@ def annotations = [ "ApiTransformer.java", "Authenticator.java", "DefaultValue.java", - "PeerAuthenticator.java", "AuthLevel.java", "Transformer.java", ] diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/PeerAuth.java b/endpoints-framework/src/main/java/com/google/api/server/spi/PeerAuth.java deleted file mode 100644 index 0cfb9cef..00000000 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/PeerAuth.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2016 Google Inc. 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 com.google.api.server.spi; - -import com.google.api.server.spi.auth.EndpointsPeerAuthenticator; -import com.google.api.server.spi.config.PeerAuthenticator; -import com.google.api.server.spi.config.Singleton; -import com.google.api.server.spi.config.model.ApiMethodConfig; -import com.google.api.server.spi.request.Attribute; -import com.google.common.annotations.VisibleForTesting; - -import javax.servlet.http.HttpServletRequest; - -/** - * Utilities used to do peer authorization. - */ -public class PeerAuth { - private static final Singleton.Instantiator INSTANTIATOR - = new Singleton.Instantiator(new EndpointsPeerAuthenticator()); - - /** - * Must be used to instantiate new {@link PeerAuthenticator}s to honor - * {@link com.google.api.server.spi.config.Singleton} contract. - * - * @return a new instance of clazz, or an existing one if clazz is annotated with @{@link - * com.google.api.server.spi.config.Singleton} - */ - public static PeerAuthenticator instantiatePeerAuthenticator(Class clazz) { - return INSTANTIATOR.getInstanceOrDefault(clazz); - } - - private final HttpServletRequest request; - private final Attribute attr; - private final ApiMethodConfig config; - - @VisibleForTesting - PeerAuth(HttpServletRequest request) { - this.request = request; - attr = Attribute.from(request); - config = attr.get(Attribute.API_METHOD_CONFIG); - } - - static PeerAuth from(HttpServletRequest request) { - return new PeerAuth(request); - } - - @VisibleForTesting - Iterable getPeerAuthenticatorInstances() { - return INSTANTIATOR.getInstancesOrDefault(config.getPeerAuthenticators()); - } - - boolean authorizePeer() { - if (!attr.isEnabled(Attribute.RESTRICT_SERVLET)) { - return true; - } - Iterable peerAuthenticators = getPeerAuthenticatorInstances(); - if (peerAuthenticators != null) { - for (PeerAuthenticator peerAuthenticator : peerAuthenticators) { - if (!peerAuthenticator.authenticate(request)) { - return false; - } - } - } - return true; - } -} diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/ServletInitializationParameters.java b/endpoints-framework/src/main/java/com/google/api/server/spi/ServletInitializationParameters.java index 6e5b78d5..3a2b3f4e 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/ServletInitializationParameters.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/ServletInitializationParameters.java @@ -58,14 +58,6 @@ public String apply(Class clazz) { */ public abstract ImmutableSet> getServiceClasses(); - /** - * Returns if the SPI servlet is restricted. - * - * @deprecated No longer serves any purpose and will be removed in a future release - */ - @Deprecated - public abstract boolean isServletRestricted(); - /** * Returns if client ID whitelisting is enabled. */ @@ -101,7 +93,6 @@ public String apply(Class clazz) { public static Builder builder() { return new AutoValue_ServletInitializationParameters.Builder() - .setServletRestricted(true) .setClientIdWhitelistEnabled(true) .setIllegalArgumentBackendError(false) .setExceptionCompatibilityEnabled(true) @@ -138,24 +129,6 @@ public Builder addServiceClasses(Iterable> serviceClasses) { */ public abstract Builder setServiceClasses(ImmutableSet> clazzes); - /** - * Sets if the servlet is restricted. Defaults to {@code true}. - * - * @deprecated No longer serves any purpose and will be removed in a future release - */ - @Deprecated - public abstract Builder setServletRestricted(boolean servletRestricted); - - /** - * Sets if the servlet is restricted. Retained for API compatibility. - * - * @deprecated Retained for API compatibility - */ - @Deprecated - public Builder setRestricted(boolean servletRestricted) { - return setServletRestricted(servletRestricted); - } - /** * Sets if the client ID whitelist is enabled, defaulting to {@code true}. */ @@ -211,10 +184,6 @@ public static ServletInitializationParameters fromServletConfig( builder.addServiceClass(getClassForName(serviceClassName, classLoader)); } } - String servletRestricted = config.getInitParameter(RESTRICTED); - if (servletRestricted != null) { - builder.setServletRestricted(parseBoolean(servletRestricted, RESTRICTED)); - } String clientIdWhitelist = config.getInitParameter(CLIENT_ID_WHITELIST_ENABLED); if (clientIdWhitelist != null) { builder.setClientIdWhitelistEnabled( @@ -269,7 +238,6 @@ private static Class getClassForName(String className, ClassLoader classLoade public Map asMap() { return new HashMap() {{ put(SERVICES, CSV_JOINER.join(Iterables.transform(getServiceClasses(), CLASS_TO_NAME))); - put(RESTRICTED, Boolean.toString(isServletRestricted())); put(CLIENT_ID_WHITELIST_ENABLED, Boolean.toString(isClientIdWhitelistEnabled())); put(ILLEGAL_ARGUMENT_BACKEND_ERROR, Boolean.toString(isIllegalArgumentBackendError())); put(EXCEPTION_COMPATIBILITY, Boolean.toString(isExceptionCompatibilityEnabled())); diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/auth/EndpointsPeerAuthenticator.java b/endpoints-framework/src/main/java/com/google/api/server/spi/auth/EndpointsPeerAuthenticator.java deleted file mode 100644 index b803cc76..00000000 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/auth/EndpointsPeerAuthenticator.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2016 Google Inc. 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 com.google.api.server.spi.auth; - -import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken; -import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; -import com.google.api.client.googleapis.auth.oauth2.GooglePublicKeysManager; -import com.google.api.server.spi.Client; -import com.google.api.server.spi.EnvUtil; -import com.google.api.server.spi.config.PeerAuthenticator; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableSet; - -import com.google.common.flogger.FluentLogger; -import java.io.IOException; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.logging.Logger; - -import javax.servlet.http.HttpServletRequest; - -/** - * The default peer authenticator. It verify the request is from Google Cloud Endpoints frontend. It - * is different from EndpointsAuthenticator, which authenticates the end user. - */ -public class EndpointsPeerAuthenticator implements PeerAuthenticator { - @VisibleForTesting - static final String ISSUER = "https://www.cloudendpointsapis.com"; - @VisibleForTesting - static final String SIGNER = "cloud-endpoints-signer@system.gserviceaccount.com"; - @VisibleForTesting - static final String HEADER_APPENGINE_PEER = "X-Appengine-Peer"; - @VisibleForTesting - static final String APPENGINE_PEER = "apiserving"; - @VisibleForTesting - static final String HEADER_PEER_AUTHORIZATION = "Peer-Authorization"; - - private static final String PUBLIC_CERT_URL = - "https://www.googleapis.com/service_accounts/v1/metadata/x509/" + SIGNER; - private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - private static final ImmutableSet localHostAddresses = getLocalHostAddresses(); - - private final GoogleJwtAuthenticator jwtAuthenticator; - - private static ImmutableSet getLocalHostAddresses() { - ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); - try { - builder.add(InetAddress.getLocalHost().getHostAddress()); - } catch (IOException e) { - // try next. - } - try { - builder.add(InetAddress.getByName(null).getHostAddress()); - } catch (IOException e) { - // try next. - } - try { - for (InetAddress inetAddress : InetAddress.getAllByName("localhost")) { - builder.add(inetAddress.getHostAddress()); - } - } catch (IOException e) { - // check at the end. - } - ImmutableSet localHostSet = builder.build(); - if (localHostSet.isEmpty()) { - logger.atWarning().log("Unable to lookup local addresses."); - } - return localHostSet; - } - - public EndpointsPeerAuthenticator() { - Client client = Client.getInstance(); - GooglePublicKeysManager keyManager = new GooglePublicKeysManager.Builder( - client.getHttpTransport(), client.getJsonFactory()).setPublicCertsEncodedUrl( - PUBLIC_CERT_URL).build(); - GoogleIdTokenVerifier verifier = - new GoogleIdTokenVerifier.Builder(keyManager).setIssuer(ISSUER).build(); - jwtAuthenticator = new GoogleJwtAuthenticator(verifier); - } - - @VisibleForTesting - public EndpointsPeerAuthenticator(GoogleJwtAuthenticator jwtAuthenticator) { - this.jwtAuthenticator = jwtAuthenticator; - } - - @Override - public boolean authenticate(HttpServletRequest request) { - // Preserve current check for App Engine Env. - if (EnvUtil.isRunningOnAppEngine()) { - return APPENGINE_PEER.equals(request.getHeader(HEADER_APPENGINE_PEER)); - } - - // Skip peer verification for localhost request. - if (localHostAddresses.contains(request.getRemoteAddr())) { - logger.atFine().log("Skip endpoints peer verication from localhost."); - return true; - } - // Verify peer token, signer and audience. - GoogleIdToken idToken = - jwtAuthenticator.verifyToken(request.getHeader(HEADER_PEER_AUTHORIZATION)); - if (idToken == null || !SIGNER.equals(idToken.getPayload().getEmail()) - || !matchHostAndPort(idToken, request)) { - return false; - } - return true; - } - - private boolean matchHostAndPort(GoogleIdToken idToken, HttpServletRequest request) { - URL urlFromIdToken; - URL urlFromRequest; - try { - urlFromIdToken = new URL((String) idToken.getPayload().getAudience()); - urlFromRequest = new URL(request.getRequestURL().toString()); - return urlFromIdToken.getHost().equals(urlFromRequest.getHost()) - && getPort(urlFromIdToken) == getPort(urlFromRequest); - } catch (MalformedURLException e) { - logger.atWarning().log("Invalid URL from request"); - return false; - } - } - - private int getPort(URL url) { - int port = url.getPort(); - return port == -1 ? url.getDefaultPort() : port; - } -} diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/Api.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/Api.java index 3edbf46f..274e184f 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/Api.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/Api.java @@ -146,13 +146,6 @@ ApiIssuerAudience[] issuerAudiences() default { */ Class[] authenticators() default {Authenticator.class}; - /** - * Custom peer authenticators. Applies to all methods of the API unless overridden by - * {@code @ApiClass#peerAuthenticators} or {@code @ApiMethod#peerAuthenticators}. See - * {@link PeerAuthenticator}. - */ - Class[] peerAuthenticators() default {PeerAuthenticator.class}; - /** * {@code true} if this API configuration is used as the base for another. Should be {@code false} * for most situations. diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiClass.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiClass.java index 351821cc..cff9e023 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiClass.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiClass.java @@ -77,12 +77,6 @@ ApiIssuerAudience[] issuerAudiences() default { */ Class[] authenticators() default {Authenticator.class}; - /** - * Custom peer authenticators, applicable to all methods of the API class unless overridden by - * {@code @ApiMethod#peerAuthenticators}. - */ - Class[] peerAuthenticators() default {PeerAuthenticator.class}; - /** * {@code AnnotationBoolean.TRUE} to request that overriding configuration be loaded from the * appengine datastore. diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiMethod.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiMethod.java index 3065fa77..bd0b5f5c 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiMethod.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiMethod.java @@ -113,11 +113,6 @@ ApiIssuerAudience[] issuerAudiences() default { */ Class[] authenticators() default {Authenticator.class}; - /** - * Custom peer authenticators used to verify peer for this method. - */ - Class[] peerAuthenticators() default {PeerAuthenticator.class}; - /** * Whether or not API method should be ignored. */ diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/PeerAuthenticator.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/PeerAuthenticator.java deleted file mode 100644 index 10b9ded4..00000000 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/PeerAuthenticator.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2016 Google Inc. 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 com.google.api.server.spi.config; - -import javax.servlet.http.HttpServletRequest; - -/** - * Peer authenticators aim to verify the peer and run before {@code Authenticator}. It returns false - * if authentication failed and stops handling the rest of the request; true if authentication - * succeeds and continue to execute rest of peer authenticators. - * - *

- * If no peer authenticator is set, {@code EndpointsPeerAuthenticator} will be the default to verify - * the request is from Google. If you supply your own peer authenticator, make sure you also put - * {@code EndpointsPeerAuthenticator} to the head of peerAuthenticators list to verify the request - * is from Google. - */ -public interface PeerAuthenticator { - boolean authenticate(HttpServletRequest request); -} diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/Singleton.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/Singleton.java index 198a7afc..b6c74bbb 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/Singleton.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/Singleton.java @@ -30,7 +30,7 @@ import java.util.logging.Level; /** - * Annotation used with Authenticator and PeerAuthenticator to denote only one instance will be + * Annotation used with Authenticator to denote only one instance will be * created for optimization. Implementation must be thread safe. Without the annotation a new * (peer)authenticator instance will be created for each request. */ diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/AnnotationUtil.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/AnnotationUtil.java index b0fd9a34..d3d68b1e 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/AnnotationUtil.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/AnnotationUtil.java @@ -17,7 +17,6 @@ import com.google.api.server.spi.config.Api; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import java.lang.annotation.Annotation; import java.lang.reflect.Method; @@ -118,9 +117,4 @@ public static boolean isUnspecified(Class[] values) { return values == null || (values.length == 1 && values[0].equals(Authenticator.class)); } - - public static boolean isUnspecifiedPeerAuthenticators( - Class[] values) { - return values == null || (values.length == 1 && values[0].equals(PeerAuthenticator.class)); - } } diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiAnnotationConfig.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiAnnotationConfig.java index 017ed0cc..90fad3e6 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiAnnotationConfig.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiAnnotationConfig.java @@ -19,7 +19,6 @@ import com.google.api.server.spi.config.ApiLimitMetric; import com.google.api.server.spi.config.AuthLevel; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import com.google.api.server.spi.config.model.ApiConfig; import com.google.api.server.spi.config.model.ApiIssuerAudienceConfig; import com.google.api.server.spi.config.model.ApiIssuerConfigs; @@ -175,13 +174,6 @@ public void setAuthenticatorsIfSpecified(Class[] authen } } - public void setPeerAuthenticatorsIfSpecified( - Class[] peerAuthenticators) { - if (!AnnotationUtil.isUnspecifiedPeerAuthenticators(peerAuthenticators)) { - config.setPeerAuthenticators(Arrays.asList(peerAuthenticators)); - } - } - public void setApiKeyRequiredIfSpecified(AnnotationBoolean apiKeyRequired) { if (apiKeyRequired == AnnotationBoolean.TRUE) { config.setApiKeyRequired(true); diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiClassAnnotationConfig.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiClassAnnotationConfig.java index 101cb8d9..ffd02789 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiClassAnnotationConfig.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiClassAnnotationConfig.java @@ -18,7 +18,6 @@ import com.google.api.server.spi.config.AnnotationBoolean; import com.google.api.server.spi.config.AuthLevel; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import com.google.api.server.spi.config.model.ApiClassConfig; import com.google.api.server.spi.config.model.ApiIssuerAudienceConfig; import com.google.api.server.spi.config.scope.AuthScopeExpressions; @@ -79,13 +78,6 @@ public void setAuthenticatorsIfSpecified(Class[] authen } } - public void setPeerAuthenticatorsIfSpecified( - Class[] peerAuthenticators) { - if (!AnnotationUtil.isUnspecifiedPeerAuthenticators(peerAuthenticators)) { - config.setPeerAuthenticators(Arrays.asList(peerAuthenticators)); - } - } - public void setUseDatastoreIfSpecified(AnnotationBoolean useDatastore) { if (useDatastore == AnnotationBoolean.TRUE) { config.setUseDatastore(true); diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiConfigAnnotationReader.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiConfigAnnotationReader.java index c9faaff4..44b6b9b8 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiConfigAnnotationReader.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiConfigAnnotationReader.java @@ -28,7 +28,6 @@ import com.google.api.server.spi.config.ApiMetricCost; import com.google.api.server.spi.config.AuthLevel; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import com.google.api.server.spi.config.Transformer; import com.google.api.server.spi.config.model.ApiClassConfig; import com.google.api.server.spi.config.model.ApiClassConfig.MethodConfigMap; @@ -208,8 +207,6 @@ private void readApi(ApiAnnotationConfig config, Annotation api) config.setClientIdsIfSpecified(getAnnotationProperty(api, "clientIds")); config.setAuthenticatorsIfSpecified( this.[]>getAnnotationProperty(api, "authenticators")); - config.setPeerAuthenticatorsIfSpecified(this - .[]>getAnnotationProperty(api, "peerAuthenticators")); config.setApiKeyRequiredIfSpecified( this.getAnnotationProperty(api, "apiKeyRequired")); config.setApiLimitMetrics( @@ -302,8 +299,6 @@ private void readApiClass(ApiClassAnnotationConfig config, Annotation apiClass) config.setClientIdsIfSpecified(getAnnotationProperty(apiClass, "clientIds")); config.setAuthenticatorsIfSpecified( this.[]>getAnnotationProperty(apiClass, "authenticators")); - config.setPeerAuthenticatorsIfSpecified(this.< - Class[]>getAnnotationProperty(apiClass, "peerAuthenticators")); config.setUseDatastoreIfSpecified( getAnnotationProperty(apiClass, "useDatastoreForAdditionalConfig")); config.setApiKeyRequiredIfSpecified( @@ -360,9 +355,6 @@ private void readApiMethodInstance(ApiMethodAnnotationConfig config, Annotation config.setClientIdsIfSpecified(getAnnotationProperty(apiMethod, "clientIds")); config.setAuthenticatorsIfSpecified( this.[]>getAnnotationProperty(apiMethod, "authenticators")); - config.setPeerAuthenticatorsIfSpecified(this.< - Class[]>getAnnotationProperty(apiMethod, - "peerAuthenticators")); config.setIgnoredIfSpecified(getAnnotationProperty(apiMethod, "ignored")); config.setApiKeyRequiredIfSpecified( this.getAnnotationProperty(apiMethod, "apiKeyRequired")); diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiMethodAnnotationConfig.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiMethodAnnotationConfig.java index 590857ec..607ed8e6 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiMethodAnnotationConfig.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiMethodAnnotationConfig.java @@ -19,7 +19,6 @@ import com.google.api.server.spi.config.ApiMetricCost; import com.google.api.server.spi.config.AuthLevel; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import com.google.api.server.spi.config.model.ApiIssuerAudienceConfig; import com.google.api.server.spi.config.model.ApiMethodConfig; import com.google.api.server.spi.config.model.ApiMetricCostConfig; @@ -105,13 +104,6 @@ public void setAuthenticatorsIfSpecified(Class[] authen } } - public void setPeerAuthenticatorsIfSpecified( - Class[] peerAuthenticators) { - if (!AnnotationUtil.isUnspecifiedPeerAuthenticators(peerAuthenticators)) { - config.setPeerAuthenticators(Arrays.asList(peerAuthenticators)); - } - } - public void setIgnoredIfSpecified(AnnotationBoolean ignored) { if (ignored == AnnotationBoolean.TRUE) { config.setIgnored(true); diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/model/ApiClassConfig.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/model/ApiClassConfig.java index fa8ed086..3ad9e2ae 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/model/ApiClassConfig.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/model/ApiClassConfig.java @@ -15,12 +15,10 @@ */ package com.google.api.server.spi.config.model; -import com.google.api.server.spi.Constant; import com.google.api.server.spi.EndpointMethod; import com.google.api.server.spi.TypeLoader; import com.google.api.server.spi.config.AuthLevel; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import com.google.api.server.spi.config.scope.AuthScopeExpression; import com.google.common.base.Preconditions; @@ -52,7 +50,6 @@ public class ApiClassConfig { private ApiIssuerAudienceConfig issuerAudiences; private List clientIds; private List> authenticators; - private List> peerAuthenticators; private Boolean apiKeyRequired; private final MethodConfigMap methods; @@ -69,7 +66,6 @@ public ApiClassConfig(ApiConfig apiConfig, TypeLoader typeLoader, Class apiCl this.issuerAudiences = ApiIssuerAudienceConfig.UNSPECIFIED; this.clientIds = null; this.authenticators = null; - this.peerAuthenticators = null; this.useDatastore = null; this.methods = new MethodConfigMap(this); this.apiKeyRequired = null; @@ -88,8 +84,6 @@ public ApiClassConfig(ApiClassConfig original, ApiConfig apiConfig) { this.clientIds = original.clientIds == null ? null : new ArrayList<>(original.clientIds); this.authenticators = original.authenticators == null ? null : new ArrayList<>(original.authenticators); - this.peerAuthenticators = - original.peerAuthenticators == null ? null : new ArrayList<>(original.peerAuthenticators); this.useDatastore = original.useDatastore; this.methods = new MethodConfigMap(original.methods, this); this.apiKeyRequired = original.apiKeyRequired; @@ -111,7 +105,6 @@ public boolean equals(Object o) { Objects.equals(issuerAudiences, config.issuerAudiences) && Objects.equals(clientIds, config.clientIds) && Objects.equals(authenticators, config.authenticators) && - Objects.equals(peerAuthenticators, config.peerAuthenticators) && Objects.equals(useDatastore, config.useDatastore) && methods.equals(config.methods) && Objects.equals(apiKeyRequired, config.apiKeyRequired); @@ -123,7 +116,7 @@ public boolean equals(Object o) { @Override public int hashCode() { return Objects.hash(apiClassJavaName, apiClassJavaSimpleName, typeLoader, resource, - authLevel, scopeExpression, audiences, clientIds, authenticators, peerAuthenticators, + authLevel, scopeExpression, audiences, clientIds, authenticators, useDatastore, methods, issuerAudiences, apiKeyRequired); } @@ -199,15 +192,6 @@ public List> getAuthenticators() { return authenticators != null ? authenticators : apiConfig.getAuthenticators(); } - - public void setPeerAuthenticators(List> peerAuthenticators) { - this.peerAuthenticators = peerAuthenticators; - } - - public List> getPeerAuthenticators() { - return peerAuthenticators != null ? peerAuthenticators : apiConfig.getPeerAuthenticators(); - } - public void setUseDatastore(boolean useDatastore) { this.useDatastore = useDatastore; } diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/model/ApiConfig.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/model/ApiConfig.java index b684f34f..93965ec1 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/model/ApiConfig.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/model/ApiConfig.java @@ -21,7 +21,6 @@ import com.google.api.server.spi.config.ApiConfigInconsistency; import com.google.api.server.spi.config.AuthLevel; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import com.google.api.server.spi.config.scope.AuthScopeExpression; import com.google.api.server.spi.config.scope.AuthScopeExpressions; import com.google.common.base.Preconditions; @@ -74,7 +73,6 @@ public class ApiConfig { private ApiIssuerAudienceConfig issuerAudiences; private List clientIds; private List> authenticators; - private List> peerAuthenticators; private boolean apiKeyRequired; private final ApiAuthConfig authConfig; @@ -141,7 +139,6 @@ protected ApiConfig(ApiConfig original) { this.issuerAudiences = original.issuerAudiences; this.clientIds = original.clientIds == null ? null : new ArrayList<>(original.clientIds); this.authenticators = original.authenticators; - this.peerAuthenticators = original.peerAuthenticators; this.apiKeyRequired = original.apiKeyRequired; this.apiLimitMetrics = original.apiLimitMetrics; this.authConfig = new ApiAuthConfig(original.authConfig); @@ -193,7 +190,6 @@ public Iterable> getConfigurationInconsistencies( .addIfInconsistent("issuerAudiencies", issuerAudiences, config.issuerAudiences) .addIfInconsistent("clientIds", clientIds, config.clientIds) .addIfInconsistent("authenticators", authenticators, config.authenticators) - .addIfInconsistent("peerAuthenticators", peerAuthenticators, config.peerAuthenticators) .addIfInconsistent("apiKeyRequired", apiKeyRequired, config.apiKeyRequired) .addIfInconsistent("apiLimitMetrics", apiLimitMetrics, config.apiLimitMetrics) .addAll(authConfig.getConfigurationInconsistencies(config.authConfig)) @@ -209,7 +205,7 @@ public int hashCode() { return Objects.hash(typeLoader, root, name, canonicalName, version, title, description, documentationLink, backendRoot, isAbstract, defaultVersion, discoverable, useDatastore, resource, authLevel, scopeExpression, audiences, clientIds, authenticators, - peerAuthenticators, authConfig, cacheControlConfig, frontendLimitsConfig, + authConfig, cacheControlConfig, frontendLimitsConfig, serializationConfig, apiClassConfig, issuers, issuerAudiences, apiKeyRequired, apiLimitMetrics); } @@ -279,7 +275,6 @@ protected void setDefaults(ServiceContext serviceContext) { issuerAudiences = ApiIssuerAudienceConfig.EMPTY; clientIds = DEFAULT_CLIENT_IDS; authenticators = null; - peerAuthenticators = null; apiKeyRequired = false; apiLimitMetrics = ImmutableList.of(); } @@ -478,14 +473,6 @@ public List> getAuthenticators() { return authenticators; } - public void setPeerAuthenticators(List> peerAuthenticators) { - this.peerAuthenticators = peerAuthenticators; - } - - public List> getPeerAuthenticators() { - return peerAuthenticators; - } - public void setApiKeyRequired(boolean apiKeyRequired) { this.apiKeyRequired = apiKeyRequired; } diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/model/ApiMethodConfig.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/model/ApiMethodConfig.java index ae2faa8c..e37bfde3 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/model/ApiMethodConfig.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/model/ApiMethodConfig.java @@ -20,12 +20,10 @@ import com.google.api.server.spi.TypeLoader; import com.google.api.server.spi.config.AuthLevel; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import com.google.api.server.spi.config.model.ApiParameterConfig.Classification; import com.google.api.server.spi.config.scope.AuthScopeExpression; import com.google.api.server.spi.response.BadRequestException; import com.google.api.server.spi.response.ConflictException; -import com.google.api.server.spi.response.ErrorMap; import com.google.api.server.spi.response.ForbiddenException; import com.google.api.server.spi.response.InternalServerErrorException; import com.google.api.server.spi.response.NotFoundException; @@ -176,7 +174,6 @@ public String guessResourceName( private ApiIssuerAudienceConfig issuerAudiences; private List clientIds; private List> authenticators; - private List> peerAuthenticators; private boolean ignored = false; private boolean deprecated = false; private Boolean apiKeyRequired; @@ -209,8 +206,6 @@ public ApiMethodConfig(ApiMethodConfig original, ApiClassConfig apiClassConfig) this.clientIds = original.clientIds == null ? null : new ArrayList<>(original.clientIds); this.authenticators = original.authenticators == null ? null : new ArrayList<>(original.authenticators); - this.peerAuthenticators = - original.peerAuthenticators == null ? null : new ArrayList<>(original.peerAuthenticators); this.ignored = original.ignored; this.apiKeyRequired = original.apiKeyRequired; this.returnType = original.returnType; @@ -250,7 +245,6 @@ protected void setDefaults(EndpointMethod endpointMethod, TypeLoader typeLoader, issuerAudiences = ApiIssuerAudienceConfig.UNSPECIFIED; clientIds = null; authenticators = null; - peerAuthenticators = null; ignored = false; apiKeyRequired = null; returnType = endpointMethod.getReturnType(); @@ -282,7 +276,6 @@ public boolean equals(Object o) { Objects.equals(issuerAudiences, config.issuerAudiences) && Objects.equals(clientIds, config.clientIds) && Objects.equals(authenticators, config.authenticators) && - Objects.equals(peerAuthenticators, config.peerAuthenticators) && Objects.equals(typeLoader, config.typeLoader) && ignored == config.ignored && apiKeyRequired == config.apiKeyRequired && @@ -296,7 +289,7 @@ public boolean equals(Object o) { @Override public int hashCode() { return Objects.hash(endpointMethodName, parameterConfigs, name, path, httpMethod, - scopeExpression, audiences, clientIds, authenticators, peerAuthenticators, typeLoader, + scopeExpression, audiences, clientIds, authenticators, typeLoader, ignored, issuerAudiences, apiKeyRequired, returnType, metricCosts); } @@ -492,14 +485,6 @@ public List> getAuthenticators() { return authenticators != null ? authenticators : apiClassConfig.getAuthenticators(); } - public void setPeerAuthenticators(List> peerAuthenticators) { - this.peerAuthenticators = peerAuthenticators; - } - - public List> getPeerAuthenticators() { - return peerAuthenticators != null ? peerAuthenticators : apiClassConfig.getPeerAuthenticators(); - } - public void setIgnored(boolean ignored) { this.ignored = ignored; } diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/validation/ApiConfigValidator.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/validation/ApiConfigValidator.java index e605420b..43a360a1 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/validation/ApiConfigValidator.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/validation/ApiConfigValidator.java @@ -239,7 +239,6 @@ private void validateMethod(ApiMethodConfig config) throws ApiMethodConfigInvali } validateNullaryConstructor(config.getAuthenticators(), config, "custom authenticator"); - validateNullaryConstructor(config.getPeerAuthenticators(), config, "custom peer authenticator"); Set parameterNames = Sets.newHashSet(); for (ApiParameterConfig parameter : config.getParameterConfigs()) { diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/request/Attribute.java b/endpoints-framework/src/main/java/com/google/api/server/spi/request/Attribute.java index e56b4965..27c4f1df 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/request/Attribute.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/request/Attribute.java @@ -42,10 +42,6 @@ public class Attribute { */ public static final String ENABLE_CLIENT_ID_WHITELIST = "endpoints:Enable-Client-Id-Whitelist"; - /** - * @deprecated - */ - public static final String RESTRICT_SERVLET = "endpoints:Restrict-Servlet"; /** * A {@link Boolean} indicating if the App Engine user should be populated. */ @@ -106,7 +102,6 @@ public static Attribute bindStandardRequestAttributes(HttpServletRequest request ApiMethodConfig methodConfig, ServletInitializationParameters initParameters) { Attribute attr = Attribute.from(request); - attr.set(Attribute.RESTRICT_SERVLET, initParameters.isServletRestricted()); attr.set(Attribute.ENABLE_CLIENT_ID_WHITELIST, initParameters.isClientIdWhitelistEnabled()); attr.set(Attribute.API_METHOD_CONFIG, methodConfig); // No clientId is allowed. Producer is not interested in Jwt/OAuth2 authentication. diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/PeerAuthTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/PeerAuthTest.java deleted file mode 100644 index 94142efa..00000000 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/PeerAuthTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2016 Google Inc. 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 com.google.api.server.spi; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -import com.google.api.server.spi.auth.EndpointsPeerAuthenticator; -import com.google.api.server.spi.config.PeerAuthenticator; -import com.google.api.server.spi.config.model.ApiMethodConfig; -import com.google.api.server.spi.request.Attribute; -import com.google.api.server.spi.testing.FailPeerAuthenticator; -import com.google.api.server.spi.testing.PassPeerAuthenticator; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.mock.web.MockHttpServletRequest; - -import java.util.List; - -/** - * Test for PeerAuth. - */ -@RunWith(MockitoJUnitRunner.class) -public class PeerAuthTest { - @Mock private ApiMethodConfig config; - - private MockHttpServletRequest request; - private PeerAuth peerAuth; - private Attribute attr; - - @Before - public void setUp() throws Exception { - request = new MockHttpServletRequest(); - attr = Attribute.from(request); - attr.set(Attribute.RESTRICT_SERVLET, true); - attr.set(Attribute.API_METHOD_CONFIG, config); - peerAuth = PeerAuth.from(request); - } - - @Test - public void testGetPeerAuthenticatorInstances_default() throws Exception { - when(config.getPeerAuthenticators()).thenReturn(null); - List peerAuthenticators = - Lists.newArrayList(peerAuth.getPeerAuthenticatorInstances()); - assertEquals(1, peerAuthenticators.size()); - assertTrue(peerAuthenticators.get(0) instanceof EndpointsPeerAuthenticator); - } - - @Test - public void testGetPeerAuthenticatorInstances() throws Exception { - when(config.getPeerAuthenticators()).thenReturn( - ImmutableList.of(PassPeerAuthenticator.class, FailPeerAuthenticator.class)); - List peerAuthenticators = - Lists.newArrayList(peerAuth.getPeerAuthenticatorInstances()); - assertEquals(2, peerAuthenticators.size()); - assertTrue(peerAuthenticators.get(0) instanceof PassPeerAuthenticator); - assertTrue(peerAuthenticators.get(1) instanceof FailPeerAuthenticator); - } - - @Test - public void testGetPeerAuthenticatorInstances_singleton() throws Exception { - when(config.getPeerAuthenticators()).thenReturn(ImmutableList.of(PassPeerAuthenticator.class, - FailPeerAuthenticator.class, PassPeerAuthenticator.class)); - List peerAuthenticators = - Lists.newArrayList(peerAuth.getPeerAuthenticatorInstances()); - assertEquals(3, peerAuthenticators.size()); - assertTrue(peerAuthenticators.get(0) instanceof PassPeerAuthenticator); - assertTrue(peerAuthenticators.get(1) instanceof FailPeerAuthenticator); - assertTrue(peerAuthenticators.get(2) instanceof PassPeerAuthenticator); - assertSame(peerAuthenticators.get(0), peerAuthenticators.get(2)); - } - - @Test - public void testGetPeerAuthenticatorInstances_nonSingleton() throws Exception { - when(config.getPeerAuthenticators()).thenReturn(ImmutableList.of(PassPeerAuthenticator.class, - FailPeerAuthenticator.class, FailPeerAuthenticator.class)); - List peerAuthenticators = - Lists.newArrayList(peerAuth.getPeerAuthenticatorInstances()); - assertEquals(3, peerAuthenticators.size()); - assertTrue(peerAuthenticators.get(0) instanceof PassPeerAuthenticator); - assertTrue(peerAuthenticators.get(1) instanceof FailPeerAuthenticator); - assertTrue(peerAuthenticators.get(2) instanceof FailPeerAuthenticator); - assertNotSame(peerAuthenticators.get(1), peerAuthenticators.get(2)); - } - - @Test - public void testPeerAuthorize_nonRestricted() throws Exception { - attr.set(Attribute.RESTRICT_SERVLET, false); - assertTrue(peerAuth.authorizePeer()); - } - - @Test - public void testPeerAuthorize_pass() throws Exception { - when(config.getPeerAuthenticators()).thenReturn( - ImmutableList.>of(PassPeerAuthenticator.class)); - assertTrue(peerAuth.authorizePeer()); - } - - @Test - public void testPeerAuthorize_fail() throws Exception { - when(config.getPeerAuthenticators()).thenReturn( - ImmutableList.>of(FailPeerAuthenticator.class)); - assertFalse(peerAuth.authorizePeer()); - } - - @Test - public void testPeerAuthorize_passThenFail() throws Exception { - when(config.getPeerAuthenticators()).thenReturn( - ImmutableList.of(PassPeerAuthenticator.class, FailPeerAuthenticator.class)); - assertFalse(peerAuth.authorizePeer()); - } - - @Test - public void testPeerAuthorize_failThenPass() throws Exception { - when(config.getPeerAuthenticators()).thenReturn( - ImmutableList.of(FailPeerAuthenticator.class, PassPeerAuthenticator.class)); - assertFalse(peerAuth.authorizePeer()); - } -} diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/ServletInitializationParametersTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/ServletInitializationParametersTest.java index fc1cd7d2..0226233f 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/ServletInitializationParametersTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/ServletInitializationParametersTest.java @@ -43,21 +43,19 @@ public void testBuilder_defaults() { ServletInitializationParameters initParameters = ServletInitializationParameters.builder() .build(); assertThat(initParameters.getServiceClasses()).isEmpty(); - assertThat(initParameters.isServletRestricted()).isTrue(); assertThat(initParameters.isClientIdWhitelistEnabled()).isTrue(); assertThat(initParameters.isIllegalArgumentBackendError()).isFalse(); assertThat(initParameters.isExceptionCompatibilityEnabled()).isTrue(); assertThat(initParameters.isPrettyPrintEnabled()).isTrue(); assertThat(initParameters.isAddContentLength()).isFalse(); assertThat(initParameters.getApiExplorerUrlTemplate()).isNull(); - verifyAsMap(initParameters, "", "true", "true", "false", "true", "true", "false", null); + verifyAsMap(initParameters, "", "true", "false", "true", "true", "false", null); } @Test public void testBuilder_emptySetsAndTrue() { ServletInitializationParameters initParameters = ServletInitializationParameters.builder() .setClientIdWhitelistEnabled(true) - .setRestricted(true) .addServiceClasses(ImmutableSet.>of()) .setIllegalArgumentBackendError(true) .setExceptionCompatibilityEnabled(true) @@ -66,18 +64,16 @@ public void testBuilder_emptySetsAndTrue() { .setApiExplorerUrlTemplate("apiExplorer") .build(); assertThat(initParameters.getServiceClasses()).isEmpty(); - assertThat(initParameters.isServletRestricted()).isTrue(); assertThat(initParameters.isClientIdWhitelistEnabled()).isTrue(); assertThat(initParameters.isIllegalArgumentBackendError()).isTrue(); assertThat(initParameters.isExceptionCompatibilityEnabled()).isTrue(); assertThat(initParameters.getApiExplorerUrlTemplate()).isEqualTo("apiExplorer"); - verifyAsMap(initParameters, "", "true", "true", "true", "true", "true", "true", "apiExplorer"); + verifyAsMap(initParameters, "", "true", "true", "true", "true", "true", "apiExplorer"); } @Test public void testBuilder_oneEntrySetsAndFalse() { ServletInitializationParameters initParameters = ServletInitializationParameters.builder() - .setRestricted(false) .addServiceClass(String.class) .setClientIdWhitelistEnabled(false) .setIllegalArgumentBackendError(false) @@ -86,10 +82,9 @@ public void testBuilder_oneEntrySetsAndFalse() { .setAddContentLength(false) .build(); assertThat(initParameters.getServiceClasses()).containsExactly(String.class); - assertThat(initParameters.isServletRestricted()).isFalse(); assertThat(initParameters.isClientIdWhitelistEnabled()).isFalse(); verifyAsMap( - initParameters, String.class.getName(), "false", "false", "false", "false", "false","false", null); + initParameters, String.class.getName(), "false", "false", "false", "false","false", null); } @Test @@ -98,7 +93,7 @@ public void testBuilder_twoEntrySets() { .addServiceClasses(ImmutableSet.of(String.class, Integer.class)) .build(); assertThat(initParameters.getServiceClasses()).containsExactly(String.class, Integer.class); - verifyAsMap(initParameters, String.class.getName() + ',' + Integer.class.getName(), "true", + verifyAsMap(initParameters, String.class.getName() + ',' + Integer.class.getName(), "true", "false", "true", "true", "false", null); } @@ -107,16 +102,14 @@ public void testFromServletConfig_nullConfig() throws ServletException { ServletInitializationParameters initParameters = ServletInitializationParameters.fromServletConfig(null, getClass().getClassLoader()); assertThat(initParameters.getServiceClasses()).isEmpty(); - assertThat(initParameters.isServletRestricted()).isTrue(); assertThat(initParameters.isClientIdWhitelistEnabled()).isTrue(); } @Test public void testFromServletConfig_nullValues() throws ServletException { ServletInitializationParameters initParameters = - fromServletConfig(null, null, null, null, null, null, null, null); + fromServletConfig(null, null, null, null, null, null, null); assertThat(initParameters.getServiceClasses()).isEmpty(); - assertThat(initParameters.isServletRestricted()).isTrue(); assertThat(initParameters.isClientIdWhitelistEnabled()).isTrue(); assertThat(initParameters.isIllegalArgumentBackendError()).isFalse(); assertThat(initParameters.isExceptionCompatibilityEnabled()).isTrue(); @@ -127,9 +120,8 @@ public void testFromServletConfig_nullValues() throws ServletException { @Test public void testFromServletConfig_emptySetsAndFalse() throws ServletException { ServletInitializationParameters initParameters = - fromServletConfig("", "false", "false", "false", "false", "false", "false", null); + fromServletConfig("", "false", "false", "false", "false", "false", null); assertThat(initParameters.getServiceClasses()).isEmpty(); - assertThat(initParameters.isServletRestricted()).isFalse(); assertThat(initParameters.isClientIdWhitelistEnabled()).isFalse(); assertThat(initParameters.isIllegalArgumentBackendError()).isFalse(); assertThat(initParameters.isExceptionCompatibilityEnabled()).isFalse(); @@ -140,9 +132,8 @@ public void testFromServletConfig_emptySetsAndFalse() throws ServletException { @Test public void testFromServletConfig_oneEntrySetsAndTrue() throws ServletException { ServletInitializationParameters initParameters = - fromServletConfig(String.class.getName(), "true", "true", "true", "true", "true", "true", null); + fromServletConfig(String.class.getName(), "true", "true", "true", "true", "true", null); assertThat(initParameters.getServiceClasses()).containsExactly(String.class); - assertThat(initParameters.isServletRestricted()).isTrue(); assertThat(initParameters.isClientIdWhitelistEnabled()).isTrue(); assertThat(initParameters.isIllegalArgumentBackendError()).isTrue(); assertThat(initParameters.isExceptionCompatibilityEnabled()).isTrue(); @@ -153,22 +144,22 @@ public void testFromServletConfig_oneEntrySetsAndTrue() throws ServletException @Test public void testFromServletConfig_twoEntrySets() throws ServletException { ServletInitializationParameters initParameters = fromServletConfig( - String.class.getName() + ',' + Integer.class.getName(), null, null, null, null, null, null, null); + String.class.getName() + ',' + Integer.class.getName(), null, null, null, null, null, null); assertThat(initParameters.getServiceClasses()).containsExactly(String.class, Integer.class); } @Test public void testFromServletConfig_skipsEmptyElements() throws ServletException { ServletInitializationParameters initParameters = fromServletConfig( - ",," + String.class.getName() + ",,," + Integer.class.getName() + ",", null, null, null, + ",," + String.class.getName() + ",,," + Integer.class.getName() + ",", null, null, null, null, null, null); assertThat(initParameters.getServiceClasses()).containsExactly(String.class, Integer.class); } @Test - public void testFromServletConfig_invalidRestrictedThrows() throws ServletException { + public void testFromServletConfig_invalidBooleanThrows() throws ServletException { try { - fromServletConfig(null, "yes", null, null, null, null, null, null); + fromServletConfig(null, "yes", null, null, null, null, null); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { // expected @@ -177,13 +168,12 @@ public void testFromServletConfig_invalidRestrictedThrows() throws ServletExcept private void verifyAsMap( ServletInitializationParameters initParameters, String serviceClasses, - String isServletRestricted, String isClientIdWhitelistEnabled, + String isClientIdWhitelistEnabled, String isIllegalArgumentBackendError, String isExceptionCompatibilityEnabled, String isPrettyPrintEnabled, String isAddContentLength, String apiExplorerUrlTemplate) { Map map = initParameters.asMap(); - assertThat(map).hasSize(8); + assertThat(map).hasSize(7); assertThat(map.get("services")).isEqualTo(serviceClasses); - assertThat(map.get("restricted")).isEqualTo(isServletRestricted); assertThat(map.get("clientIdWhitelistEnabled")).isEqualTo(isClientIdWhitelistEnabled); assertThat(map.get("illegalArgumentIsBackendError")).isEqualTo(isIllegalArgumentBackendError); assertThat(map.get("enableExceptionCompatibility")).isEqualTo(isExceptionCompatibilityEnabled); @@ -193,13 +183,13 @@ private void verifyAsMap( } private ServletInitializationParameters fromServletConfig( - String serviceClasses, String isServletRestricted, + String serviceClasses, String isClientIdWhitelistEnabled, String isIllegalArgumentBackendError, String isExceptionCompatibilityEnabled, String isPrettyPrintEnabled, String isAddContentLength, String apiExplorerUrlTemplate) throws ServletException { ServletConfig servletConfig = new StubServletConfig(serviceClasses, - isServletRestricted, isClientIdWhitelistEnabled, isIllegalArgumentBackendError, + isClientIdWhitelistEnabled, isIllegalArgumentBackendError, isExceptionCompatibilityEnabled, isPrettyPrintEnabled, isAddContentLength, apiExplorerUrlTemplate); return ServletInitializationParameters.fromServletConfig( servletConfig, getClass().getClassLoader()); @@ -209,12 +199,11 @@ private static class StubServletConfig implements ServletConfig { private final Map initParameters; public StubServletConfig( - String serviceClasses, String isServletRestricted, String isClientIdWhitelistEnabled, + String serviceClasses, String isClientIdWhitelistEnabled, String isIllegalArgumentBackendError, String isExceptionCompatibilityEnabled, String isPrettyPrintEnabled, String isAddContentLength, String apiExplorerUrlTemplate) { initParameters = Maps.newHashMap(); initParameters.put("services", serviceClasses); - initParameters.put("restricted", isServletRestricted); initParameters.put("clientIdWhitelistEnabled", isClientIdWhitelistEnabled); initParameters.put("illegalArgumentIsBackendError", isIllegalArgumentBackendError); initParameters.put("enableExceptionCompatibility", isExceptionCompatibilityEnabled); diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/EndpointsPeerAuthenticatorTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/auth/EndpointsPeerAuthenticatorTest.java deleted file mode 100644 index e81d8785..00000000 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/auth/EndpointsPeerAuthenticatorTest.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2016 Google Inc. 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 com.google.api.server.spi.auth; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.when; - -import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken; -import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload; -import com.google.api.server.spi.EnvUtil; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.mock.web.MockHttpServletRequest; - -import java.net.InetAddress; - -/** - * Tests for {@code EndpointsPeerAuthenticator}. - */ -@RunWith(MockitoJUnitRunner.class) -public class EndpointsPeerAuthenticatorTest { - private static final String FAKE_TOKEN = "fakeToken"; - - @Mock private GoogleJwtAuthenticator jwtAuthenticator; - @Mock private GoogleIdToken token; - - private final Payload payload = new Payload(); - private MockHttpServletRequest request; - private EndpointsPeerAuthenticator authenticator; - - @Before - public void setUp() throws Exception { - System.clearProperty(EnvUtil.ENV_APPENGINE_RUNTIME); - authenticator = new EndpointsPeerAuthenticator(jwtAuthenticator); - request = new MockHttpServletRequest(); - request.setRemoteAddr("8.8.8.8"); - } - - @After - public void tearDown() throws Exception { - EnvUtil.recoverAppEngineRuntime(); - } - - @Test - public void testAuthenticate_localHost() throws Exception { - request.setRemoteAddr(InetAddress.getLocalHost().getHostAddress()); - assertTrue(authenticator.authenticate(request)); - } - - @Test - public void testAuthenticate_localHostIp() { - request.setRemoteAddr("127.0.0.1"); - assertTrue(authenticator.authenticate(request)); - } - - @Test - public void testAuthenticate_appEngineRunTimeNoXAppengineHeader() { - System.setProperty(EnvUtil.ENV_APPENGINE_RUNTIME, "Production"); - assertFalse(authenticator.authenticate(request)); - } - - @Test - public void testAuthenticate_appEngineRunTimeUnmatchedXAppengineHeader() { - System.setProperty(EnvUtil.ENV_APPENGINE_RUNTIME, "Production"); - request.addHeader(EndpointsPeerAuthenticator.APPENGINE_PEER, "invalid"); - assertFalse(authenticator.authenticate(request)); - } - - @Test - public void testAuthenticate_appEngineRunTimeSuccess() { - System.setProperty(EnvUtil.ENV_APPENGINE_RUNTIME, "Production"); - request.addHeader(EndpointsPeerAuthenticator.HEADER_APPENGINE_PEER, - EndpointsPeerAuthenticator.APPENGINE_PEER); - assertTrue(authenticator.authenticate(request)); - } - - @Test - public void testAuthenticate_noPeerAuthorizationHeader() { - assertFalse(authenticator.authenticate(request)); - } - - @Test - public void testAuthenticate_invalidHeader() { - request.addHeader(EndpointsPeerAuthenticator.HEADER_PEER_AUTHORIZATION, FAKE_TOKEN); - when(jwtAuthenticator.verifyToken(FAKE_TOKEN)).thenReturn(null); - assertFalse(authenticator.authenticate(request)); - } - - @Test - public void testAuthenticate_invalidEmail() { - payload.setEmail("invalid@gmail.com"); - request.addHeader(EndpointsPeerAuthenticator.HEADER_PEER_AUTHORIZATION, FAKE_TOKEN); - when(jwtAuthenticator.verifyToken(FAKE_TOKEN)).thenReturn(token); - when(token.getPayload()).thenReturn(payload); - assertFalse(authenticator.authenticate(request)); - } - - @Test - public void testAuthenticate_unmatchedHost() { - payload.setEmail(EndpointsPeerAuthenticator.SIGNER); - payload.setAudience("http://otherhost.com/api"); - request.addHeader(EndpointsPeerAuthenticator.HEADER_PEER_AUTHORIZATION, FAKE_TOKEN); - request.addHeader("Host", "myhost.com"); - when(jwtAuthenticator.verifyToken(FAKE_TOKEN)).thenReturn(token); - when(token.getPayload()).thenReturn(payload); - assertFalse(authenticator.authenticate(request)); - } - - @Test - public void testAuthenticate_unmatchedPortDefault() { - payload.setEmail(EndpointsPeerAuthenticator.SIGNER); - payload.setAudience("https://myhost.com/api"); - request.addHeader(EndpointsPeerAuthenticator.HEADER_PEER_AUTHORIZATION, FAKE_TOKEN); - request.addHeader("Host", "myhost.com"); - when(jwtAuthenticator.verifyToken(FAKE_TOKEN)).thenReturn(token); - when(token.getPayload()).thenReturn(payload); - assertFalse(authenticator.authenticate(request)); - } - - @Test - public void testAuthenticate_unmatchedPort() { - request = createRequest("myhost.com", 456, "", "", ""); - request.setRemoteAddr("8.8.8.8"); - payload.setEmail(EndpointsPeerAuthenticator.SIGNER); - payload.setAudience("http://otherhost.com:789/api"); - request.addHeader(EndpointsPeerAuthenticator.HEADER_PEER_AUTHORIZATION, FAKE_TOKEN); - when(jwtAuthenticator.verifyToken(FAKE_TOKEN)).thenReturn(token); - when(token.getPayload()).thenReturn(payload); - assertFalse(authenticator.authenticate(request)); - } - - @Test - public void testAuthenticate_success() { - request = createRequest("myhost.com", 456, "", "", ""); - request.setRemoteAddr("8.8.8.8"); - payload.setEmail(EndpointsPeerAuthenticator.SIGNER); - payload.setAudience("http://myhost.com:456/api"); - request.addHeader(EndpointsPeerAuthenticator.HEADER_PEER_AUTHORIZATION, FAKE_TOKEN); - when(jwtAuthenticator.verifyToken(FAKE_TOKEN)).thenReturn(token); - when(token.getPayload()).thenReturn(payload); - assertTrue(authenticator.authenticate(request)); - } - - @Test - public void testNewInstance() { - try { - authenticator = EndpointsPeerAuthenticator.class.newInstance(); - } catch (Exception e) { - fail("newInstance on EndpointsPeerAuthenticator.class failed"); - } - } - - private static MockHttpServletRequest createRequest( - String host, int port, String servletPath, String contextPath, String queryString) { - MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Host", host); - request.setServerName(host); - request.setServerPort(port); - request.setServletPath(servletPath); - request.setQueryString(queryString); - request.setContextPath(contextPath); - return request; - } -} diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiAnnotationConfigTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiAnnotationConfigTest.java index 07bc8f23..38ed1854 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiAnnotationConfigTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiAnnotationConfigTest.java @@ -26,13 +26,11 @@ import com.google.api.server.spi.config.Api; import com.google.api.server.spi.config.AuthLevel; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import com.google.api.server.spi.config.model.ApiConfig; import com.google.api.server.spi.config.model.ApiMethodConfig; import com.google.api.server.spi.config.scope.AuthScopeExpression; import com.google.api.server.spi.config.scope.AuthScopeExpressions; import com.google.api.server.spi.testing.PassAuthenticator; -import com.google.api.server.spi.testing.PassPeerAuthenticator; import com.google.api.server.spi.testing.TestEndpoint; import com.google.common.collect.ImmutableList; @@ -382,21 +380,6 @@ public void testSetAuthenticatorIfSpecified_unspecified() throws Exception { assertNull(config.getAuthenticators()); } - @Test - public void testSetPeerAuthenticatorIfSpecified() throws Exception { - annotationConfig.setPeerAuthenticatorsIfSpecified(PassPeerAuthenticator.testArray); - assertEquals(Arrays.asList(PassPeerAuthenticator.testArray), config.getPeerAuthenticators()); - } - - // Unchecked cast needed to get a generic array type. - @SuppressWarnings("unchecked") - public void testSetPeerAuthenticatorIfSpecified_unspecified() throws Exception { - Class[] peerAuthenticators = {PeerAuthenticator.class}; - annotationConfig.setPeerAuthenticatorsIfSpecified( - (Class[]) peerAuthenticators); - assertNull(config.getPeerAuthenticators()); - } - private EndpointMethod getResultNoParamsMethod() throws NoSuchMethodException, SecurityException { return getSimpleEndpointMethod(TestEndpoint.class.getMethod("getResultNoParams")); } diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiClassAnnotationConfigTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiClassAnnotationConfigTest.java index 266913d8..27709914 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiClassAnnotationConfigTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiClassAnnotationConfigTest.java @@ -19,12 +19,10 @@ import com.google.api.server.spi.config.Api; import com.google.api.server.spi.config.AuthLevel; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import com.google.api.server.spi.config.model.ApiClassConfig; import com.google.api.server.spi.config.scope.AuthScopeExpression; import com.google.api.server.spi.config.scope.AuthScopeExpressions; import com.google.api.server.spi.testing.PassAuthenticator; -import com.google.api.server.spi.testing.PassPeerAuthenticator; import org.junit.Before; import org.junit.Test; @@ -185,22 +183,7 @@ public void testSetAuthenticatorIfSpecified_unspecified() throws Exception { Class[] authenticators = {Authenticator.class}; annotationConfig.setAuthenticatorsIfSpecified( (Class[]) authenticators); - Mockito.verifyZeroInteractions(config); - } - - @Test - public void testSetPeerAuthenticatorIfSpecified() throws Exception { - annotationConfig.setPeerAuthenticatorsIfSpecified(PassPeerAuthenticator.testArray); - Mockito.verify(config).setPeerAuthenticators(Arrays.asList(PassPeerAuthenticator.testArray)); - } - - // Unchecked cast needed to get a generic array type. - @SuppressWarnings("unchecked") - public void testSetPeerAuthenticatorIfSpecified_unspecified() throws Exception { - Class[] peerAuthenticators = {PeerAuthenticator.class}; - annotationConfig.setPeerAuthenticatorsIfSpecified( - (Class[]) peerAuthenticators); - Mockito.verifyZeroInteractions(config); + Mockito.verifyNoInteractions(config); } @Test diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiConfigAnnotationReaderTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiConfigAnnotationReaderTest.java index b07a2779..1d2ff8ce 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiConfigAnnotationReaderTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiConfigAnnotationReaderTest.java @@ -67,11 +67,9 @@ import com.google.api.server.spi.testing.Endpoint3; import com.google.api.server.spi.testing.Endpoint4; import com.google.api.server.spi.testing.FailAuthenticator; -import com.google.api.server.spi.testing.FailPeerAuthenticator; import com.google.api.server.spi.testing.Foo; import com.google.api.server.spi.testing.InterfaceReferenceEndpoint; import com.google.api.server.spi.testing.PassAuthenticator; -import com.google.api.server.spi.testing.PassPeerAuthenticator; import com.google.api.server.spi.testing.ReferenceOverridingEndpoint; import com.google.api.server.spi.testing.RestfulResourceEndpointBase; import com.google.api.server.spi.testing.SimpleBean; @@ -150,7 +148,6 @@ public void testBasicEndpoint() throws Exception { DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, - null, null); } @@ -194,8 +191,7 @@ public void testEndpointWithInheritance() throws Exception { defaultScopes, defaultAudiences, defaultClientIds, - ImmutableList.of(PassAuthenticator.class), - ImmutableList.of(PassPeerAuthenticator.class)); + ImmutableList.of(PassAuthenticator.class)); assertEquals(1, getBar.getParameterConfigs().size()); validateParameter(getBar.getParameterConfigs().get(0), "id", false, null, String.class); } @@ -217,7 +213,6 @@ public void testEndpointWithBridgeMethods() throws Exception { DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, - null, null); ApiMethodConfig fn2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod( BridgeInheritanceEndpoint.class.getSuperclass().getMethod("fn2"))); @@ -228,7 +223,6 @@ public void testEndpointWithBridgeMethods() throws Exception { DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, - null, null); ApiMethodConfig bridge = config.getApiClassConfig().getMethods().get(methodToEndpointMethod( @@ -271,7 +265,6 @@ public void testSimpleOverrideEndpoint() throws Exception { DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, - null, null); } @@ -505,8 +498,7 @@ public void testServiceWithOverridingInheritance() throws Exception { String[] expectedAudiences = { "a0", "a1" }; String[] expectedClientIds = { "c0", "c1" }; validateMethod(listFoos, "foos.list", "foos", ApiMethod.HttpMethod.GET, expectedScopes, - expectedAudiences, expectedClientIds, ImmutableList.of(FailAuthenticator.class), - ImmutableList.of(FailPeerAuthenticator.class)); + expectedAudiences, expectedClientIds, ImmutableList.of(FailAuthenticator.class)); assertEquals(0, listFoos.getParameterConfigs().size()); ApiMethodConfig getFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod( @@ -518,8 +510,7 @@ public void testServiceWithOverridingInheritance() throws Exception { defaultScopes, defaultAudiences, defaultClientIds, - ImmutableList.of(PassAuthenticator.class), - ImmutableList.of(PassPeerAuthenticator.class)); + ImmutableList.of(PassAuthenticator.class)); assertEquals(1, getFoo.getParameterConfigs().size()); validateParameter(getFoo.getParameterConfigs().get(0), "id", false, null, String.class); @@ -532,8 +523,7 @@ public void testServiceWithOverridingInheritance() throws Exception { defaultScopes, defaultAudiences, defaultClientIds, - ImmutableList.of(PassAuthenticator.class), - ImmutableList.of(PassPeerAuthenticator.class)); + ImmutableList.of(PassAuthenticator.class)); assertEquals(1, insertFoo.getParameterConfigs().size()); validateParameter(insertFoo.getParameterConfigs().get(0), null, false, null, Foo.class); @@ -544,8 +534,7 @@ public void testServiceWithOverridingInheritance() throws Exception { defaultScopes, defaultAudiences, defaultClientIds, - ImmutableList.of(PassAuthenticator.class), - ImmutableList.of(PassPeerAuthenticator.class)); + ImmutableList.of(PassAuthenticator.class)); assertEquals(1, execute2.getParameterConfigs().size()); validateParameter(execute2.getParameterConfigs().get(0), "serialized", false, null, SimpleBean.class, DumbSerializer2.class, Integer.class); @@ -590,8 +579,7 @@ public void testServiceWithOverridingReference() throws Exception { defaultScopes, defaultAudiences, defaultClientIds, - ImmutableList.of(PassAuthenticator.class), - ImmutableList.of(PassPeerAuthenticator.class)); + ImmutableList.of(PassAuthenticator.class)); assertEquals(1, getFoo.getParameterConfigs().size()); validateParameter(getFoo.getParameterConfigs().get(0), "id", false, null, String.class); } @@ -805,7 +793,6 @@ public void method(@Named("serialized") TestBean tb) {} DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, - null, null); validateParameter(methodConfig.getParameterConfigs().get(0), "serialized", false, null, TestBean.class, TestSerializer.class, String.class); @@ -1276,8 +1263,7 @@ private void validateEndpoint1(ApiConfig config, Class claz String[] expectedAudiences = { "a0", "a1" }; String[] expectedClientIds = { "c0", "c1" }; validateMethod(listFoos, "foos.list", "foos", ApiMethod.HttpMethod.GET, expectedScopes, - expectedAudiences, expectedClientIds, ImmutableList.of(FailAuthenticator.class), - ImmutableList.of(FailPeerAuthenticator.class)); + expectedAudiences, expectedClientIds, ImmutableList.of(FailAuthenticator.class)); assertEquals(0, listFoos.getParameterConfigs().size()); ApiMethodConfig getFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod( @@ -1289,8 +1275,7 @@ private void validateEndpoint1(ApiConfig config, Class claz defaultScopes, defaultAudiences, defaultClientIds, - ImmutableList.of(PassAuthenticator.class), - ImmutableList.of(PassPeerAuthenticator.class)); + ImmutableList.of(PassAuthenticator.class)); assertEquals(1, getFoo.getParameterConfigs().size()); validateParameter(getFoo.getParameterConfigs().get(0), "id", false, null, String.class); @@ -1303,8 +1288,7 @@ private void validateEndpoint1(ApiConfig config, Class claz defaultScopes, defaultAudiences, defaultClientIds, - ImmutableList.of(PassAuthenticator.class), - ImmutableList.of(PassPeerAuthenticator.class)); + ImmutableList.of(PassAuthenticator.class)); assertEquals(1, insertFoo.getParameterConfigs().size()); validateParameter(insertFoo.getParameterConfigs().get(0), null, false, null, Foo.class); @@ -1317,8 +1301,7 @@ private void validateEndpoint1(ApiConfig config, Class claz defaultScopes, defaultAudiences, defaultClientIds, - ImmutableList.of(PassAuthenticator.class), - ImmutableList.of(PassPeerAuthenticator.class)); + ImmutableList.of(PassAuthenticator.class)); assertEquals(2, updateFoo.getParameterConfigs().size()); validateParameter(updateFoo.getParameterConfigs().get(0), "id", false, null, String.class); validateParameter(updateFoo.getParameterConfigs().get(1), null, false, null, Foo.class); @@ -1329,8 +1312,7 @@ private void validateEndpoint1(ApiConfig config, Class claz defaultScopes, defaultAudiences, defaultClientIds, - ImmutableList.of(PassAuthenticator.class), - ImmutableList.of(PassPeerAuthenticator.class)); + ImmutableList.of(PassAuthenticator.class)); assertEquals(1, removeFoo.getParameterConfigs().size()); validateParameter(removeFoo.getParameterConfigs().get(0), "id", false, null, String.class); @@ -1344,8 +1326,7 @@ private void validateEndpoint1(ApiConfig config, Class claz defaultScopes, defaultAudiences, defaultClientIds, - ImmutableList.of(PassAuthenticator.class), - ImmutableList.of(PassPeerAuthenticator.class)); + ImmutableList.of(PassAuthenticator.class)); assertEquals(9, execute0.getParameterConfigs().size()); validateParameter(execute0.getParameterConfigs().get(0), "id", false, null, String.class); validateParameter(execute0.getParameterConfigs().get(1), "i0", false, null, int.class); @@ -1364,8 +1345,7 @@ private void validateEndpoint1(ApiConfig config, Class claz defaultScopes, defaultAudiences, defaultClientIds, - ImmutableList.of(PassAuthenticator.class), - ImmutableList.of(PassPeerAuthenticator.class)); + ImmutableList.of(PassAuthenticator.class)); assertEquals(1, execute1.getParameterConfigs().size()); validateParameter(execute1.getParameterConfigs().get(0), null, false, null, Foo.class); @@ -1376,8 +1356,7 @@ private void validateEndpoint1(ApiConfig config, Class claz defaultScopes, defaultAudiences, defaultClientIds, - ImmutableList.of(PassAuthenticator.class), - ImmutableList.of(PassPeerAuthenticator.class)); + ImmutableList.of(PassAuthenticator.class)); assertEquals(1, execute2.getParameterConfigs().size()); validateParameter(execute2.getParameterConfigs().get(0), "serialized", false, null, SimpleBean.class, DumbSerializer1.class, String.class); @@ -1387,8 +1366,7 @@ private void validateMethod(ApiMethodConfig method, String name, String path, St String[] scopes, String[] audiences, String[] clientIds, - List authenticators, - List peerAuthenticators) { + List authenticators) { assertEquals(name, method.getName()); assertEquals(path, method.getPath()); assertEquals(httpMethod, method.getHttpMethod()); @@ -1396,7 +1374,6 @@ private void validateMethod(ApiMethodConfig method, String name, String path, St assertEquals(Arrays.asList(audiences), method.getAudiences()); assertEquals(Arrays.asList(clientIds), method.getClientIds()); assertEquals(authenticators, method.getAuthenticators()); - assertEquals(peerAuthenticators, method.getPeerAuthenticators()); } private void validateMethodForAuth(ApiMethodConfig method, String[] scopes, String[] audiences, diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiMethodAnnotationConfigTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiMethodAnnotationConfigTest.java index c97dfff1..a86c5d1c 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiMethodAnnotationConfigTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiMethodAnnotationConfigTest.java @@ -21,11 +21,9 @@ import com.google.api.server.spi.EndpointMethod; import com.google.api.server.spi.TypeLoader; import com.google.api.server.spi.auth.EndpointsAuthenticator; -import com.google.api.server.spi.auth.EndpointsPeerAuthenticator; import com.google.api.server.spi.config.Api; import com.google.api.server.spi.config.AuthLevel; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import com.google.api.server.spi.config.model.ApiClassConfig; import com.google.api.server.spi.config.model.ApiConfig; import com.google.api.server.spi.config.model.ApiMethodConfig; @@ -33,7 +31,6 @@ import com.google.api.server.spi.config.scope.AuthScopeExpression; import com.google.api.server.spi.config.scope.AuthScopeExpressions; import com.google.api.server.spi.testing.PassAuthenticator; -import com.google.api.server.spi.testing.PassPeerAuthenticator; import com.google.api.server.spi.testing.TestEndpoint; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; @@ -67,8 +64,6 @@ public class ApiMethodAnnotationConfigTest { private static final List defaultClientIds = Lists.newArrayList("c1", "c2"); private static final List> defaultAuthenticators = ImmutableList.>of(EndpointsAuthenticator.class); - private static final List> defaultPeerAuthenticators = - ImmutableList.>of(EndpointsPeerAuthenticator.class); @Before public void setUp() throws Exception { @@ -81,8 +76,6 @@ public void setUp() throws Exception { Mockito.when(apiClassConfig.getClientIds()).thenReturn(defaultClientIds); Mockito.>>when(apiClassConfig.getAuthenticators()) .thenReturn(defaultAuthenticators); - Mockito.>>when(apiClassConfig.getPeerAuthenticators()) - .thenReturn(defaultPeerAuthenticators); Mockito.when(apiClassConfig.getApiClassJavaSimpleName()).thenReturn( TestEndpoint.class.getSimpleName()); Mockito.when(apiConfig.getSerializationConfig()).thenReturn(serializationConfig); @@ -104,7 +97,6 @@ public void testDefaults() { assertEquals(defaultAudiences, config.getAudiences()); assertEquals(defaultClientIds, config.getClientIds()); assertEquals(defaultAuthenticators, config.getAuthenticators()); - assertEquals(defaultPeerAuthenticators, config.getPeerAuthenticators()); } @Test @@ -361,29 +353,6 @@ public void testSetAuthenticatorIfSpecified_unspecified() throws Exception { assertEquals(Arrays.asList(PassAuthenticator.testArray), config.getAuthenticators()); } - @Test - public void testPeerSetAuthenticatorIfSpecified() throws Exception { - annotationConfig.setPeerAuthenticatorsIfSpecified(PassPeerAuthenticator.testArray); - assertEquals(Arrays.asList(PassPeerAuthenticator.testArray), config.getPeerAuthenticators()); - } - - // Unchecked cast needed to get a generic array type. - @SuppressWarnings("unchecked") - public void testSetPeerAuthenticatorIfSpecified_unspecified() throws Exception { - Class[] unspecified = {PeerAuthenticator.class}; - Class[] unspecifiedConverted = - (Class[]) unspecified; - - testDefaults(); - - annotationConfig.setPeerAuthenticatorsIfSpecified(unspecifiedConverted); - testDefaults(); - - annotationConfig.setPeerAuthenticatorsIfSpecified(PassPeerAuthenticator.testArray); - annotationConfig.setPeerAuthenticatorsIfSpecified(unspecifiedConverted); - assertEquals(Arrays.asList(PassPeerAuthenticator.testArray), config.getPeerAuthenticators()); - } - private static AuthScopeExpression toScopeExpression(String... scopes) { return AuthScopeExpressions.interpret(scopes); } diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiConfigTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiConfigTest.java index 500e378f..3da29f0d 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiConfigTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiConfigTest.java @@ -20,12 +20,10 @@ import com.google.api.server.spi.ServiceContext; import com.google.api.server.spi.TypeLoader; -import com.google.api.server.spi.auth.EndpointsPeerAuthenticator; import com.google.api.server.spi.auth.GoogleJwtAuthenticator; import com.google.api.server.spi.config.ApiConfigInconsistency; import com.google.api.server.spi.config.AuthLevel; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import com.google.api.server.spi.config.scope.AuthScopeExpressions; import com.google.api.server.spi.testing.DumbSerializer1; import com.google.api.server.spi.testing.FloatToStringSerializer; @@ -177,8 +175,6 @@ public void testCopyConstructor() { apiConfig.setClientIds(ImmutableList.of("clientid")); apiConfig.setAuthenticators( ImmutableList.>of(GoogleJwtAuthenticator.class)); - apiConfig.setPeerAuthenticators( - ImmutableList.>of(EndpointsPeerAuthenticator.class)); assertThat(apiConfig).isEqualTo(new ApiConfig(apiConfig)); } } diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiMethodConfigTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiMethodConfigTest.java index b71a8ec1..712d1800 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiMethodConfigTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/model/ApiMethodConfigTest.java @@ -32,7 +32,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.List; diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/validation/ApiConfigValidatorTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/validation/ApiConfigValidatorTest.java index 632e66d4..9211b679 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/validation/ApiConfigValidatorTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/validation/ApiConfigValidatorTest.java @@ -34,7 +34,6 @@ import com.google.api.server.spi.config.ApiIssuerAudience; import com.google.api.server.spi.config.ApiMethod; import com.google.api.server.spi.config.Authenticator; -import com.google.api.server.spi.config.PeerAuthenticator; import com.google.api.server.spi.config.Transformer; import com.google.api.server.spi.config.model.ApiConfig; import com.google.api.server.spi.config.model.SchemaRepository; @@ -42,7 +41,6 @@ import com.google.api.server.spi.testing.DefaultValueSerializer; import com.google.api.server.spi.testing.DuplicateMethodEndpoint; import com.google.api.server.spi.testing.PassAuthenticator; -import com.google.api.server.spi.testing.PassPeerAuthenticator; import com.google.api.server.spi.testing.TestEndpoint; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; @@ -572,72 +570,6 @@ public User authenticate(HttpServletRequest request) { } } - @Test - public void testValidatePeerAuthenticator() throws Exception { - config.getApiClassConfig().getMethods() - .get(methodToEndpointMethod(TestEndpoint.class.getMethod("getResultNoParams"))) - .setPeerAuthenticators( - ImmutableList.>of(PassPeerAuthenticator.class)); - - validator.validate(config); - } - - @Test - public void testValidatePeerAuthenticator_noNullary() throws Exception { - final class InvalidPeerAuthenticator implements PeerAuthenticator { - @SuppressWarnings("unused") - public InvalidPeerAuthenticator(int x) {} - - @SuppressWarnings("unused") - @Override - public boolean authenticate(HttpServletRequest request) { - return false; - } - } - - config.getApiClassConfig().getMethods() - .get(methodToEndpointMethod(TestEndpoint.class.getMethod("getResultNoParams"))) - .setPeerAuthenticators( - ImmutableList.>of(InvalidPeerAuthenticator.class)); - - try { - validator.validate(config); - fail(); - } catch (InvalidConstructorException expected) { - assertTrue(expected.getMessage().contains("Invalid custom peer authenticator")); - assertTrue(expected.getMessage().endsWith( - "InvalidPeerAuthenticator. It must have a public nullary constructor.")); - } - } - - @Test - public void testValidatePeerAuthenticator_privateNullary() throws Exception { - final class InvalidPeerAuthenticator implements PeerAuthenticator { - @SuppressWarnings("unused") - private InvalidPeerAuthenticator() {} - - @SuppressWarnings("unused") - @Override - public boolean authenticate(HttpServletRequest request) { - return false; - } - } - - config.getApiClassConfig().getMethods() - .get(methodToEndpointMethod(TestEndpoint.class.getMethod("getResultNoParams"))) - .setPeerAuthenticators( - ImmutableList.>of(InvalidPeerAuthenticator.class)); - - try { - validator.validate(config); - fail(); - } catch (InvalidConstructorException expected) { - assertTrue(expected.getMessage().contains("Invalid custom peer authenticator")); - assertTrue(expected.getMessage().endsWith( - "InvalidPeerAuthenticator. It must have a public nullary constructor.")); - } - } - @Test public void testValidateMethods_ignoredMethod() throws Exception { final class Bean { diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/request/AttributeTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/request/AttributeTest.java index 7e107833..44a441fd 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/request/AttributeTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/request/AttributeTest.java @@ -52,31 +52,17 @@ public void setUp() { request = new MockHttpServletRequest(); } - @Test - public void bindStandardRequestAttributes_restricted() throws Exception { - when(methodConfig.getClientIds()).thenReturn(null); - - ServletInitializationParameters initParams = - createInitParams(true /* restricted */, true /* clientIdWhitelistEnabled */); - Attribute attr = Attribute.bindStandardRequestAttributes(request, methodConfig, initParams); - assertTrue(attr.isEnabled(Attribute.RESTRICT_SERVLET)); - - initParams = createInitParams(false /* restricted */, true /* clientIdWhitelistEnabled */); - attr = Attribute.bindStandardRequestAttributes(request, methodConfig, initParams); - assertFalse(attr.isEnabled(Attribute.RESTRICT_SERVLET)); - } - @Test public void bindStandardRequestAttributes_clientIdWhitelist() throws Exception { when(methodConfig.getClientIds()).thenReturn(null); ServletInitializationParameters initParams = - createInitParams(true /* restricted */, true /* clientIdWhitelistEnabled */); + createInitParams(true /* clientIdWhitelistEnabled */); Attribute attr = Attribute.bindStandardRequestAttributes(request, methodConfig, initParams); assertTrue(attr.isEnabled(Attribute.ENABLE_CLIENT_ID_WHITELIST)); attr.remove(Attribute.ENABLE_CLIENT_ID_WHITELIST); - initParams = createInitParams(true /* restricted */, false /* clientIdWhitelistEnabled */); + initParams = createInitParams(false /* clientIdWhitelistEnabled */); attr = Attribute.bindStandardRequestAttributes(request, methodConfig, initParams); assertFalse(attr.isEnabled(Attribute.ENABLE_CLIENT_ID_WHITELIST)); } @@ -84,19 +70,19 @@ public void bindStandardRequestAttributes_clientIdWhitelist() throws Exception { @Test public void bindStandardRequestAttributes_skipTokenAuth() throws Exception { ServletInitializationParameters initParams = - createInitParams(true /* restricted */, true /* clientIdWhitelistEnabled */); + createInitParams(true /* clientIdWhitelistEnabled */); when(methodConfig.getClientIds()).thenReturn(null); Attribute attr = Attribute.bindStandardRequestAttributes(request, methodConfig, initParams); assertTrue(attr.isEnabled(Attribute.SKIP_TOKEN_AUTH)); attr.remove(Attribute.SKIP_TOKEN_AUTH); - initParams = createInitParams(true /* restricted */, true /* clientIdWhitelistEnabled */); + initParams = createInitParams(true /* clientIdWhitelistEnabled */); when(methodConfig.getClientIds()).thenReturn(ImmutableList.of("clientId")); attr = Attribute.bindStandardRequestAttributes(request, methodConfig, initParams); assertFalse(attr.isEnabled(Attribute.SKIP_TOKEN_AUTH)); attr.remove(Attribute.SKIP_TOKEN_AUTH); - initParams = createInitParams(true /* restricted */, false /* clientIdWhitelistEnabled */); + initParams = createInitParams(false /* clientIdWhitelistEnabled */); attr = Attribute.bindStandardRequestAttributes(request, methodConfig, initParams); assertFalse(attr.isEnabled(Attribute.SKIP_TOKEN_AUTH)); } @@ -105,7 +91,7 @@ public void bindStandardRequestAttributes_skipTokenAuth() throws Exception { public void bindStandardRequestAttributes_apiMethodConfig() throws Exception { when(methodConfig.getClientIds()).thenReturn(null); ServletInitializationParameters initParams = - createInitParams(true /* restricted */, true /* clientIdWhitelistEnabled */); + createInitParams(true /* clientIdWhitelistEnabled */); Attribute attr = Attribute.bindStandardRequestAttributes(request, methodConfig, initParams); assertEquals(attr.get(Attribute.API_METHOD_CONFIG), methodConfig); } @@ -116,10 +102,8 @@ public void bindStandardRequestAttributes_apiMethodConfig() throws Exception { * * @throws ServletException */ - protected ServletInitializationParameters createInitParams(boolean restricted, - boolean clientIdWhitelistEnabled) throws Exception { + protected ServletInitializationParameters createInitParams(boolean clientIdWhitelistEnabled) throws Exception { return ServletInitializationParameters.builder() - .setRestricted(restricted) .setClientIdWhitelistEnabled(clientIdWhitelistEnabled) .build(); } diff --git a/test-utils/src/main/java/com/google/api/server/spi/testing/Endpoint1.java b/test-utils/src/main/java/com/google/api/server/spi/testing/Endpoint1.java index e133d67e..9dafc4c2 100644 --- a/test-utils/src/main/java/com/google/api/server/spi/testing/Endpoint1.java +++ b/test-utils/src/main/java/com/google/api/server/spi/testing/Endpoint1.java @@ -69,7 +69,6 @@ audiences = {"aa0", "aa1"}, clientIds = {"cc0", "cc1"}, authenticators = { PassAuthenticator.class }, - peerAuthenticators = { PassPeerAuthenticator.class }, defaultVersion = AnnotationBoolean.TRUE, transformers = { DumbSerializer1.class }, useDatastoreForAdditionalConfig = AnnotationBoolean.TRUE @@ -87,8 +86,7 @@ public class Endpoint1 { scopes = {"s0", "s1 s2"}, audiences = {"a0", "a1"}, clientIds = {"c0", "c1"}, - authenticators = { FailAuthenticator.class }, - peerAuthenticators = { FailPeerAuthenticator.class } + authenticators = { FailAuthenticator.class } ) public List listFoos() { return null; diff --git a/test-utils/src/main/java/com/google/api/server/spi/testing/FailPeerAuthenticator.java b/test-utils/src/main/java/com/google/api/server/spi/testing/FailPeerAuthenticator.java deleted file mode 100644 index ce6497fe..00000000 --- a/test-utils/src/main/java/com/google/api/server/spi/testing/FailPeerAuthenticator.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2016 Google Inc. 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 com.google.api.server.spi.testing; - -import com.google.api.server.spi.config.PeerAuthenticator; - -import javax.servlet.http.HttpServletRequest; - -/** - * Simple dumb peer authenticator for tests that always fail. - */ -public class FailPeerAuthenticator implements PeerAuthenticator { - @Override - public boolean authenticate(HttpServletRequest request) { - return false; - } - - public static Class[] testArray = makeTestArray(); - - // Unchecked cast needed to get a generic array type. - @SuppressWarnings("unchecked") - private static Class[] makeTestArray() { - Class[] peerAuthenticators = {FailPeerAuthenticator.class}; - return (Class[]) peerAuthenticators; - } -} diff --git a/test-utils/src/main/java/com/google/api/server/spi/testing/PassPeerAuthenticator.java b/test-utils/src/main/java/com/google/api/server/spi/testing/PassPeerAuthenticator.java deleted file mode 100644 index 6beb1665..00000000 --- a/test-utils/src/main/java/com/google/api/server/spi/testing/PassPeerAuthenticator.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2016 Google Inc. 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 com.google.api.server.spi.testing; - -import com.google.api.server.spi.config.PeerAuthenticator; -import com.google.api.server.spi.config.Singleton; - -import javax.servlet.http.HttpServletRequest; - -/** - * Simple dumb peer authenticator for tests that always pass. - */ -@Singleton -public class PassPeerAuthenticator implements PeerAuthenticator { - @Override - public boolean authenticate(HttpServletRequest request) { - return true; - } - - public static Class[] testArray = makeTestArray(); - - // Unchecked cast needed to get a generic array type. - @SuppressWarnings("unchecked") - private static Class[] makeTestArray() { - Class[] peerAuthenticators = {PassPeerAuthenticator.class}; - return (Class[]) peerAuthenticators; - } -} From 61e2634d95fec3e8adabf720f3fc208c75715bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Denis?= Date: Fri, 25 Oct 2019 19:17:36 +0200 Subject: [PATCH 08/12] Remove deprecated root and backendRoot on @Api --- .../com/google/api/server/spi/config/Api.java | 20 ++----------------- .../ApiConfigAnnotationReader.java | 9 --------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/Api.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/Api.java index 274e184f..20bd2d06 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/Api.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/Api.java @@ -26,16 +26,8 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Api { - public static final int UNSPECIFIED_INT = Integer.MIN_VALUE; - public static final String UNSPECIFIED_STRING_FOR_LIST = "_UNSPECIFIED_LIST_STRING_VALUE"; - - /** - * Frontend root URL, e.g. "https://example.appspot.com/_ah/api". All api - * methods will be exposed below this path. This will default to - * "https://yourapp.appspot.com/_ah/api". - */ - @Deprecated - String root() default ""; + int UNSPECIFIED_INT = Integer.MIN_VALUE; + String UNSPECIFIED_STRING_FOR_LIST = "_UNSPECIFIED_LIST_STRING_VALUE"; /** * Name of the API, e.g. "guestbook". This is used as the prefix for all api @@ -73,14 +65,6 @@ */ String documentationLink() default ""; - /** - * Backend root URL, e.g. "https://example.appspot.com/_ah/spi". This is the root of all backend - * method calls. This will default to "https://yourapp.appspot.com/_ah/spi". Non-secure http URLs - * will be automatically converted to use https. - */ - @Deprecated - String backendRoot() default ""; - /** * Configures authentication information. See {@link ApiAuth} for details. */ diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiConfigAnnotationReader.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiConfigAnnotationReader.java index 44b6b9b8..a2e3d3b5 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiConfigAnnotationReader.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/annotationreader/ApiConfigAnnotationReader.java @@ -19,14 +19,10 @@ import com.google.api.server.spi.MethodHierarchyReader; import com.google.api.server.spi.ServiceContext; import com.google.api.server.spi.TypeLoader; -import com.google.api.server.spi.config.AnnotationBoolean; import com.google.api.server.spi.config.ApiConfigException; import com.google.api.server.spi.config.ApiConfigSource; import com.google.api.server.spi.config.ApiIssuer; import com.google.api.server.spi.config.ApiIssuerAudience; -import com.google.api.server.spi.config.ApiLimitMetric; -import com.google.api.server.spi.config.ApiMetricCost; -import com.google.api.server.spi.config.AuthLevel; import com.google.api.server.spi.config.Authenticator; import com.google.api.server.spi.config.Transformer; import com.google.api.server.spi.config.model.ApiClassConfig; @@ -40,13 +36,11 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.reflect.TypeToken; - import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collection; import java.util.Map; - import javax.annotation.Nullable; /** @@ -180,7 +174,6 @@ private boolean readEndpointClass(ApiConfig config, Class endpointClass, Anno private void readApi(ApiAnnotationConfig config, Annotation api) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { config.setIsAbstractIfSpecified(getAnnotationProperty(api, "isAbstract")); - config.setRootIfNotEmpty(getAnnotationProperty(api, "root")); config.setNameIfNotEmpty(getAnnotationProperty(api, "name")); config.setCanonicalNameIfNotEmpty(getAnnotationProperty(api, "canonicalName")); @@ -196,8 +189,6 @@ private void readApi(ApiAnnotationConfig config, Annotation api) config.setUseDatastoreIfSpecified( getAnnotationProperty(api, "useDatastoreForAdditionalConfig")); - config.setBackendRootIfNotEmpty(getAnnotationProperty(api, "backendRoot")); - config.setResourceIfNotEmpty(getAnnotationProperty(api, "resource")); config.setAuthLevelIfSpecified(getAnnotationProperty(api, "authLevel")); config.setScopesIfSpecified(getAnnotationProperty(api, "scopes")); From a55b6132120a40f2e0d54a657e141377f51f3876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Denis?= Date: Fri, 25 Oct 2019 19:18:09 +0200 Subject: [PATCH 09/12] Remove deprecated method level cache control --- .../api/server/spi/config/ApiMethod.java | 10 ----- .../spi/config/ApiMethodCacheControl.java | 45 ------------------- .../api/server/spi/testing/Endpoint1.java | 29 ++---------- .../testing/ReferenceOverridingEndpoint.java | 7 +-- .../testing/SubclassedOverridingEndpoint.java | 4 +- 5 files changed, 6 insertions(+), 89 deletions(-) delete mode 100644 endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiMethodCacheControl.java diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiMethod.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiMethod.java index bd0b5f5c..cfcddc9a 100644 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiMethod.java +++ b/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiMethod.java @@ -67,16 +67,6 @@ public static class HttpMethod { */ String httpMethod() default ""; - /** - * Cache-Control header settings for this method. See - * {@link ApiMethodCacheControl} for details. - * - * @deprecated ApiMethodCacheControl is deprecated and will be removed in a future version of - * Cloud Endpoints. - */ - @Deprecated - ApiMethodCacheControl cacheControl() default @ApiMethodCacheControl; - /** * Set frontend auth level. */ diff --git a/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiMethodCacheControl.java b/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiMethodCacheControl.java deleted file mode 100644 index 49141f2a..00000000 --- a/endpoints-framework/src/main/java/com/google/api/server/spi/config/ApiMethodCacheControl.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2016 Google Inc. 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 com.google.api.server.spi.config; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for configuration of API method cache control. - * @deprecated ApiMethodCacheControl is deprecated and will be removed in a future version of - * Cloud Endpoints. - */ -// TODO: Delete this after a sufficient deprecation period. -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -@Deprecated -public @interface ApiMethodCacheControl { - - /** - * Disables caching of this method. The default value is true, so merely - * adding this annotation to your method config will disable caching for that - * method, unless you set this field to {@code false}. - */ - boolean noCache() default true; - - /** - * Overrides the maximum age to cache responses from this method. - */ - int maxAge() default 0; -} diff --git a/test-utils/src/main/java/com/google/api/server/spi/testing/Endpoint1.java b/test-utils/src/main/java/com/google/api/server/spi/testing/Endpoint1.java index 9dafc4c2..dfcdae27 100644 --- a/test-utils/src/main/java/com/google/api/server/spi/testing/Endpoint1.java +++ b/test-utils/src/main/java/com/google/api/server/spi/testing/Endpoint1.java @@ -23,7 +23,6 @@ import com.google.api.server.spi.config.ApiFrontendLimits; import com.google.api.server.spi.config.ApiMethod; import com.google.api.server.spi.config.ApiMethod.HttpMethod; -import com.google.api.server.spi.config.ApiMethodCacheControl; import com.google.api.server.spi.config.Named; import com.google.api.server.spi.config.Nullable; @@ -79,10 +78,6 @@ public class Endpoint1 { name = "foos.list", path = "foos", httpMethod = HttpMethod.GET, - cacheControl = @ApiMethodCacheControl( - noCache = true, - maxAge = 1 - ), scopes = {"s0", "s1 s2"}, audiences = {"a0", "a1"}, clientIds = {"c0", "c1"}, @@ -95,11 +90,7 @@ public List listFoos() { @ApiMethod( name = "foos.get", path = "foos/{id}", - httpMethod = HttpMethod.GET, - cacheControl = @ApiMethodCacheControl( - noCache = false, - maxAge = 2 - ) + httpMethod = HttpMethod.GET ) public Foo getFoo(@Named("id") String id) { return null; @@ -108,11 +99,7 @@ public Foo getFoo(@Named("id") String id) { @ApiMethod( name = "foos.insert", path = "foos", - httpMethod = HttpMethod.POST, - cacheControl = @ApiMethodCacheControl( - noCache = false, - maxAge = 3 - ) + httpMethod = HttpMethod.POST ) public Foo insertFoo(Foo r) { return null; @@ -121,11 +108,7 @@ public Foo insertFoo(Foo r) { @ApiMethod( name = "foos.update", path = "foos/{id}", - httpMethod = HttpMethod.PUT, - cacheControl = @ApiMethodCacheControl( - noCache = false, - maxAge = 4 - ) + httpMethod = HttpMethod.PUT ) public Foo updateFoo(@Named("id") String id, Foo r) { return null; @@ -134,11 +117,7 @@ public Foo updateFoo(@Named("id") String id, Foo r) { @ApiMethod( name = "foos.remove", path = "foos/{id}", - httpMethod = HttpMethod.DELETE, - cacheControl = @ApiMethodCacheControl( - noCache = false, - maxAge = 5 - ) + httpMethod = HttpMethod.DELETE ) public void removeFoo(@Named("id") String id) { } diff --git a/test-utils/src/main/java/com/google/api/server/spi/testing/ReferenceOverridingEndpoint.java b/test-utils/src/main/java/com/google/api/server/spi/testing/ReferenceOverridingEndpoint.java index 130a97b2..a90ccda4 100644 --- a/test-utils/src/main/java/com/google/api/server/spi/testing/ReferenceOverridingEndpoint.java +++ b/test-utils/src/main/java/com/google/api/server/spi/testing/ReferenceOverridingEndpoint.java @@ -20,7 +20,6 @@ import com.google.api.server.spi.config.ApiFrontendLimits; import com.google.api.server.spi.config.ApiMethod; import com.google.api.server.spi.config.ApiMethod.HttpMethod; -import com.google.api.server.spi.config.ApiMethodCacheControl; import com.google.api.server.spi.config.ApiReference; import javax.inject.Named; @@ -45,11 +44,7 @@ public class ReferenceOverridingEndpoint extends SubclassedOverridingEndpoint { @ApiMethod( name = "foos.get3", path = "foos/{id}", - httpMethod = HttpMethod.GET, - cacheControl = @ApiMethodCacheControl( - noCache = false, - maxAge = 2 - ) + httpMethod = HttpMethod.GET ) @Override public Foo getFoo(@Named("id") String id) { diff --git a/test-utils/src/main/java/com/google/api/server/spi/testing/SubclassedOverridingEndpoint.java b/test-utils/src/main/java/com/google/api/server/spi/testing/SubclassedOverridingEndpoint.java index a9e2718b..8aad066e 100644 --- a/test-utils/src/main/java/com/google/api/server/spi/testing/SubclassedOverridingEndpoint.java +++ b/test-utils/src/main/java/com/google/api/server/spi/testing/SubclassedOverridingEndpoint.java @@ -20,7 +20,6 @@ import com.google.api.server.spi.config.ApiCacheControl; import com.google.api.server.spi.config.ApiFrontendLimits; import com.google.api.server.spi.config.ApiMethod; -import com.google.api.server.spi.config.ApiMethodCacheControl; import java.util.Collections; import java.util.List; @@ -53,8 +52,7 @@ public List listFoos() { // Override a config. @ApiMethod( - name = "foos.get2", - cacheControl = @ApiMethodCacheControl(maxAge = 4) + name = "foos.get2" ) @Override public Foo getFoo(@Named("id") String id) { From a34f82f1ccee212df741457a460526d6e5d224a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Denis?= Date: Fri, 25 Oct 2019 19:18:37 +0200 Subject: [PATCH 10/12] Remove code for legacy servlet mode --- .../api/server/spi/guice/EndpointsModule.java | 39 +-------------- .../server/spi/guice/EndpointsModuleTest.java | 50 ++++--------------- 2 files changed, 12 insertions(+), 77 deletions(-) diff --git a/endpoints-framework-guice/src/main/java/com/google/api/server/spi/guice/EndpointsModule.java b/endpoints-framework-guice/src/main/java/com/google/api/server/spi/guice/EndpointsModule.java index ee7814eb..694c7832 100644 --- a/endpoints-framework-guice/src/main/java/com/google/api/server/spi/guice/EndpointsModule.java +++ b/endpoints-framework-guice/src/main/java/com/google/api/server/spi/guice/EndpointsModule.java @@ -25,7 +25,6 @@ * this class and call one of the helpers in {@link #configureServlets()}. */ public class EndpointsModule extends ServletModule { - private static final Logger logger = Logger.getLogger(EndpointsModule.class.getName()); /** * Configure Endpoints given a list of service classes using {@link GuiceEndpointsServlet}. * @@ -36,40 +35,10 @@ public class EndpointsModule extends ServletModule { */ protected void configureEndpoints( String urlPattern, Iterable> serviceClasses) { - configureEndpoints(urlPattern, serviceClasses, false); - } - - /** - * Configure Endpoints given a list of service classes. - * - * @deprecated the legacy servlet is no longer available. - * @param urlPattern the URL pattern to configure the servlet on. For the legacy servlet, use - * "/_ah/spi/*". For the new servlet, use "/_ah/api/*" if backwards compatibility is desired, or - * any other pattern if compatibility is not an issue. - * @param serviceClasses the list of backend classes to be included - * @param useLegacyServlet whether or not to use the old style servlet - */ - @Deprecated - protected void configureEndpoints( - String urlPattern, Iterable> serviceClasses, boolean useLegacyServlet) { ServletInitializationParameters initParameters = ServletInitializationParameters.builder() .addServiceClasses(serviceClasses) .build(); - configureEndpoints(urlPattern, initParameters, useLegacyServlet); - } - - /** - * Configure Endpoints given {@link ServletInitializationParameters} using - * {@link GuiceEndpointsServlet}. - * - * @param urlPattern the URL pattern to configure the servlet on. For the legacy servlet, use - * "/_ah/spi/*". For the new servlet, use "/_ah/api/*" if backwards compatibility is desired, or - * any other pattern if compatibility is not an issue - * @param initParameters the initialization parameters. Must include service classes to be useful - */ - protected void configureEndpoints( - String urlPattern, ServletInitializationParameters initParameters) { - configureEndpoints(urlPattern, initParameters, false); + configureEndpoints(urlPattern, initParameters); } /** @@ -79,15 +48,11 @@ protected void configureEndpoints( * "/_ah/spi/*". For the new servlet, use "/_ah/api/*" if backwards compatibility is desired, or * any other pattern if compatibility is not an issue * @param initParameters the initialization parameters. Must include service classes to be useful - * @param useLegacyServlet whether or not to use the old style servlet */ protected void configureEndpoints( - String urlPattern, ServletInitializationParameters initParameters, boolean useLegacyServlet) { + String urlPattern, ServletInitializationParameters initParameters) { bind(ServiceMap.class) .toInstance(ServiceMap.create(binder(), initParameters.getServiceClasses())); - if (useLegacyServlet) { - logger.severe("the legacy servlet is no longer available."); - } super.serve(urlPattern).with(GuiceEndpointsServlet.class, initParameters.asMap()); } } diff --git a/endpoints-framework-guice/src/test/java/com/google/api/server/spi/guice/EndpointsModuleTest.java b/endpoints-framework-guice/src/test/java/com/google/api/server/spi/guice/EndpointsModuleTest.java index 83353df4..ada9972a 100644 --- a/endpoints-framework-guice/src/test/java/com/google/api/server/spi/guice/EndpointsModuleTest.java +++ b/endpoints-framework-guice/src/test/java/com/google/api/server/spi/guice/EndpointsModuleTest.java @@ -63,7 +63,7 @@ public void setUp() throws Exception { @Override protected void configureServlets() { super.configureServlets(); - configureEndpoints(URL_PATTERN, INIT_PARAMETERS, true); + configureEndpoints(URL_PATTERN, INIT_PARAMETERS); } }; Elements.getElements(module); @@ -111,64 +111,34 @@ public void testConfigureEndpoints_withoutInterceptor() { services.toArray()[0].getClass()); } - @Test - public void testConfigureEndpoints_legacyServletWithServices() { - testServletClassWithServices(true, GuiceEndpointsServlet.class); - } - - @Test - public void testConfigureEndpoints_newServletWithServices() { - testServletClassWithServices(false, GuiceEndpointsServlet.class); - } - @Test public void testConfigureEndpoints_defaultServletWithServices() { - testServletClassWithServices(null, GuiceEndpointsServlet.class); - } - - @Test - public void testConfigureEndpoints_legacyServletWithInitParams() { - testServletClassWithInitParams(true, GuiceEndpointsServlet.class); - } - - @Test - public void testConfigureEndpoints_newServletWithInitParams() { - testServletClassWithInitParams(false, GuiceEndpointsServlet.class); + testServletClassWithServices(GuiceEndpointsServlet.class); } @Test public void testConfigureEndpoints_defaultServletWithInitParams() { - testServletClassWithInitParams(null, GuiceEndpointsServlet.class); + testServletClassWithInitParams(GuiceEndpointsServlet.class); } - private void testServletClassWithServices(final Boolean servletFlag, Class expectedClass) { + private void testServletClassWithServices(Class expectedClass) { testServletClass(new EndpointsModule() { @Override protected void configureServlets() { super.configureServlets(); - if (servletFlag == null) { - configureEndpoints(URL_PATTERN, SERVICES); - } else { - configureEndpoints(URL_PATTERN, SERVICES, servletFlag); - } + configureEndpoints(URL_PATTERN, SERVICES); } }, expectedClass); } - private void testServletClassWithInitParams(final Boolean servletFlag, Class expectedClass) { + private void testServletClassWithInitParams(Class expectedClass) { testServletClass(new EndpointsModule() { @Override protected void configureServlets() { super.configureServlets(); - if (servletFlag == null) { - configureEndpoints(URL_PATTERN, ServletInitializationParameters.builder() - .addServiceClasses(SERVICES) - .build()); - } else { - configureEndpoints(URL_PATTERN, ServletInitializationParameters.builder() - .addServiceClasses(SERVICES) - .build(), servletFlag); - } + configureEndpoints(URL_PATTERN, ServletInitializationParameters.builder() + .addServiceClasses(SERVICES) + .build()); } }, expectedClass); } @@ -194,7 +164,7 @@ public void testConfigureEndpoints_defaultInitParameters() { @Override protected void configureServlets() { super.configureServlets(); - configureEndpoints(URL_PATTERN, SERVICES, true); + configureEndpoints(URL_PATTERN, SERVICES); } }; Injector injector = Guice.createInjector(module, new DummyModule()); From 370e08fa2f149aa04da1bb5f5c9712f06a17e7bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Denis?= Date: Fri, 25 Oct 2019 19:19:04 +0200 Subject: [PATCH 11/12] Various code updates for deprecated methods --- .../google/api/server/spi/tools/GetDiscoveryDocAction.java | 2 +- .../java/com/google/api/server/spi/tools/JacksonUtil.java | 2 +- .../annotationreader/ApiAnnotationIntrospectorTest.java | 2 +- .../server/spi/response/ServletResponseResultWriterTest.java | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/endpoints-framework-tools/src/main/java/com/google/api/server/spi/tools/GetDiscoveryDocAction.java b/endpoints-framework-tools/src/main/java/com/google/api/server/spi/tools/GetDiscoveryDocAction.java index 83b84e30..b5a26d3f 100644 --- a/endpoints-framework-tools/src/main/java/com/google/api/server/spi/tools/GetDiscoveryDocAction.java +++ b/endpoints-framework-tools/src/main/java/com/google/api/server/spi/tools/GetDiscoveryDocAction.java @@ -140,7 +140,7 @@ apiConfigs, new DiscoveryContext().setHostname(hostname).setBasePath(basePath), outputDir + "/" + key.getName() + "-" + key.getVersion() + "-rest.discovery"; String docString = writer.writeValueAsString(entry.getValue()); if (outputToDisk) { - Files.write(docString, new File(discoveryDocFilePath), UTF_8); + Files.asCharSink(new File(discoveryDocFilePath), UTF_8).write(docString); System.out.println("API Discovery Document written to " + discoveryDocFilePath); } builder.put(discoveryDocFilePath, docString); diff --git a/endpoints-framework-tools/src/main/java/com/google/api/server/spi/tools/JacksonUtil.java b/endpoints-framework-tools/src/main/java/com/google/api/server/spi/tools/JacksonUtil.java index 14788742..b15a46f4 100644 --- a/endpoints-framework-tools/src/main/java/com/google/api/server/spi/tools/JacksonUtil.java +++ b/endpoints-framework-tools/src/main/java/com/google/api/server/spi/tools/JacksonUtil.java @@ -47,7 +47,7 @@ public static ObjectNode mergeObject(ObjectNode object1, ObjectNode object2, JsonNode child2 = object2.get(fieldName); JsonNode child1 = object1.get(fieldName); JsonNode merged = (child1 == null) ? child2 : mergeNode(child1, child2, throwOnConflict); - object1.put(fieldName, merged); + object1.set(fieldName, merged); } return object1; } diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiAnnotationIntrospectorTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiAnnotationIntrospectorTest.java index 05ded3fd..6b7d769d 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiAnnotationIntrospectorTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/config/annotationreader/ApiAnnotationIntrospectorTest.java @@ -593,7 +593,7 @@ public TestResourceWithCustomSerializer transformFrom(Map in) { try { obj = clazz.newInstance(); } catch (Exception e) { - Throwables.propagate(e); + throw new RuntimeException(e); } obj.point = String.format("%d,%d", MoreObjects.firstNonNull(in.get("x"), 0), diff --git a/endpoints-framework/src/test/java/com/google/api/server/spi/response/ServletResponseResultWriterTest.java b/endpoints-framework/src/test/java/com/google/api/server/spi/response/ServletResponseResultWriterTest.java index f6799d17..3d240378 100644 --- a/endpoints-framework/src/test/java/com/google/api/server/spi/response/ServletResponseResultWriterTest.java +++ b/endpoints-framework/src/test/java/com/google/api/server/spi/response/ServletResponseResultWriterTest.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertTrue; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.json.JsonWriteFeature; import com.fasterxml.jackson.databind.ObjectWriter; import com.google.api.server.spi.ObjectMapperUtil; import com.google.api.server.spi.ServiceException; @@ -486,7 +486,7 @@ private ServletResponseResultWriter createCustomizedWriter(HttpServletResponse r ServletResponseResultWriter writer = new ServletResponseResultWriter(response, null) { @Override protected ObjectWriter configureWriter(ObjectWriter objectWriter) { - return objectWriter.withoutFeatures(JsonGenerator.Feature.QUOTE_FIELD_NAMES); + return objectWriter.withoutFeatures(JsonWriteFeature.QUOTE_FIELD_NAMES); } }; return writer; From 4088d7646aaf48601b15d1fad8bff3e259843404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Denis?= Date: Fri, 25 Oct 2019 17:10:28 +0200 Subject: [PATCH 12/12] Update to 2.4.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index cb815639..242bca38 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=2.3.4 +version=2.4.0 sourceCompatibility=1.8 targetCompatibility=1.8