Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(667)

Unified Diff: net/websockets/websocket_stream_test.cc

Issue 304093003: Support recovery from SSL errors for new WebSocket implementation (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-for-pool-throttling
Patch Set: Fixes from tyoshino review. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/websockets/websocket_stream.cc ('k') | net/websockets/websocket_test_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/websockets/websocket_stream_test.cc
diff --git a/net/websockets/websocket_stream_test.cc b/net/websockets/websocket_stream_test.cc
index 4ea8538b76273c28af1164db13b8e145192a3770..0344cceb539810aaf0028477d316f31f6d6540b5 100644
--- a/net/websockets/websocket_stream_test.cc
+++ b/net/websockets/websocket_stream_test.cc
@@ -16,10 +16,12 @@
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "net/base/net_errors.h"
+#include "net/base/test_data_directory.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/socket_test_util.h"
+#include "net/test/cert_test_util.h"
#include "net/url_request/url_request_test_util.h"
#include "net/websockets/websocket_basic_handshake_stream.h"
#include "net/websockets/websocket_frame.h"
@@ -79,7 +81,7 @@ class DeterministicKeyWebSocketHandshakeStreamCreateHelper
class WebSocketStreamCreateTest : public ::testing::Test {
public:
- WebSocketStreamCreateTest(): has_failed_(false) {}
+ WebSocketStreamCreateTest() : has_failed_(false), ssl_fatal_(false) {}
void CreateAndConnectCustomResponse(
const std::string& socket_url,
@@ -116,7 +118,7 @@ class WebSocketStreamCreateTest : public ::testing::Test {
const std::vector<std::string>& sub_protocols,
const std::string& origin,
scoped_ptr<DeterministicSocketData> socket_data) {
- url_request_context_host_.SetRawExpectations(socket_data.Pass());
+ url_request_context_host_.AddRawExpectations(socket_data.Pass());
CreateAndConnectStream(socket_url, sub_protocols, origin);
}
@@ -125,6 +127,12 @@ class WebSocketStreamCreateTest : public ::testing::Test {
void CreateAndConnectStream(const std::string& socket_url,
const std::vector<std::string>& sub_protocols,
const std::string& origin) {
+ for (size_t i = 0; i < ssl_data_.size(); ++i) {
+ scoped_ptr<SSLSocketDataProvider> ssl_data(ssl_data_[i]);
+ ssl_data_[i] = NULL;
+ url_request_context_host_.AddSSLSocketDataProvider(ssl_data.Pass());
+ }
+ ssl_data_.clear();
scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate(
new TestConnectDelegate(this));
WebSocketStream::ConnectDelegate* delegate = connect_delegate.get();
@@ -175,6 +183,15 @@ class WebSocketStreamCreateTest : public ::testing::Test {
ADD_FAILURE();
owner_->response_info_ = response.Pass();
}
+ virtual void OnSSLCertificateError(
+ scoped_ptr<WebSocketEventInterface::SSLErrorCallbacks>
+ ssl_error_callbacks,
+ const SSLInfo& ssl_info,
+ bool fatal) OVERRIDE {
+ owner_->ssl_error_callbacks_ = ssl_error_callbacks.Pass();
+ owner_->ssl_info_ = ssl_info;
+ owner_->ssl_fatal_ = fatal;
+ }
private:
WebSocketStreamCreateTest* owner_;
@@ -189,6 +206,10 @@ class WebSocketStreamCreateTest : public ::testing::Test {
bool has_failed_;
scoped_ptr<WebSocketHandshakeRequestInfo> request_info_;
scoped_ptr<WebSocketHandshakeResponseInfo> response_info_;
+ scoped_ptr<WebSocketEventInterface::SSLErrorCallbacks> ssl_error_callbacks_;
+ SSLInfo ssl_info_;
+ bool ssl_fatal_;
+ ScopedVector<SSLSocketDataProvider> ssl_data_;
};
// There are enough tests of the Sec-WebSocket-Extensions header that they
@@ -1032,6 +1053,48 @@ TEST_F(WebSocketStreamCreateTest, NoResponse) {
failure_message());
}
+TEST_F(WebSocketStreamCreateTest, SelfSignedCertificateFailure) {
+ ssl_data_.push_back(
+ new SSLSocketDataProvider(ASYNC, ERR_CERT_AUTHORITY_INVALID));
+ ssl_data_[0]->cert =
+ ImportCertFromFile(GetTestCertsDirectory(), "unittest.selfsigned.der");
+ ASSERT_TRUE(ssl_data_[0]->cert);
+ scoped_ptr<DeterministicSocketData> raw_socket_data(
+ new DeterministicSocketData(NULL, 0, NULL, 0));
+ CreateAndConnectRawExpectations("wss://localhost/",
+ NoSubProtocols(),
+ "http://localhost",
+ raw_socket_data.Pass());
+ RunUntilIdle();
+ EXPECT_FALSE(has_failed());
+ ASSERT_TRUE(ssl_error_callbacks_);
+ ssl_error_callbacks_->CancelSSLRequest(ERR_CERT_AUTHORITY_INVALID,
+ &ssl_info_);
+ RunUntilIdle();
+ EXPECT_TRUE(has_failed());
+}
+
+TEST_F(WebSocketStreamCreateTest, SelfSignedCertificateSuccess) {
+ scoped_ptr<SSLSocketDataProvider> ssl_data(
+ new SSLSocketDataProvider(ASYNC, ERR_CERT_AUTHORITY_INVALID));
+ ssl_data->cert =
+ ImportCertFromFile(GetTestCertsDirectory(), "unittest.selfsigned.der");
+ ASSERT_TRUE(ssl_data->cert);
+ ssl_data_.push_back(ssl_data.release());
+ ssl_data.reset(new SSLSocketDataProvider(ASYNC, OK));
+ ssl_data_.push_back(ssl_data.release());
+ url_request_context_host_.AddRawExpectations(
+ make_scoped_ptr(new DeterministicSocketData(NULL, 0, NULL, 0)));
+ CreateAndConnectStandard(
+ "wss://localhost/", "/", NoSubProtocols(), "http://localhost", "", "");
+ RunUntilIdle();
+ ASSERT_TRUE(ssl_error_callbacks_);
+ ssl_error_callbacks_->ContinueSSLRequest();
+ RunUntilIdle();
+ EXPECT_FALSE(has_failed());
+ EXPECT_TRUE(stream_);
+}
+
TEST_F(WebSocketStreamCreateUMATest, Incomplete) {
const std::string name("Net.WebSocket.HandshakeResult");
scoped_ptr<base::HistogramSamples> original(GetSamples(name));
@@ -1107,9 +1170,9 @@ TEST_F(WebSocketStreamCreateUMATest, Failed) {
if (original) {
samples->Subtract(*original); // Cancel the original values.
}
- EXPECT_EQ(0, samples->GetCount(INCOMPLETE));
+ EXPECT_EQ(1, samples->GetCount(INCOMPLETE));
EXPECT_EQ(0, samples->GetCount(CONNECTED));
- EXPECT_EQ(1, samples->GetCount(FAILED));
+ EXPECT_EQ(0, samples->GetCount(FAILED));
}
} // namespace
« no previous file with comments | « net/websockets/websocket_stream.cc ('k') | net/websockets/websocket_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698