Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Backed out changeset 3e26ed399241
  • Loading branch information
jcjones committed Jan 27, 2019
1 parent f9b996b commit 53105e7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 143 deletions.
6 changes: 0 additions & 6 deletions gtests/ssl_gtest/Makefile
Expand Up @@ -36,12 +36,6 @@ CPPSRCS := $(filter-out $(shell grep -l '^TEST_F' $(CPPSRCS)), $(CPPSRCS))
CFLAGS += -DNSS_DISABLE_TLS_1_3
endif

ifdef NSS_ALLOW_SSLKEYLOGFILE
SSLKEYLOGFILE_FILES = ssl_keylog_unittest.cc
else
SSLKEYLOGFILE_FILES = $(NULL)
endif

#######################################################################
# (5) Execute "global" rules. (OPTIONAL) #
#######################################################################
Expand Down
3 changes: 1 addition & 2 deletions gtests/ssl_gtest/manifest.mn
Expand Up @@ -20,7 +20,6 @@ CPPSRCS = \
ssl_ciphersuite_unittest.cc \
ssl_custext_unittest.cc \
ssl_damage_unittest.cc \
ssl_debug_env_unittest.cc \
ssl_dhe_unittest.cc \
ssl_drop_unittest.cc \
ssl_ecdh_unittest.cc \
Expand All @@ -32,6 +31,7 @@ CPPSRCS = \
ssl_gather_unittest.cc \
ssl_gtest.cc \
ssl_hrr_unittest.cc \
ssl_keylog_unittest.cc \
ssl_keyupdate_unittest.cc \
ssl_loopback_unittest.cc \
ssl_misc_unittest.cc \
Expand All @@ -53,7 +53,6 @@ CPPSRCS = \
tls_filter.cc \
tls_protect.cc \
tls_esni_unittest.cc \
$(SSLKEYLOGFILE_FILES) \
$(NULL)

INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
Expand Down
53 changes: 0 additions & 53 deletions gtests/ssl_gtest/ssl_debug_env_unittest.cc

This file was deleted.

4 changes: 1 addition & 3 deletions gtests/ssl_gtest/ssl_gtest.gyp
Expand Up @@ -21,7 +21,6 @@
'ssl_ciphersuite_unittest.cc',
'ssl_custext_unittest.cc',
'ssl_damage_unittest.cc',
'ssl_debug_env_unittest.cc',
'ssl_dhe_unittest.cc',
'ssl_drop_unittest.cc',
'ssl_ecdh_unittest.cc',
Expand Down Expand Up @@ -100,8 +99,7 @@
'../../lib/ssl'
],
'defines': [
'NSS_USE_STATIC_LIBS',
'NSS_ALLOW_SSLKEYLOGFILE=1',
'NSS_USE_STATIC_LIBS'
],
},
'variables': {
Expand Down
108 changes: 29 additions & 79 deletions gtests/ssl_gtest/ssl_keylog_unittest.cc
Expand Up @@ -15,59 +15,20 @@

namespace nss_test {

static const std::string kKeylogFilePath = "keylog.txt";
static const std::string kKeylogBlankEnv = "SSLKEYLOGFILE=";
static const std::string kKeylogSetEnv = kKeylogBlankEnv + kKeylogFilePath;

extern "C" {
extern FILE* ssl_keylog_iob;
}

class KeyLogFileTestBase : public TlsConnectGeneric {
private:
std::string env_to_set_;
static const std::string keylog_file_path = "keylog.txt";
static const std::string keylog_env = "SSLKEYLOGFILE=" + keylog_file_path;

class KeyLogFileTest : public TlsConnectGeneric {
public:
virtual void CheckKeyLog() = 0;

KeyLogFileTestBase(std::string env) : env_to_set_(env) {}

void SetUp() override {
TlsConnectGeneric::SetUp();
// Remove previous results (if any).
(void)remove(kKeylogFilePath.c_str());
PR_SetEnv(env_to_set_.c_str());
}

void ConnectAndCheck() {
// This is a child process, ensure that error messages immediately
// propagate or else it will not be visible.
::testing::GTEST_FLAG(throw_on_failure) = true;

if (version_ == SSL_LIBRARY_VERSION_TLS_1_3) {
SetupForZeroRtt();
client_->Set0RttEnabled(true);
server_->Set0RttEnabled(true);
ExpectResumption(RESUME_TICKET);
ZeroRttSendReceive(true, true);
Handshake();
ExpectEarlyDataAccepted(true);
CheckConnected();
SendReceive();
} else {
Connect();
(void)remove(keylog_file_path.c_str());
PR_SetEnv(keylog_env.c_str());
}
CheckKeyLog();
_exit(0);
}
};

class KeyLogFileTest : public KeyLogFileTestBase {
public:
KeyLogFileTest() : KeyLogFileTestBase(kKeylogSetEnv) {}

void CheckKeyLog() override {
std::ifstream f(kKeylogFilePath);
void CheckKeyLog() {
std::ifstream f(keylog_file_path);
std::map<std::string, size_t> labels;
std::set<std::string> client_randoms;
for (std::string line; std::getline(f, line);) {
Expand Down Expand Up @@ -104,6 +65,28 @@ class KeyLogFileTest : public KeyLogFileTestBase {
ASSERT_EQ(4U, labels["EXPORTER_SECRET"]);
}
}

void ConnectAndCheck() {
// This is a child process, ensure that error messages immediately
// propagate or else it will not be visible.
::testing::GTEST_FLAG(throw_on_failure) = true;

if (version_ == SSL_LIBRARY_VERSION_TLS_1_3) {
SetupForZeroRtt();
client_->Set0RttEnabled(true);
server_->Set0RttEnabled(true);
ExpectResumption(RESUME_TICKET);
ZeroRttSendReceive(true, true);
Handshake();
ExpectEarlyDataAccepted(true);
CheckConnected();
SendReceive();
} else {
Connect();
}
CheckKeyLog();
_exit(0);
}
};

// Tests are run in a separate process to ensure that NSS is not initialized yet
Expand All @@ -130,39 +113,6 @@ INSTANTIATE_TEST_CASE_P(
TlsConnectTestBase::kTlsV13));
#endif

class KeyLogFileUnsetTest : public KeyLogFileTestBase {
public:
KeyLogFileUnsetTest() : KeyLogFileTestBase(kKeylogBlankEnv) {}

void CheckKeyLog() override {
std::ifstream f(kKeylogFilePath);
EXPECT_FALSE(f.good());

EXPECT_EQ(nullptr, ssl_keylog_iob);
}
};

TEST_P(KeyLogFileUnsetTest, KeyLogFile) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";

ASSERT_EXIT(ConnectAndCheck(), ::testing::ExitedWithCode(0), "");
}

INSTANTIATE_TEST_CASE_P(
KeyLogFileDTLS12, KeyLogFileUnsetTest,
::testing::Combine(TlsConnectTestBase::kTlsVariantsDatagram,
TlsConnectTestBase::kTlsV11V12));
INSTANTIATE_TEST_CASE_P(
KeyLogFileTLS12, KeyLogFileUnsetTest,
::testing::Combine(TlsConnectTestBase::kTlsVariantsStream,
TlsConnectTestBase::kTlsV10ToV12));
#ifndef NSS_DISABLE_TLS_1_3
INSTANTIATE_TEST_CASE_P(
KeyLogFileTLS13, KeyLogFileUnsetTest,
::testing::Combine(TlsConnectTestBase::kTlsVariantsStream,
TlsConnectTestBase::kTlsV13));
#endif

} // namespace nss_test

#endif // NSS_ALLOW_SSLKEYLOGFILE

0 comments on commit 53105e7

Please sign in to comment.