You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/09/07 03:14:09 UTC
[incubator-servicecomb-java-chassis] 03/03: [SCB-897] add IT for
servicecomb.rest.server.maxInitialLineLength config
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit bb7728097395125485aaff0fbd08edde28107dff
Author: yaohaishi <ya...@huawei.com>
AuthorDate: Fri Sep 7 00:56:37 2018 +0800
[SCB-897] add IT for servicecomb.rest.server.maxInitialLineLength config
---
.../org/apache/servicecomb/it/ConsumerMain.java | 3 +
.../it/testcase/base/TestRestServerConfig.java | 67 ++++++++++++++++++++++
.../it/schema/RestServerConfigSchema.java | 34 +++++++++++
.../src/main/resources/microservice.yaml | 4 ++
4 files changed, 108 insertions(+)
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
index c35d0cf..a3b7704 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
@@ -28,6 +28,7 @@ import org.apache.servicecomb.it.testcase.TestParamCodec;
import org.apache.servicecomb.it.testcase.TestTrace;
import org.apache.servicecomb.it.testcase.TestTraceEdge;
import org.apache.servicecomb.it.testcase.base.TestParamCodecEdge;
+import org.apache.servicecomb.it.testcase.base.TestRestServerConfig;
public class ConsumerMain {
private static ResultPrinter resultPrinter = new ResultPrinter();
@@ -113,6 +114,8 @@ public class ConsumerMain {
ITJUnitUtils.runWithHighwayAndRest(TestParamCodec.class);
ITJUnitUtils.run(TestParamCodecEdge.class);
+ ITJUnitUtils.runWithRest(TestRestServerConfig.class);
+
ITJUnitUtils.getParents().pop();
deploys.getBaseProducer().stop();
}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestRestServerConfig.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestRestServerConfig.java
new file mode 100644
index 0000000..6192c7e
--- /dev/null
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestRestServerConfig.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.it.testcase.base;
+
+import org.apache.servicecomb.it.Consumers;
+import org.apache.servicecomb.it.junit.ITJUnitUtils;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.base.Strings;
+
+public class TestRestServerConfig {
+ // GET /v1/restServerConfig/testMaxInitialLineLength?q=...... HTTP/1.1
+ private static final String INITIAL_LINE_SUFFIX = " HTTP/1.1";
+
+ private static final String INITIAL_LINE_PREFIX = "GET /v1/restServerConfig/testMaxInitialLineLength?q=";
+
+ interface RestServerConfigSchemaIntf {
+ String testMaxInitialLineLength(String q);
+ }
+
+ static Consumers<RestServerConfigSchemaIntf> consumers = new Consumers<>("restServerConfig",
+ RestServerConfigSchemaIntf.class);
+
+ @BeforeClass
+ public static void classSetup() {
+ consumers.init(ITJUnitUtils.getTransport());
+ }
+
+ /**
+ * Max initial line length is set to 5000
+ */
+ @Test
+ public void testMaxInitialLineLength5000() {
+ String q = Strings.repeat("q", 5000 - INITIAL_LINE_PREFIX.length() - INITIAL_LINE_SUFFIX.length());
+ String result = consumers.getIntf().testMaxInitialLineLength(q);
+ Assert.assertEquals("OK", result);
+ }
+
+ @Test
+ public void testMaxInitialLineLength5001() {
+ String q = Strings.repeat("q", 5001 - INITIAL_LINE_PREFIX.length() - INITIAL_LINE_SUFFIX.length());
+ try {
+ consumers.getIntf().testMaxInitialLineLength(q.toString());
+ Assert.fail("an exception is expected!");
+ } catch (InvocationException e) {
+ Assert.assertEquals(414, e.getStatusCode());
+ }
+ }
+}
diff --git a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/RestServerConfigSchema.java b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/RestServerConfigSchema.java
new file mode 100644
index 0000000..d8a3dac
--- /dev/null
+++ b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/RestServerConfigSchema.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.servicecomb.it.schema;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+
+@RestSchema(schemaId = "restServerConfig")
+@Path("/v1/restServerConfig")
+public class RestServerConfigSchema {
+ @Path("/testMaxInitialLineLength")
+ @GET
+ public String testMaxInitialLineLength(@QueryParam("q") String q) {
+ return "OK";
+ }
+}
diff --git a/integration-tests/it-producer/src/main/resources/microservice.yaml b/integration-tests/it-producer/src/main/resources/microservice.yaml
index 102722d..2621253 100644
--- a/integration-tests/it-producer/src/main/resources/microservice.yaml
+++ b/integration-tests/it-producer/src/main/resources/microservice.yaml
@@ -18,3 +18,7 @@
service_description:
name: it-producer
+servicecomb:
+ rest:
+ server:
+ maxInitialLineLength: 5000
\ No newline at end of file