summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorricea <ricea@chromium.org>2014-11-20 01:57:07 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-20 09:57:40 +0000
commit11bdcd08b9aa8413b2096f542cf81d4251114832 (patch)
treec3480712d3c9d39690d357177f3fc049756c09bd
parent5e431c15487b8e9f749810435eb0ef491af0737e (diff)
downloadchromium_src-11bdcd08b9aa8413b2096f542cf81d4251114832.zip
chromium_src-11bdcd08b9aa8413b2096f542cf81d4251114832.tar.gz
chromium_src-11bdcd08b9aa8413b2096f542cf81d4251114832.tar.bz2
Rename websocket_handshake_handler.* to websocket_handshake_challenge.*
Simplify the calling convention of ComputeSecWebSocketAccept to just return a string, and add a test for it. BUG= TEST=net_unittests Review URL: https://codereview.chromium.org/683033003 Cr-Commit-Position: refs/heads/master@{#304996}
-rw-r--r--net/BUILD.gn7
-rw-r--r--net/net.gypi6
-rw-r--r--net/websockets/websocket_basic_handshake_stream.cc6
-rw-r--r--net/websockets/websocket_handshake_challenge.cc20
-rw-r--r--net/websockets/websocket_handshake_challenge.h21
-rw-r--r--net/websockets/websocket_handshake_challenge_test.cc24
-rw-r--r--net/websockets/websocket_handshake_handler.cc23
-rw-r--r--net/websockets/websocket_handshake_handler.h19
-rw-r--r--net/websockets/websocket_handshake_handler_test.cc17
9 files changed, 74 insertions, 69 deletions
diff --git a/net/BUILD.gn b/net/BUILD.gn
index 464c00a..2f0a6bc 100644
--- a/net/BUILD.gn
+++ b/net/BUILD.gn
@@ -406,8 +406,8 @@ component("net") {
"websockets/websocket_frame_parser.h",
"websockets/websocket_handshake_constants.cc",
"websockets/websocket_handshake_constants.h",
- "websockets/websocket_handshake_handler.cc",
- "websockets/websocket_handshake_handler.h",
+ "websockets/websocket_handshake_challenge.cc",
+ "websockets/websocket_handshake_challenge.h",
"websockets/websocket_handshake_request_info.cc",
"websockets/websocket_handshake_request_info.h",
"websockets/websocket_handshake_response_info.cc",
@@ -1235,8 +1235,7 @@ test("net_unittests") {
"websockets/websocket_extension_parser_test.cc",
"websockets/websocket_frame_parser_test.cc",
"websockets/websocket_frame_test.cc",
- "websockets/websocket_handshake_handler_spdy_test.cc",
- "websockets/websocket_handshake_handler_test.cc",
+ "websockets/websocket_handshake_challenge_test.cc",
"websockets/websocket_handshake_stream_create_helper_test.cc",
"websockets/websocket_inflater_test.cc",
"websockets/websocket_stream_test.cc",
diff --git a/net/net.gypi b/net/net.gypi
index 337f016..cc9ff357 100644
--- a/net/net.gypi
+++ b/net/net.gypi
@@ -1236,8 +1236,8 @@
'websockets/websocket_frame_parser.h',
'websockets/websocket_handshake_constants.cc',
'websockets/websocket_handshake_constants.h',
- 'websockets/websocket_handshake_handler.cc',
- 'websockets/websocket_handshake_handler.h',
+ 'websockets/websocket_handshake_challenge.cc',
+ 'websockets/websocket_handshake_challenge.h',
'websockets/websocket_handshake_request_info.cc',
'websockets/websocket_handshake_request_info.h',
'websockets/websocket_handshake_response_info.cc',
@@ -1709,7 +1709,7 @@
'websockets/websocket_extension_parser_test.cc',
'websockets/websocket_frame_parser_test.cc',
'websockets/websocket_frame_test.cc',
- 'websockets/websocket_handshake_handler_test.cc',
+ 'websockets/websocket_handshake_challenge_test.cc',
'websockets/websocket_handshake_stream_create_helper_test.cc',
'websockets/websocket_inflater_test.cc',
'websockets/websocket_stream_test.cc',
diff --git a/net/websockets/websocket_basic_handshake_stream.cc b/net/websockets/websocket_basic_handshake_stream.cc
index 769b802..08ee6ae 100644
--- a/net/websockets/websocket_basic_handshake_stream.cc
+++ b/net/websockets/websocket_basic_handshake_stream.cc
@@ -39,8 +39,8 @@
#include "net/websockets/websocket_deflate_stream.h"
#include "net/websockets/websocket_deflater.h"
#include "net/websockets/websocket_extension_parser.h"
+#include "net/websockets/websocket_handshake_challenge.h"
#include "net/websockets/websocket_handshake_constants.h"
-#include "net/websockets/websocket_handshake_handler.h"
#include "net/websockets/websocket_handshake_request_info.h"
#include "net/websockets/websocket_handshake_response_info.h"
#include "net/websockets/websocket_stream.h"
@@ -435,8 +435,8 @@ int WebSocketBasicHandshakeStream::SendRequest(
requested_sub_protocols_,
&enriched_headers);
- ComputeSecWebSocketAccept(handshake_challenge,
- &handshake_challenge_response_);
+ handshake_challenge_response_ =
+ ComputeSecWebSocketAccept(handshake_challenge);
DCHECK(connect_delegate_);
scoped_ptr<WebSocketHandshakeRequestInfo> request(
diff --git a/net/websockets/websocket_handshake_challenge.cc b/net/websockets/websocket_handshake_challenge.cc
new file mode 100644
index 0000000..3a1c3e8
--- /dev/null
+++ b/net/websockets/websocket_handshake_challenge.cc
@@ -0,0 +1,20 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/websockets/websocket_handshake_challenge.h"
+
+#include "base/base64.h"
+#include "base/sha1.h"
+#include "net/websockets/websocket_handshake_constants.h"
+
+namespace net {
+
+std::string ComputeSecWebSocketAccept(const std::string& key) {
+ std::string accept;
+ std::string hash = base::SHA1HashString(key + websockets::kWebSocketGuid);
+ base::Base64Encode(hash, &accept);
+ return accept;
+}
+
+} // namespace net
diff --git a/net/websockets/websocket_handshake_challenge.h b/net/websockets/websocket_handshake_challenge.h
new file mode 100644
index 0000000..e21f2b0
--- /dev/null
+++ b/net/websockets/websocket_handshake_challenge.h
@@ -0,0 +1,21 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_CHALLENGE_H_
+#define NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_CHALLENGE_H_
+
+#include <string>
+
+#include "net/base/net_export.h"
+
+namespace net {
+
+// Given a WebSocket handshake challenge, compute the value that the server
+// should return in the Sec-WebSocket-Accept header.
+NET_EXPORT_PRIVATE std::string ComputeSecWebSocketAccept(
+ const std::string& key);
+
+} // namespace net
+
+#endif // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_CHALLENGE_H_
diff --git a/net/websockets/websocket_handshake_challenge_test.cc b/net/websockets/websocket_handshake_challenge_test.cc
new file mode 100644
index 0000000..d7e45ca
--- /dev/null
+++ b/net/websockets/websocket_handshake_challenge_test.cc
@@ -0,0 +1,24 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/websockets/websocket_handshake_challenge.h"
+
+#include <string>
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+
+namespace {
+
+// Test the example challenge from the RFC6455.
+TEST(WebSocketHandshakeChallengeTest, RFC6455) {
+ const std::string key = "dGhlIHNhbXBsZSBub25jZQ==";
+ std::string accept = ComputeSecWebSocketAccept(key);
+ EXPECT_EQ("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", accept);
+}
+
+} // namespace
+
+} // namespace net
diff --git a/net/websockets/websocket_handshake_handler.cc b/net/websockets/websocket_handshake_handler.cc
deleted file mode 100644
index 6bcc230..0000000
--- a/net/websockets/websocket_handshake_handler.cc
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/websockets/websocket_handshake_handler.h"
-
-#include "base/base64.h"
-#include "base/logging.h"
-#include "base/sha1.h"
-#include "net/websockets/websocket_handshake_constants.h"
-
-namespace net {
-
-void ComputeSecWebSocketAccept(const std::string& key,
- std::string* accept) {
- DCHECK(accept);
-
- std::string hash =
- base::SHA1HashString(key + websockets::kWebSocketGuid);
- base::Base64Encode(hash, accept);
-}
-
-} // namespace net
diff --git a/net/websockets/websocket_handshake_handler.h b/net/websockets/websocket_handshake_handler.h
deleted file mode 100644
index c65e6d9..0000000
--- a/net/websockets/websocket_handshake_handler.h
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_HANDLER_H_
-#define NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_HANDLER_H_
-
-#include <string>
-
-namespace net {
-
-// Given a WebSocket handshake challenge, compute the correct response.
-// TODO(ricea): There should probably be a test for this.
-void ComputeSecWebSocketAccept(const std::string& key,
- std::string* accept);
-
-} // namespace net
-
-#endif // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_HANDLER_H_
diff --git a/net/websockets/websocket_handshake_handler_test.cc b/net/websockets/websocket_handshake_handler_test.cc
deleted file mode 100644
index 8eff571..0000000
--- a/net/websockets/websocket_handshake_handler_test.cc
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/websockets/websocket_handshake_handler.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace net {
-
-namespace {
-
-// TODO(ricea): Put a test for ComputeSecWebSocketAccept() here.
-
-} // namespace
-
-} // namespace net