Jetty9 - Fixed a couple of tests (bad copy/paste) and ignored 2 tests due to pending considerations about how to properly handle 100-Continue.

This commit is contained in:
Simone Bordet 2012-08-23 17:18:29 +02:00
parent f118c77f90
commit 7a5997df9d
1 changed files with 168 additions and 209 deletions

View File

@ -24,11 +24,6 @@
*/
package org.eclipse.jetty.server;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
@ -40,8 +35,14 @@ import org.eclipse.jetty.server.handler.HandlerCollection;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
*
*/
@ -114,134 +115,123 @@ public class RFC2616Test
@Test
public void test3_6_a() throws Exception
{
String response=null;
int offset=0;
// Chunk last
response=connector.getResponses(
"GET /R1 HTTP/1.1\n"+
"Host: localhost\n"+
"Transfer-Encoding: chunked,identity\n"+
"Content-Type: text/plain\n"+
"\015\012"+
"5;\015\012"+
"123\015\012\015\012"+
"0;\015\012\015\012");
String response = connector.getResponses(
"GET /R1 HTTP/1.1\n" +
"Host: localhost\n" +
"Transfer-Encoding: chunked,identity\n" +
"Content-Type: text/plain\n" +
"\015\012" +
"5;\015\012" +
"123\015\012\015\012" +
"0;\015\012\015\012");
checkContains(response,offset,"HTTP/1.1 400 Bad","Chunked last");
}
@Test
public void test3_6_b() throws Exception
{
String response=null;
int offset=0;
// Chunked
response=connector.getResponses(
"GET /R1 HTTP/1.1\n"+
"Host: localhost\n"+
"Transfer-Encoding: chunked\n"+
"Content-Type: text/plain\n"+
"\n"+
"2;\n"+
"12\n"+
"3;\n"+
"345\n"+
"0;\n\n"+
String response = connector.getResponses(
"GET /R1 HTTP/1.1\n" +
"Host: localhost\n" +
"Transfer-Encoding: chunked\n" +
"Content-Type: text/plain\n" +
"\n" +
"2;\n" +
"12\n" +
"3;\n" +
"345\n" +
"0;\n\n" +
"GET /R2 HTTP/1.1\n"+
"Host: localhost\n"+
"Transfer-Encoding: chunked\n"+
"Content-Type: text/plain\n"+
"\n"+
"4;\n"+
"6789\n"+
"5;\n"+
"abcde\n"+
"0;\n\n"+
"GET /R2 HTTP/1.1\n" +
"Host: localhost\n" +
"Transfer-Encoding: chunked\n" +
"Content-Type: text/plain\n" +
"\n" +
"4;\n" +
"6789\n" +
"5;\n" +
"abcde\n" +
"0;\n\n" +
"GET /R3 HTTP/1.1\n"+
"Host: localhost\n"+
"Connection: close\n"+
"\n");
"GET /R3 HTTP/1.1\n" +
"Host: localhost\n" +
"Connection: close\n" +
"\n");
offset=checkContains(response,offset,"HTTP/1.1 200","3.6.1 Chunking");
offset=checkContains(response,offset,"12345","3.6.1 Chunking");
offset=checkContains(response,offset,"HTTP/1.1 200","3.6.1 Chunking");
offset=checkContains(response,offset,"6789abcde","3.6.1 Chunking");
offset=checkContains(response,offset,"/R3","3.6.1 Chunking");
}
@Test
public void test3_6_c() throws Exception
{
String response=null;
int offset=0;
String response = connector.getResponses(
"POST /R1 HTTP/1.1\n" +
"Host: localhost\n" +
"Transfer-Encoding: chunked\n" +
"Content-Type: text/plain\n" +
"\n" +
"3;\n" +
"fgh\n" +
"3;\n" +
"Ijk\n" +
"0;\n\n" +
response=connector.getResponses(
"POST /R1 HTTP/1.1\n"+
"Host: localhost\n"+
"Transfer-Encoding: chunked\n"+
"Content-Type: text/plain\n"+
"\n"+
"3;\n"+
"fgh\n"+
"3;\n"+
"Ijk\n"+
"0;\n\n"+
"POST /R2 HTTP/1.1\n" +
"Host: localhost\n" +
"Transfer-Encoding: chunked\n" +
"Content-Type: text/plain\n" +
"\n" +
"4;\n" +
"lmno\n" +
"5;\n" +
"Pqrst\n" +
"0;\n\n" +
"POST /R2 HTTP/1.1\n"+
"Host: localhost\n"+
"Transfer-Encoding: chunked\n"+
"Content-Type: text/plain\n"+
"\n"+
"4;\n"+
"lmno\n"+
"5;\n"+
"Pqrst\n"+
"0;\n\n"+
"GET /R3 HTTP/1.1\n"+
"Host: localhost\n"+
"Connection: close\n"+
"\n");
"GET /R3 HTTP/1.1\n" +
"Host: localhost\n" +
"Connection: close\n" +
"\n");
checkNotContained(response,"HTTP/1.1 100","3.6.1 Chunking");
offset=checkContains(response,offset,"HTTP/1.1 200","3.6.1 Chunking");
offset=checkContains(response,offset,"fghIjk","3.6.1 Chunking");
offset=checkContains(response,offset,"HTTP/1.1 200","3.6.1 Chunking");
offset=checkContains(response,offset,"lmnoPqrst","3.6.1 Chunking");
offset=checkContains(response,offset,"/R3","3.6.1 Chunking");
}
@Test
public void test3_6_d() throws Exception
{
String response=null;
int offset=0;
// Chunked and keep alive
response=connector.getResponses(
"GET /R1 HTTP/1.1\n"+
"Host: localhost\n"+
"Transfer-Encoding: chunked\n"+
"Content-Type: text/plain\n"+
"Connection: keep-alive\n"+
"\n"+
"3;\n"+
"123\n"+
"3;\n"+
"456\n"+
"0;\n\n"+
String response = connector.getResponses(
"GET /R1 HTTP/1.1\n" +
"Host: localhost\n" +
"Transfer-Encoding: chunked\n" +
"Content-Type: text/plain\n" +
"Connection: keep-alive\n" +
"\n" +
"3;\n" +
"123\n" +
"3;\n" +
"456\n" +
"0;\n\n" +
"GET /R2 HTTP/1.1\n"+
"Host: localhost\n"+
"Connection: close\n"+
"\n");
"GET /R2 HTTP/1.1\n" +
"Host: localhost\n" +
"Connection: close\n" +
"\n");
offset=checkContains(response,offset,"HTTP/1.1 200","3.6.1 Chunking")+10;
offset=checkContains(response,offset,"123456","3.6.1 Chunking");
offset=checkContains(response,offset,"/R2","3.6.1 Chunking")+10;
}
@Test
@ -252,14 +242,14 @@ public class RFC2616Test
HttpFields fields=new HttpFields();
fields.put("Q","bbb;q=0.5,aaa,ccc;q=0.002,d;q=0,e;q=0.0001,ddd;q=0.001,aa2,abb;q=0.7");
Enumeration qualities=fields.getValues("Q",", \t");
List list=HttpFields.qualityList(qualities);
assertEquals("Quality parameters","aaa",HttpFields.valueParameters(list.get(0).toString(),null));
assertEquals("Quality parameters","aa2",HttpFields.valueParameters(list.get(1).toString(),null));
assertEquals("Quality parameters","abb",HttpFields.valueParameters(list.get(2).toString(),null));
assertEquals("Quality parameters","bbb",HttpFields.valueParameters(list.get(3).toString(),null));
assertEquals("Quality parameters","ccc",HttpFields.valueParameters(list.get(4).toString(),null));
assertEquals("Quality parameters","ddd",HttpFields.valueParameters(list.get(5).toString(),null));
Enumeration<String> qualities=fields.getValues("Q",", \t");
List<String> list=HttpFields.qualityList(qualities);
assertEquals("Quality parameters","aaa",HttpFields.valueParameters(list.get(0),null));
assertEquals("Quality parameters","aa2",HttpFields.valueParameters(list.get(1),null));
assertEquals("Quality parameters","abb",HttpFields.valueParameters(list.get(2),null));
assertEquals("Quality parameters","bbb",HttpFields.valueParameters(list.get(3),null));
assertEquals("Quality parameters","ccc",HttpFields.valueParameters(list.get(4),null));
assertEquals("Quality parameters","ddd",HttpFields.valueParameters(list.get(5),null));
}
catch (Exception e)
{
@ -271,61 +261,55 @@ public class RFC2616Test
@Test
public void test4_4_2() throws Exception
{
String response;
int offset=0;
int offset=0;
// If _content length not used, second request will not be read.
String response = connector.getResponses(
"GET /R1 HTTP/1.1\n" +
"Host: localhost\n" +
"Transfer-Encoding: identity\n" +
"Content-Type: text/plain\n" +
"Content-Length: 5\n" +
"\n" +
"123\015\012" +
// 2
// If _content length not used, second request will not be read.
response=connector.getResponses(
"GET /R1 HTTP/1.1\n"+
"Host: localhost\n"+
"Transfer-Encoding: identity\n"+
"Content-Type: text/plain\n"+
"Content-Length: 5\n"+
"\n"+
"123\015\012"+
"GET /R2 HTTP/1.1\n"+
"Host: localhost\n"+
"Transfer-Encoding: other\n"+
"Connection: close\n"+
"\n");
offset=checkContains(response,offset,"HTTP/1.1 200 OK","2. identity")+10;
offset=checkContains(response,offset,"/R1","2. identity")+3;
offset=checkContains(response,offset,"HTTP/1.1 200 OK","2. identity")+10;
offset=checkContains(response,offset,"/R2","2. identity")+3;
"GET /R2 HTTP/1.1\n" +
"Host: localhost\n" +
"Transfer-Encoding: other\n" +
"Connection: close\n" +
"\n");
offset=checkContains(response,offset,"HTTP/1.1 200 OK","2. identity")+10;
offset=checkContains(response,offset,"/R1","2. identity")+3;
offset=checkContains(response,offset,"HTTP/1.1 200 OK","2. identity")+10;
offset=checkContains(response,offset,"/R2","2. identity")+3;
}
@Test
public void test4_4_3() throws Exception
{
String response;
int offset=0;
// 3
// _content length is ignored, as chunking is used. If it is
// not ignored, the second request wont be seen.
offset=0;
response=connector.getResponses(
"GET /R1 HTTP/1.1\n"+
"Host: localhost\n"+
"Transfer-Encoding: chunked\n"+
"Content-Type: text/plain\n"+
"Content-Length: 100\n"+
"\n"+
"3;\n"+
"123\n"+
"3;\n"+
"456\n"+
"0;\n"+
"\n"+
int offset=0;
String response = connector.getResponses(
"GET /R1 HTTP/1.1\n" +
"Host: localhost\n" +
"Transfer-Encoding: chunked\n" +
"Content-Type: text/plain\n" +
"Content-Length: 100\n" +
"\n" +
"3;\n" +
"123\n" +
"3;\n" +
"456\n" +
"0;\n" +
"\n" +
"GET /R2 HTTP/1.1\n"+
"Host: localhost\n"+
"Connection: close\n"+
"Content-Type: text/plain\n"+
"Content-Length: 6\n"+
"\n"+
"abcdef");
"GET /R2 HTTP/1.1\n" +
"Host: localhost\n" +
"Connection: close\n" +
"Content-Type: text/plain\n" +
"Content-Length: 6\n" +
"\n" +
"abcdef");
offset=checkContains(response,offset,"HTTP/1.1 200 OK","3. ignore c-l")+1;
offset=checkContains(response,offset,"/R1","3. ignore c-l")+1;
offset=checkContains(response,offset,"123456","3. ignore c-l")+1;
@ -361,26 +345,20 @@ public class RFC2616Test
@Test
public void test5_2_1() throws Exception
{
String response;
int offset=0;
// Default Host
offset=0;
response=connector.getResponses("GET http://VirtualHost:8888/path/R1 HTTP/1.1\n"+"Host: wronghost\n"+"Connection: close\n"+"\n");
int offset=0;
String response = connector.getResponses("GET http://VirtualHost:8888/path/R1 HTTP/1.1\n" + "Host: wronghost\n" + "Connection: close\n" + "\n");
offset=checkContains(response,offset,"HTTP/1.1 200","Default host")+1;
offset=checkContains(response,offset,"Virtual Dump","virtual host")+1;
offset=checkContains(response,offset,"Dump HttpHandler","Default host")+1;
offset=checkContains(response,offset,"pathInfo=/path/R1","Default host")+1;
}
@Test
public void test5_2_2() throws Exception
{
String response;
int offset=0;
// Default Host
offset=0;
response=connector.getResponses("GET /path/R1 HTTP/1.1\n"+"Host: localhost\n"+"Connection: close\n"+"\n");
int offset=0;
String response = connector.getResponses("GET /path/R1 HTTP/1.1\n" + "Host: localhost\n" + "Connection: close\n" + "\n");
offset=checkContains(response,offset,"HTTP/1.1 200","Default host")+1;
offset=checkContains(response,offset,"Dump HttpHandler","Default host")+1;
offset=checkContains(response,offset,"pathInfo=/path/R1","Default host")+1;
@ -396,12 +374,9 @@ public class RFC2616Test
@Test
public void test5_2() throws Exception
{
String response;
int offset=0;
// Virtual Host
offset=0;
response=connector.getResponses("GET /path/R1 HTTP/1.1\n"+"Host: VirtualHost\n"+"Connection: close\n"+"\n");
int offset=0;
String response = connector.getResponses("GET /path/R1 HTTP/1.1\n" + "Host: VirtualHost\n" + "Connection: close\n" + "\n");
offset=checkContains(response,offset,"HTTP/1.1 200","2. virtual host field")+1;
offset=checkContains(response,offset,"Virtual Dump","2. virtual host field")+1;
offset=checkContains(response,offset,"pathInfo=/path/R1","2. virtual host field")+1;
@ -424,11 +399,8 @@ public class RFC2616Test
{
try
{
String response;
int offset=0;
offset=0;
response=connector.getResponses("GET /R1 HTTP/1.1\n"+"Host: localhost\n"+"\n",250,TimeUnit.MILLISECONDS);
String response = connector.getResponses("GET /R1 HTTP/1.1\n" + "Host: localhost\n" + "\n", 250, TimeUnit.MILLISECONDS);
offset=checkContains(response,offset,"HTTP/1.1 200 OK\015\012","8.1.2 default")+10;
checkContains(response,offset,"Content-Length: ","8.1.2 default");
@ -456,38 +428,34 @@ public class RFC2616Test
@Test
public void test10_4_18() throws Exception
{
String response;
int offset=0;
// Expect Failure
offset=0;
response=connector.getResponses(
"GET /R1 HTTP/1.1\n"+
"Host: localhost\n"+
"Expect: unknown\n"+
"Content-Type: text/plain\n"+
"Content-Length: 8\n"+
"\n");
int offset=0;
String response = connector.getResponses(
"GET /R1 HTTP/1.1\n" +
"Host: localhost\n" +
"Expect: unknown\n" +
"Content-Type: text/plain\n" +
"Content-Length: 8\n" +
"\n");
offset=checkContains(response,offset,"HTTP/1.1 417","8.2.3 expect failure")+1;
}
@Ignore
@Test
public void test8_2_3_dash5() throws Exception
{
String response;
// Expect with body: client sends the content right away, we should not send 100-Continue
int offset=0;
// Expect with body
offset=0;
response=connector.getResponses(
"GET /R1 HTTP/1.1\n"+
"Host: localhost\n"+
"Expect: 100-continue\n"+
"Content-Type: text/plain\n"+
"Content-Length: 8\n"+
"Connection: close\n"+
"\n"+
"123456\015\012");
checkNotContained(response,offset,"HTTP/1.1 100 ","8.2.3 expect 100");
String response = connector.getResponses(
"GET /R1 HTTP/1.1\n" +
"Host: localhost\n" +
"Expect: 100-continue\n" +
"Content-Type: text/plain\n" +
"Content-Length: 8\n" +
"Connection: close\n" +
"\n" +
"123456\015\012");
checkNotContained(response, offset, "HTTP/1.1 100 ", "8.2.3 expect 100");
offset=checkContains(response,offset,"HTTP/1.1 200 OK","8.2.3 expect with body")+1;
}
@ -517,19 +485,17 @@ public class RFC2616Test
offset=checkContains(response,offset,"654321","8.2.3 expect 100")+1;
}
@Ignore
@Test
public void test8_2_4() throws Exception
{
String response;
int offset=0;
// Expect 100 not sent
offset=0;
response=connector.getResponses("GET /R1?error=401 HTTP/1.1\n"+
"Host: localhost\n"+
"Expect: 100-continue\n"+
"Content-Type: text/plain\n"+
"Content-Length: 8\n"+
int offset=0;
String response = connector.getResponses("GET /R1?error=401 HTTP/1.1\n" +
"Host: localhost\n" +
"Expect: 100-continue\n" +
"Content-Type: text/plain\n" +
"Content-Length: 8\n" +
"\n");
checkNotContained(response,offset,"HTTP/1.1 100","8.2.3 expect 100");
offset=checkContains(response,offset,"HTTP/1.1 401 ","8.2.3 expect 100")+1;
@ -755,12 +721,9 @@ public class RFC2616Test
{
try
{
String response;
int offset=0;
// HTTP/1.0 OK with no host
offset=0;
response=connector.getResponses("GET /R1 HTTP/1.0\n"+"Connection: close\n"+"\n");
int offset=0;
String response = connector.getResponses("GET /R1 HTTP/1.0\n" + "Connection: close\n" + "\n");
offset=checkContains(response,offset,"HTTP/1.1 200","200")+1;
offset=0;
@ -773,8 +736,7 @@ public class RFC2616Test
offset=0;
response=connector.getResponses("GET /R1 HTTP/1.1\n"+"Host:\n"+"Connection: close\n"+"\n");
offset=checkContains(response,offset,"HTTP/1.1 200","200")+1;
offset=checkContains(response,offset,"HTTP/1.1 400","400")+1;
}
catch (Exception e)
{
@ -847,11 +809,8 @@ public class RFC2616Test
{
try
{
String response;
int offset=0;
offset=0;
response=connector.getResponses("GET /R1 HTTP/1.0\n"+"\n");
String response = connector.getResponses("GET /R1 HTTP/1.0\n" + "\n");
offset=checkContains(response,offset,"HTTP/1.1 200 OK\015\012","19.6.2 default close")+10;
checkNotContained(response,offset,"Connection: close","19.6.2 not assumed");