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

Side by Side Diff: net/socket/ssl_client_socket_unittest.cc

Issue 2758803003: Make X509Certificate creation fail if X509Certificate::Initialize fails. (Closed)
Patch Set: test updatess 2 Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/socket/ssl_client_socket.h" 5 #include "net/socket/ssl_client_socket.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 #include "testing/gtest/include/gtest/gtest.h" 71 #include "testing/gtest/include/gtest/gtest.h"
72 #include "testing/platform_test.h" 72 #include "testing/platform_test.h"
73 #include "third_party/boringssl/src/include/openssl/bio.h" 73 #include "third_party/boringssl/src/include/openssl/bio.h"
74 #include "third_party/boringssl/src/include/openssl/evp.h" 74 #include "third_party/boringssl/src/include/openssl/evp.h"
75 #include "third_party/boringssl/src/include/openssl/pem.h" 75 #include "third_party/boringssl/src/include/openssl/pem.h"
76 76
77 using net::test::IsError; 77 using net::test::IsError;
78 using net::test::IsOk; 78 using net::test::IsOk;
79 79
80 using testing::_; 80 using testing::_;
81 using testing::AnyOf;
81 using testing::Return; 82 using testing::Return;
82 using testing::Truly; 83 using testing::Truly;
83 84
84 namespace net { 85 namespace net {
85 86
86 class NetLogWithSource; 87 class NetLogWithSource;
87 88
88 namespace { 89 namespace {
89 90
90 // WrappedStreamSocket is a base class that wraps an existing StreamSocket, 91 // WrappedStreamSocket is a base class that wraps an existing StreamSocket,
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 1287
1287 // Rather than testing whether or not the underlying socket is connected, 1288 // Rather than testing whether or not the underlying socket is connected,
1288 // test that the handshake has finished. This is because it may be 1289 // test that the handshake has finished. This is because it may be
1289 // desirable to disconnect the socket before showing a user prompt, since 1290 // desirable to disconnect the socket before showing a user prompt, since
1290 // the user may take indefinitely long to respond. 1291 // the user may take indefinitely long to respond.
1291 TestNetLogEntry::List entries; 1292 TestNetLogEntry::List entries;
1292 log_.GetEntries(&entries); 1293 log_.GetEntries(&entries);
1293 EXPECT_TRUE(LogContainsEndEvent(entries, -1, NetLogEventType::SSL_CONNECT)); 1294 EXPECT_TRUE(LogContainsEndEvent(entries, -1, NetLogEventType::SSL_CONNECT));
1294 } 1295 }
1295 1296
1296 #if defined(OS_WIN)
1297 // Tests that certificates parsable by SSLClientSocket's internal SSL 1297 // Tests that certificates parsable by SSLClientSocket's internal SSL
1298 // implementation, but not X509Certificate are treated as fatal connection 1298 // implementation, but not X509Certificate are treated as fatal connection
1299 // errors. This is a regression test for https://crbug.com/91341. 1299 // errors. This is a regression test for https://crbug.com/91341.
1300 TEST_F(SSLClientSocketTest, ConnectBadValidity) { 1300 TEST_F(SSLClientSocketTest, ConnectBadValidity) {
1301 SpawnedTestServer::SSLOptions ssl_options( 1301 SpawnedTestServer::SSLOptions ssl_options(
1302 SpawnedTestServer::SSLOptions::CERT_BAD_VALIDITY); 1302 SpawnedTestServer::SSLOptions::CERT_BAD_VALIDITY);
1303 ASSERT_TRUE(StartTestServer(ssl_options)); 1303 ASSERT_TRUE(StartTestServer(ssl_options));
1304 cert_verifier_->set_default_result(ERR_CERT_DATE_INVALID);
1305
1304 SSLConfig ssl_config; 1306 SSLConfig ssl_config;
1305 int rv; 1307 int rv;
1306 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); 1308 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv));
1307 1309
1310 #if defined(OS_WIN)
1308 EXPECT_THAT(rv, IsError(ERR_SSL_SERVER_CERT_BAD_FORMAT)); 1311 EXPECT_THAT(rv, IsError(ERR_SSL_SERVER_CERT_BAD_FORMAT));
1309 EXPECT_FALSE(IsCertificateError(rv)); 1312 EXPECT_FALSE(IsCertificateError(rv));
1313 #elif defined(OS_ANDROID)
1314 // Android date handling behavior can vary depending on the platform.
1315 EXPECT_THAT(rv, AnyOf(IsError(ERR_SSL_SERVER_CERT_BAD_FORMAT),
1316 IsError(ERR_CERT_DATE_INVALID)));
1317 #else // !(defined(OS_WIN) || defined(OS_ANDROID))
1318 EXPECT_THAT(rv, IsError(ERR_CERT_DATE_INVALID));
1319 #endif
1310 } 1320 }
1311 #endif // defined(OS_WIN)
1312 1321
1313 // Attempt to connect to a page which requests a client certificate. It should 1322 // Attempt to connect to a page which requests a client certificate. It should
1314 // return an error code on connect. 1323 // return an error code on connect.
1315 TEST_F(SSLClientSocketTest, ConnectClientAuthCertRequested) { 1324 TEST_F(SSLClientSocketTest, ConnectClientAuthCertRequested) {
1316 SpawnedTestServer::SSLOptions ssl_options; 1325 SpawnedTestServer::SSLOptions ssl_options;
1317 ssl_options.request_client_certificate = true; 1326 ssl_options.request_client_certificate = true;
1318 ASSERT_TRUE(StartTestServer(ssl_options)); 1327 ASSERT_TRUE(StartTestServer(ssl_options));
1319 1328
1320 int rv; 1329 int rv;
1321 ASSERT_TRUE(CreateAndConnectSSLClientSocket(SSLConfig(), &rv)); 1330 ASSERT_TRUE(CreateAndConnectSSLClientSocket(SSLConfig(), &rv));
(...skipping 2548 matching lines...) Expand 10 before | Expand all | Expand 10 after
3870 // The read buffer should be released. 3879 // The read buffer should be released.
3871 StreamSocket::SocketMemoryStats stats; 3880 StreamSocket::SocketMemoryStats stats;
3872 client->DumpMemoryStats(&stats); 3881 client->DumpMemoryStats(&stats);
3873 EXPECT_EQ(0u, stats.buffer_size); 3882 EXPECT_EQ(0u, stats.buffer_size);
3874 EXPECT_EQ(1u, stats.cert_count); 3883 EXPECT_EQ(1u, stats.cert_count);
3875 EXPECT_LT(0u, stats.cert_size); 3884 EXPECT_LT(0u, stats.cert_size);
3876 EXPECT_EQ(stats.cert_size, stats.total_size); 3885 EXPECT_EQ(stats.cert_size, stats.total_size);
3877 } 3886 }
3878 3887
3879 } // namespace net 3888 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/x509_util_nss.cc ('k') | net/test/embedded_test_server/embedded_test_server_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698