Test name-based version APIs are reported as expected.

Notably, Conscrypt uses SSL_SESSION_get_version, so we should have tests
for it.

Change-Id: I670f1b1b9951f840f27cb62dd36ef4f05042c974
Reviewed-on: https://boringssl-review.googlesource.com/12881
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: Steven Valdez <svaldez@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
This commit is contained in:
David Benjamin 2016-12-15 13:53:25 -05:00 committed by CQ bot account: commit-bot@chromium.org
parent e6620af176
commit 458334a159

View File

@ -2588,6 +2588,27 @@ static bool TestSetVersion() {
return true; return true;
} }
static const char *GetVersionName(uint16_t version) {
switch (version) {
case SSL3_VERSION:
return "SSLv3";
case TLS1_VERSION:
return "TLSv1";
case TLS1_1_VERSION:
return "TLSv1.1";
case TLS1_2_VERSION:
return "TLSv1.2";
case TLS1_3_VERSION:
return "TLSv1.3";
case DTLS1_VERSION:
return "DTLSv1";
case DTLS1_2_VERSION:
return "DTLSv1.2";
default:
return "???";
}
}
static bool TestVersion(bool is_dtls, const SSL_METHOD *method, static bool TestVersion(bool is_dtls, const SSL_METHOD *method,
uint16_t version) { uint16_t version) {
bssl::UniquePtr<X509> cert = GetTestCertificate(); bssl::UniquePtr<X509> cert = GetTestCertificate();
@ -2619,6 +2640,29 @@ static bool TestVersion(bool is_dtls, const SSL_METHOD *method,
return false; return false;
} }
// Test the version name is reported as expected.
const char *version_name = GetVersionName(version);
if (strcmp(version_name, SSL_get_version(client.get())) != 0 ||
strcmp(version_name, SSL_get_version(server.get())) != 0) {
fprintf(stderr, "Version name mismatch. Got '%s' and '%s', wanted '%s'.\n",
SSL_get_version(client.get()), SSL_get_version(server.get()),
version_name);
return false;
}
// Test SSL_SESSION reports the same name.
const char *client_name =
SSL_SESSION_get_version(SSL_get_session(client.get()));
const char *server_name =
SSL_SESSION_get_version(SSL_get_session(server.get()));
if (strcmp(version_name, client_name) != 0 ||
strcmp(version_name, server_name) != 0) {
fprintf(stderr,
"Session version name mismatch. Got '%s' and '%s', wanted '%s'.\n",
client_name, server_name, version_name);
return false;
}
return true; return true;
} }