-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #931
- Loading branch information
Showing
12 changed files
with
537 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "okhttp-hpacktests/src/test/resources/hpack-test-case"] | ||
path = okhttp-hpacktests/src/test/resources/hpack-test-case | ||
url = git://github.com/http2jp/hpack-test-case.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
OkHttp HPACK tests | ||
================== | ||
|
||
These tests use the [hpack-test-case][1] project to validate OkHttp's HPACK | ||
implementation. The HPACK test cases are in a separate git submodule, so to | ||
initialize them, you must run: | ||
|
||
git submodule init | ||
git submodule update | ||
|
||
When new interop tests are available, you should update | ||
HpackDecodeInteropGoodTest#GOOD_INTEROP_TESTS with the directory name. | ||
|
||
TODO | ||
---- | ||
|
||
* Add maven goal to avoid manual call to git submodule init. | ||
* Make hpack-test-case update itself from git, and run new tests. | ||
* Add maven goal to generate stories and a pull request to hpack-test-case | ||
to have others validate our output. | ||
|
||
[1]: https://github.com/http2jp/hpack-test-case |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.squareup.okhttp</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>2.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>okhttp-hpacktests</artifactId> | ||
<name>OkHttp HPACK Tests</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.squareup.okio</groupId> | ||
<artifactId>okio</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.squareup.okhttp</groupId> | ||
<artifactId>okhttp</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.squareup.okhttp</groupId> | ||
<artifactId>mockwebserver</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- Gson: Java to Json conversion --> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.2.4</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<!-- Do not deploy this as an artifact to Maven central. --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
51 changes: 51 additions & 0 deletions
51
...hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropBadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) 2014 Square, 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. | ||
*/ | ||
package com.squareup.okhttp.internal.spdy; | ||
|
||
import com.squareup.okhttp.internal.spdy.hpackjson.Story; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Known bad tests for HPACK interop. | ||
*/ | ||
// TODO: fix these tests (see if the input/test is legit, fix the implementation.) | ||
@Ignore | ||
@RunWith(Parameterized.class) | ||
public class HpackDecodeInteropBadTest extends HpackDecodeTestBase { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
private static final String[] BAD_INTEROP_TESTS = { "go-hpack", "haskell-http2-diff-huffman", | ||
"haskell-http2-linear-huffman", "haskell-http2-naive-huffman", | ||
"haskell-http2-static-huffman", "node-http2-protocol", "twitter-hpack" }; | ||
|
||
public HpackDecodeInteropBadTest(Story story) { | ||
super(story); | ||
} | ||
|
||
@Parameterized.Parameters(name="{0}") | ||
public static Collection<Story[]> createStories() throws Exception { | ||
return createStories(BAD_INTEROP_TESTS); | ||
} | ||
|
||
@Test | ||
public void testGoodDecoderInterop() throws Exception { | ||
testDecoder(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...packtests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropGoodTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (C) 2014 Square, 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. | ||
*/ | ||
package com.squareup.okhttp.internal.spdy; | ||
|
||
import com.squareup.okhttp.internal.spdy.hpackjson.Story; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Known good tests for HPACK interop. | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class HpackDecodeInteropGoodTest extends HpackDecodeTestBase { | ||
|
||
|
||
private static final String[] GOOD_INTEROP_TESTS = { "haskell-http2-diff", | ||
"haskell-http2-linear", "haskell-http2-naive", "haskell-http2-static", | ||
"hyper-hpack", "nghttp2", "nghttp2-16384-4096", | ||
"nghttp2-change-table-size", "node-http2-hpack" }; | ||
|
||
public HpackDecodeInteropGoodTest(Story story) { | ||
super(story); | ||
} | ||
|
||
@Parameterized.Parameters(name="{0}") | ||
public static Collection<Story[]> createStories() throws Exception { | ||
return createStories(GOOD_INTEROP_TESTS); | ||
} | ||
|
||
@Test | ||
public void testGoodDecoderInterop() throws Exception { | ||
testDecoder(); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright (C) 2014 Square, 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. | ||
*/ | ||
package com.squareup.okhttp.internal.spdy; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
|
||
import com.squareup.okhttp.internal.spdy.hpackjson.Case; | ||
import com.squareup.okhttp.internal.spdy.hpackjson.HpackJsonUtil; | ||
import com.squareup.okhttp.internal.spdy.hpackjson.Story; | ||
import okio.Buffer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
|
||
/** | ||
* Tests Hpack implementation using https://github.com/http2jp/hpack-test-case/ | ||
*/ | ||
public class HpackDecodeTestBase { | ||
|
||
/** | ||
* Reads all stories in the folders provided, asserts if no story found. | ||
*/ | ||
protected static Collection<Story[]> createStories(String[] interopTests) | ||
throws Exception { | ||
List<Story[]> result = new ArrayList<>(); | ||
for (String interopTestName : interopTests) { | ||
List<Story> stories = HpackJsonUtil.readStories(interopTestName); | ||
if (stories.isEmpty()) { | ||
fail("No stories for: " + interopTestName); | ||
} | ||
for (Story story : stories) { | ||
result.add(new Story[] { story }); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
private final Buffer bytesIn = new Buffer(); | ||
private final HpackDraft08.Reader hpackReader = new HpackDraft08.Reader(4096, bytesIn); | ||
|
||
private final Story story; | ||
|
||
public HpackDecodeTestBase(Story story) { | ||
this.story = story; | ||
} | ||
|
||
/** | ||
* Expects wire to be set for all cases, and compares the decoder's output to | ||
* expected headers. | ||
*/ | ||
protected void testDecoder() throws Exception { | ||
testDecoder(story); | ||
} | ||
|
||
protected void testDecoder(Story story) throws Exception { | ||
for (Case caze : story.getCases()) { | ||
bytesIn.write(caze.getWire()); | ||
hpackReader.readHeaders(); | ||
hpackReader.emitReferenceSet(); | ||
assertSetEquals(String.format("seqno=%d", caze.getSeqno()), caze.getHeaders(), | ||
hpackReader.getAndReset()); | ||
} | ||
} | ||
/** | ||
* Checks if {@code expected} and {@code observed} are equal when viewed as a | ||
* set and headers are deduped. | ||
* | ||
* TODO: See if duped headers should be preserved on decode and verify. | ||
*/ | ||
private static void assertSetEquals( | ||
String message, List<Header> expected, List<Header> observed) { | ||
assertEquals(message, new LinkedHashSet<>(expected), new LinkedHashSet<>(observed)); | ||
} | ||
|
||
protected Story getStory() { | ||
return story; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackRoundTripTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2014 Square, 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. | ||
*/ | ||
package com.squareup.okhttp.internal.spdy; | ||
|
||
import com.squareup.okhttp.internal.spdy.hpackjson.Case; | ||
import com.squareup.okhttp.internal.spdy.hpackjson.Story; | ||
import okio.Buffer; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Tests for round-tripping headers through hpack.. | ||
*/ | ||
// TODO: update hpack-test-case with the output of our encoder. | ||
// This test will hide complementary bugs in the encoder and decoder, | ||
// We should test that the encoder is producing responses that are | ||
// d] | ||
@RunWith(Parameterized.class) | ||
public class HpackRoundTripTest extends HpackDecodeTestBase { | ||
|
||
private static final String[] RAW_DATA = { "raw-data" }; | ||
|
||
@Parameterized.Parameters(name="{0}") | ||
public static Collection<Story[]> getStories() throws Exception { | ||
return createStories(RAW_DATA); | ||
} | ||
|
||
private Buffer bytesOut = new Buffer(); | ||
private HpackDraft08.Writer hpackWriter = new HpackDraft08.Writer(bytesOut); | ||
|
||
public HpackRoundTripTest(Story story) { | ||
super(story); | ||
} | ||
|
||
@Test | ||
public void testRoundTrip() throws Exception { | ||
Story story = getStory().clone(); | ||
// Mutate cases in base class. | ||
for (Case caze : story.getCases()) { | ||
hpackWriter.writeHeaders(caze.getHeaders()); | ||
caze.setWire(bytesOut.readByteString()); | ||
} | ||
|
||
testDecoder(story); | ||
} | ||
|
||
} |
Oops, something went wrong.
Body can't be blank
okhttp/ ea13e5e
Add hpack-test-case test module.
Issue #931
@wezleywezley committed about 2 years ago
12 changed files
537 additions and 0 deletions
.gitmodules
@@ -0,0 +1,3 @@
+[submodule "okhttp-hpacktests/src/test/resources/hpack-test-case"]
okhttp-hpacktests/README.md
@@ -0,0 +1,22 @@
+OkHttp HPACK tests
+==================
+These tests use the [hpack-test-case][1] project to validate OkHttp's HPACK
+implementation. The HPACK test cases are in a separate git submodule, so to
+initialize them, you must run:
+
+When new interop tests are available, you should update
+HpackDecodeInteropGoodTest#GOOD_INTEROP_TESTS with the directory name.
+
+TODO
+----
+
+[1]: https://github.com/http2jp/hpack-test-case
okhttp-hpacktests/pom.xml
@@ -0,0 +1,57 @@
+
+
+
+
...hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropBadTest.java
@@ -0,0 +1,51 @@
+/*
+package com.squareup.okhttp.internal.spdy;
+
+import com.squareup.okhttp.internal.spdy.hpackjson.Story;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Collection;
Cancel Leave line note
+
+/**
+// TODO: fix these tests (see if the input/test is legit, fix the implementation.)
+@ignore
+@RunWith(Parameterized.class)
+public class HpackDecodeInteropBadTest extends HpackDecodeTestBase {
Cancel Leave line note
+
+}
...packtests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropGoodTest.java
@@ -0,0 +1,50 @@
+/*
+package com.squareup.okhttp.internal.spdy;
+
+import com.squareup.okhttp.internal.spdy.hpackjson.Story;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Collection;
+
+/*
+@RunWith(Parameterized.class)
+public class HpackDecodeInteropGoodTest extends HpackDecodeTestBase {
+
+
+}
okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeTestBase.java
@@ -0,0 +1,94 @@
+/*
+package com.squareup.okhttp.internal.spdy;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import com.squareup.okhttp.internal.spdy.hpackjson.Case;
+import com.squareup.okhttp.internal.spdy.hpackjson.HpackJsonUtil;
+import com.squareup.okhttp.internal.spdy.hpackjson.Story;
+import okio.Buffer;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+/*
+public class HpackDecodeTestBase {
+
+}
okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackRoundTripTest.java
@@ -0,0 +1,63 @@
+/*
+package com.squareup.okhttp.internal.spdy;
+
+import com.squareup.okhttp.internal.spdy.hpackjson.Case;
+import com.squareup.okhttp.internal.spdy.hpackjson.Story;
+import okio.Buffer;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Collection;
+
+/*
+// TODO: update hpack-test-case with the output of our encoder.
+// This test will hide complementary bugs in the encoder and decoder,
+// We should test that the encoder is producing responses that are
+// d]
+@RunWith(Parameterized.class)
+public class HpackRoundTripTest extends HpackDecodeTestBase {
+
+}
okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/hpackjson/Case.java
@@ -0,0 +1,69 @@
+/*
+package com.squareup.okhttp.internal.spdy.hpackjson;
+
+import com.squareup.okhttp.internal.spdy.Header;
+import okio.ByteString;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/*
+public class Case implements Cloneable {
+
+}
...p-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/hpackjson/HpackJsonUtil.java
@@ -0,0 +1,65 @@
+/*
+package com.squareup.okhttp.internal.spdy.hpackjson;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+/*
+public final class HpackJsonUtil {
+
+}
okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/hpackjson/Story.java
@@ -0,0 +1,61 @@
+/*
+package com.squareup.okhttp.internal.spdy.hpackjson;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/*
+public class Story implements Cloneable {
+
+}
okhttp-hpacktests/src/test/resources/hpack-test-case
@@ -0,0 +1 @@
+Subproject commit bc5da28a11638c460c39b763f44fe230472c1b24
pom.xml
@@ -21,6 +21,7 @@
Comment on ea13e5e
Comment
Desktop version