1
0
mirror of https://github.com/square/okhttp.git synced 2025-11-27 18:21:14 +03:00

Fix some Autobahn tests.

Bump the queue limit to 16 MiB for Autobahn tests. This is the ceiling they
use and necessary to pass their tests.

Move to port 9099. Port 9001 conflicts with supervisord.

Throw the right exceptions on close codes, at the right times.
This commit is contained in:
jwilson
2016-11-21 12:29:14 -05:00
parent 4df16f3a5b
commit c8dbccea5e
7 changed files with 23 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
{ {
"url": "ws://127.0.0.1:9001", "url": "ws://127.0.0.1:9099",
"outdir": "./target/fuzzingserver-report", "outdir": "./target/fuzzingserver-report",
"cases": ["*"], "cases": ["*"],
"exclude-cases": [ "exclude-cases": [

View File

@@ -257,7 +257,7 @@
"4.2.1 OK" "4.2.1 OK"
"4.2.2 OK" "4.2.2 OK"
"4.2.3 NON-STRICT" "4.2.3 NON-STRICT"
"4.2.4 NON-STRICT" "4.2.4 OK"
"4.2.5 OK" "4.2.5 OK"
"5.1 OK" "5.1 OK"
"5.10 OK" "5.10 OK"
@@ -265,7 +265,7 @@
"5.12 OK" "5.12 OK"
"5.13 OK" "5.13 OK"
"5.14 OK" "5.14 OK"
"5.15 NON-STRICT" "5.15 OK"
"5.16 OK" "5.16 OK"
"5.17 OK" "5.17 OK"
"5.18 OK" "5.18 OK"
@@ -283,7 +283,7 @@
"7.1.2 OK" "7.1.2 OK"
"7.1.3 OK" "7.1.3 OK"
"7.1.4 OK" "7.1.4 OK"
"7.1.5 FAILED" "7.1.5 OK"
"7.1.6 INFORMATIONAL" "7.1.6 INFORMATIONAL"
"7.13.1 INFORMATIONAL" "7.13.1 INFORMATIONAL"
"7.13.2 INFORMATIONAL" "7.13.2 INFORMATIONAL"

View File

@@ -28,7 +28,7 @@ import okio.ByteString;
* href="http://autobahn.ws/testsuite/">Autobahn Testsuite</a>. * href="http://autobahn.ws/testsuite/">Autobahn Testsuite</a>.
*/ */
public final class AutobahnTester { public final class AutobahnTester {
private static final String HOST = "ws://localhost:9001"; private static final String HOST = "ws://localhost:9099";
public static void main(String... args) throws IOException { public static void main(String... args) throws IOException {
new AutobahnTester().run(); new AutobahnTester().run();
@@ -133,7 +133,7 @@ public final class AutobahnTester {
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
newWebSocket("/updateReports?agent=" + Version.userAgent(), new WebSocketListener() { newWebSocket("/updateReports?agent=" + Version.userAgent(), new WebSocketListener() {
@Override public void onClosing(WebSocket webSocket, int code, String reason) { @Override public void onClosing(WebSocket webSocket, int code, String reason) {
webSocket.close(code, null); webSocket.close(1000, null);
latch.countDown(); latch.countDown();
} }

View File

@@ -48,6 +48,7 @@ import static okhttp3.internal.Util.closeQuietly;
import static okhttp3.internal.ws.WebSocketProtocol.CLOSE_CLIENT_GOING_AWAY; import static okhttp3.internal.ws.WebSocketProtocol.CLOSE_CLIENT_GOING_AWAY;
import static okhttp3.internal.ws.WebSocketProtocol.OPCODE_BINARY; import static okhttp3.internal.ws.WebSocketProtocol.OPCODE_BINARY;
import static okhttp3.internal.ws.WebSocketProtocol.OPCODE_TEXT; import static okhttp3.internal.ws.WebSocketProtocol.OPCODE_TEXT;
import static okhttp3.internal.ws.WebSocketProtocol.validateCloseCode;
public final class RealWebSocket implements WebSocket, WebSocketReader.FrameCallback { public final class RealWebSocket implements WebSocket, WebSocketReader.FrameCallback {
private static final List<Protocol> ONLY_HTTP1 = Collections.singletonList(Protocol.HTTP_1_1); private static final List<Protocol> ONLY_HTTP1 = Collections.singletonList(Protocol.HTTP_1_1);
@@ -56,7 +57,7 @@ public final class RealWebSocket implements WebSocket, WebSocketReader.FrameCall
* The maximum number of bytes to enqueue. Rather than enqueueing beyond this limit we tear down * The maximum number of bytes to enqueue. Rather than enqueueing beyond this limit we tear down
* the web socket! It's possible that we're writing faster than the peer can read. * the web socket! It's possible that we're writing faster than the peer can read.
*/ */
private static final long MAX_QUEUE_SIZE = 1024 * 1024; // 1 MiB. private static final long MAX_QUEUE_SIZE = 16 * 1024 * 1024; // 16 MiB.
/** A shared executor for all web sockets. */ /** A shared executor for all web sockets. */
private static final ExecutorService executor = new ThreadPoolExecutor(0, private static final ExecutorService executor = new ThreadPoolExecutor(0,
@@ -340,6 +341,7 @@ public final class RealWebSocket implements WebSocket, WebSocketReader.FrameCall
} }
@Override public synchronized boolean close(final int code, final String reason) { @Override public synchronized boolean close(final int code, final String reason) {
validateCloseCode(code);
// TODO(jwilson): confirm reason is well-formed. (<=123 bytes, etc.) // TODO(jwilson): confirm reason is well-formed. (<=123 bytes, etc.)
if (failed || enqueuedClose) return false; if (failed || enqueuedClose) return false;

View File

@@ -103,19 +103,19 @@ public final class WebSocketProtocol {
} }
} }
static void validateCloseCode(int code, boolean argument) throws ProtocolException { static String closeCodeExceptionMessage(int code) {
String message = null;
if (code < 1000 || code >= 5000) { if (code < 1000 || code >= 5000) {
message = "Code must be in range [1000,5000): " + code; return "Code must be in range [1000,5000): " + code;
} else if ((code >= 1004 && code <= 1006) || (code >= 1012 && code <= 2999)) { } else if ((code >= 1004 && code <= 1006) || (code >= 1012 && code <= 2999)) {
message = "Code " + code + " is reserved and may not be used."; return "Code " + code + " is reserved and may not be used.";
} else {
return null;
} }
if (message != null) {
if (argument) {
throw new IllegalArgumentException(message);
}
throw new ProtocolException(message);
} }
static void validateCloseCode(int code) {
String message = closeCodeExceptionMessage(code);
if (message != null) throw new IllegalArgumentException(message);
} }
public static String acceptHeader(String key) { public static String acceptHeader(String key) {

View File

@@ -42,7 +42,6 @@ import static okhttp3.internal.ws.WebSocketProtocol.PAYLOAD_BYTE_MAX;
import static okhttp3.internal.ws.WebSocketProtocol.PAYLOAD_LONG; import static okhttp3.internal.ws.WebSocketProtocol.PAYLOAD_LONG;
import static okhttp3.internal.ws.WebSocketProtocol.PAYLOAD_SHORT; import static okhttp3.internal.ws.WebSocketProtocol.PAYLOAD_SHORT;
import static okhttp3.internal.ws.WebSocketProtocol.toggleMask; import static okhttp3.internal.ws.WebSocketProtocol.toggleMask;
import static okhttp3.internal.ws.WebSocketProtocol.validateCloseCode;
/** /**
* An <a href="http://tools.ietf.org/html/rfc6455">RFC 6455</a>-compatible WebSocket frame reader. * An <a href="http://tools.ietf.org/html/rfc6455">RFC 6455</a>-compatible WebSocket frame reader.
@@ -190,7 +189,8 @@ final class WebSocketReader {
} else if (bufferSize != 0) { } else if (bufferSize != 0) {
code = buffer.readShort(); code = buffer.readShort();
reason = buffer.readUtf8(); reason = buffer.readUtf8();
validateCloseCode(code, false); String codeExceptionMessage = WebSocketProtocol.closeCodeExceptionMessage(code);
if (codeExceptionMessage != null) throw new ProtocolException(codeExceptionMessage);
} }
frameCallback.onReadClose(code, reason); frameCallback.onReadClose(code, reason);
closed = true; closed = true;

View File

@@ -33,8 +33,8 @@ import static okhttp3.internal.ws.WebSocketProtocol.PAYLOAD_BYTE_MAX;
import static okhttp3.internal.ws.WebSocketProtocol.PAYLOAD_LONG; import static okhttp3.internal.ws.WebSocketProtocol.PAYLOAD_LONG;
import static okhttp3.internal.ws.WebSocketProtocol.PAYLOAD_SHORT; import static okhttp3.internal.ws.WebSocketProtocol.PAYLOAD_SHORT;
import static okhttp3.internal.ws.WebSocketProtocol.PAYLOAD_SHORT_MAX; import static okhttp3.internal.ws.WebSocketProtocol.PAYLOAD_SHORT_MAX;
import static okhttp3.internal.ws.WebSocketProtocol.toggleMask;
import static okhttp3.internal.ws.WebSocketProtocol.validateCloseCode; import static okhttp3.internal.ws.WebSocketProtocol.validateCloseCode;
import static okhttp3.internal.ws.WebSocketProtocol.toggleMask;
/** /**
* An <a href="http://tools.ietf.org/html/rfc6455">RFC 6455</a>-compatible WebSocket frame writer. * An <a href="http://tools.ietf.org/html/rfc6455">RFC 6455</a>-compatible WebSocket frame writer.
@@ -98,7 +98,7 @@ final class WebSocketWriter {
ByteString payload = ByteString.EMPTY; ByteString payload = ByteString.EMPTY;
if (code != 0 || reason != null) { if (code != 0 || reason != null) {
if (code != 0) { if (code != 0) {
validateCloseCode(code, true); validateCloseCode(code);
} }
Buffer buffer = new Buffer(); Buffer buffer = new Buffer();
buffer.writeShort(code); buffer.writeShort(code);