Common test main
Merge from Widevine repo of http://go/wvgerrit/56521 This CL adds a common main routine for integration tests. It sets a default test configuration for the provisioning and license server urls and certificates, and allows the user to set them on the command line. Test: current unit tests still pass. Bug: 72354901 Fix Generic Crypto tests. Change-Id: I604a3d9e15d50da5041794624c4571c0dcb091f5
This commit is contained in:
@@ -39,6 +39,7 @@ namespace {
|
||||
// Http OK response code.
|
||||
const int kHttpOk = 200;
|
||||
|
||||
// TODO(fredgc): Move these to test_base.cpp in next CL.
|
||||
// Default license server, can be configured using --server command line option
|
||||
// Default key id (pssh), can be configured using --keyid command line option
|
||||
std::string g_client_auth;
|
||||
|
||||
@@ -260,14 +260,17 @@ const std::string kGpClientOfflineReleaseQueryParameters =
|
||||
const ConfigTestEnv::LicenseServerConfiguration license_servers[] = {
|
||||
{kGooglePlayServer, kGpLicenseServer, "", kGpClientAuth, kGpKeyId,
|
||||
kGpOfflineKeyId, kCpProductionProvisioningServerUrl, ""},
|
||||
|
||||
{kContentProtectionUatServer, kCpUatLicenseServer, kCpUatServiceCertificate,
|
||||
kCpClientAuth, kCpKeyId, kCpOfflineKeyId,
|
||||
// TODO(rfrias): replace when b/62880305 is addressed. For now use production
|
||||
kCpProductionProvisioningServerUrl,
|
||||
kCpProductionProvisioningServiceCertificate},
|
||||
|
||||
{kContentProtectionStagingServer, kCpStagingLicenseServer,
|
||||
kCpStagingServiceCertificate, kCpClientAuth, kCpKeyId, kCpOfflineKeyId,
|
||||
kCpStagingProvisioningServerUrl, kCpStagingProvisioningServiceCertificate},
|
||||
|
||||
{kContentProtectionProductionServer, kCpProductionLicenseServer,
|
||||
kCpProductionServiceCertificate, kCpClientAuth, kCpKeyId, kCpOfflineKeyId,
|
||||
kCpProductionProvisioningServerUrl,
|
||||
@@ -303,7 +306,21 @@ ConfigTestEnv::ConfigTestEnv(ServerConfigurationId server_id, bool streaming,
|
||||
}
|
||||
}
|
||||
|
||||
ConfigTestEnv& ConfigTestEnv::operator=(const ConfigTestEnv &other) {
|
||||
this->server_id_ = other.server_id_;
|
||||
this->client_auth_ = other.client_auth_;
|
||||
this->key_id_ = other.key_id_;
|
||||
this->key_system_ = other.key_system_;
|
||||
this->license_server_ = other.license_server_;
|
||||
this->provisioning_server_ = other.provisioning_server_;
|
||||
this->license_service_certificate_ = other.license_service_certificate_;
|
||||
this->provisioning_service_certificate_ =
|
||||
other.provisioning_service_certificate_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ConfigTestEnv::Init(ServerConfigurationId server_id) {
|
||||
this->server_id_ = server_id;
|
||||
client_auth_ = license_servers[server_id].client_tag;
|
||||
key_id_ = license_servers[server_id].key_id;
|
||||
key_system_ = kWidevineKeySystem;
|
||||
|
||||
@@ -49,20 +49,25 @@ class ConfigTestEnv {
|
||||
typedef struct {
|
||||
ServerConfigurationId id;
|
||||
std::string license_server_url;
|
||||
std::string license_service_certificate;
|
||||
std::string license_service_certificate; // Binary (not hex).
|
||||
std::string client_tag;
|
||||
std::string key_id;
|
||||
std::string key_id; // Hex.
|
||||
std::string offline_key_id;
|
||||
std::string provisioning_server_url;
|
||||
std::string provisioning_service_certificate;
|
||||
std::string provisioning_service_certificate; // Binary (not hex).
|
||||
} LicenseServerConfiguration;
|
||||
|
||||
explicit ConfigTestEnv(ServerConfigurationId server_id);
|
||||
ConfigTestEnv(ServerConfigurationId server_id, bool streaming);
|
||||
ConfigTestEnv(ServerConfigurationId server_id, bool streaming, bool renew,
|
||||
bool release);
|
||||
// Allow copy and assign. Performance is not an issue in test initialization.
|
||||
ConfigTestEnv(const ConfigTestEnv &other) { *this = other; };
|
||||
ConfigTestEnv& operator=(const ConfigTestEnv &other);
|
||||
|
||||
~ConfigTestEnv() {};
|
||||
|
||||
ServerConfigurationId server_id() { return server_id_; }
|
||||
const std::string& client_auth() const { return client_auth_; }
|
||||
const KeyId& key_id() const { return key_id_; }
|
||||
const CdmKeySystem& key_system() const { return key_system_; }
|
||||
@@ -88,13 +93,22 @@ class ConfigTestEnv {
|
||||
void set_license_server(std::string& license_server) {
|
||||
license_server_.assign(license_server);
|
||||
}
|
||||
void set_license_service_certificate(
|
||||
std::string& license_service_certificate) {
|
||||
license_service_certificate_.assign(license_service_certificate);
|
||||
}
|
||||
void set_provisioning_server(std::string& provisioning_server) {
|
||||
provisioning_server_.assign(provisioning_server);
|
||||
}
|
||||
void set_provisioning_service_certificate(
|
||||
std::string& provisioning_service_certificate) {
|
||||
provisioning_service_certificate_.assign(provisioning_service_certificate);
|
||||
}
|
||||
|
||||
private:
|
||||
void Init(ServerConfigurationId server_id);
|
||||
|
||||
ServerConfigurationId server_id_;
|
||||
std::string client_auth_;
|
||||
KeyId key_id_;
|
||||
CdmKeySystem key_system_;
|
||||
@@ -102,8 +116,6 @@ class ConfigTestEnv {
|
||||
std::string provisioning_server_;
|
||||
std::string license_service_certificate_;
|
||||
std::string provisioning_service_certificate_;
|
||||
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(ConfigTestEnv);
|
||||
};
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
@@ -24,6 +24,74 @@
|
||||
#include "url_request.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace {
|
||||
void show_menu(char* prog_name) {
|
||||
std::cout << std::endl;
|
||||
std::cout << "usage: " << prog_name << " [options]" << std::endl << std::endl;
|
||||
std::cout << " enclose multiple arguments in '' when using adb shell"
|
||||
<< std::endl;
|
||||
std::cout << " e.g. adb shell '" << prog_name << " --server=\"url\"'"
|
||||
<< std::endl;
|
||||
std::cout << " or adb shell '" << prog_name << " -u\"url\"'" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
std::cout << " -v/--verbose" << std::endl;
|
||||
std::cout << " increase logging verbosity (may be repeated)" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
std::cout << " -f/--no_filter" << std::endl;
|
||||
std::cout << " Do not filter out inappropriate tests" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
std::cout << " -c/--cast" << std::endl;
|
||||
std::cout << " Run tests appropriate for a Cast Receiver" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
std::cout << " -i/--license_server_id=<gp/cp/st>" << std::endl;
|
||||
std::cout << " specifies which default server settings to use: "
|
||||
<< std::endl;
|
||||
std::cout << " gp for GooglePlay server" << std::endl;
|
||||
std::cout << " cp for Content Protection UAT server" << std::endl;
|
||||
std::cout << " st for Content Protection Staging server" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
std::cout << " -k/--keyid=<key_id>" << std::endl;
|
||||
std::cout << " configure the key id or pssh, in hex format" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
std::cout << " -s/--service_certificate=<cert>" << std::endl;
|
||||
std::cout << " configure the signed license service certificate" << std::endl;
|
||||
std::cout << " Specify the SignedDeviceCertificate (from "
|
||||
<< "device_certificate.proto) " << std::endl;
|
||||
std::cout << " in hex format." << std::endl;
|
||||
std::cout << " Due to the length of the argument use, " << std::endl;
|
||||
std::cout << " echo \"/system/bin/request_license_test -s \\\""
|
||||
<< "0ABF02...A29914\\\"\" \\" << std::endl;
|
||||
std::cout << " > run_request_license_test.sh" << std::endl;
|
||||
std::cout << " chmod +x run_request_license_test.sh" << std::endl;
|
||||
std::cout << " adb push run_request_license_test.sh /system/bin"
|
||||
<< std::endl;
|
||||
std::cout << " adb shell sh /system/bin/run_request_license_test.sh"
|
||||
<< std::endl << std::endl;
|
||||
|
||||
std::cout << " -S/--provisioning_certificate=<cert>" << std::endl;
|
||||
std::cout << " configure the signed provisioning service certificate" << std::endl
|
||||
<< " in hex" << std::endl << std::endl;
|
||||
|
||||
std::cout << " -u/--license_server_url=<url>" << std::endl;
|
||||
std::cout << " configure the license server url, please include http[s]"
|
||||
<< " in the url" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
std::cout << " -p/--provisioning_server_url=<url>" << std::endl;
|
||||
std::cout << " configure the provisioning server url, please include http[s]"
|
||||
<< " in the url" << std::endl
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ConfigTestEnv WvCdmTestBase::default_config_(kContentProtectionUatServer);
|
||||
|
||||
TestCryptoSession::TestCryptoSession(metrics::CryptoMetrics* crypto_metrics)
|
||||
: CryptoSession(crypto_metrics) {
|
||||
@@ -79,4 +147,113 @@ void WvCdmTestBase::InstallTestRootOfTrust() {
|
||||
}
|
||||
}
|
||||
|
||||
bool WvCdmTestBase::Initialize(int argc, char **argv) {
|
||||
Properties::Init();
|
||||
bool is_cast_receiver = false;
|
||||
bool force_load_test_keybox = false; // TODO(fredgc): obsolete. remove.
|
||||
bool filter_tests = true;
|
||||
bool show_usage = false;
|
||||
|
||||
static const struct option long_options[] = {
|
||||
{"license_server_id", required_argument, NULL, 'i'},
|
||||
{"keyid", required_argument, NULL, 'k'},
|
||||
{"service_certificate", required_argument, NULL, 's'},
|
||||
{"provisioning_certificate", required_argument, NULL, 'S'},
|
||||
{"license_server_url", required_argument, NULL, 'u'},
|
||||
{"provisioning_server_url", required_argument, NULL, 'p'},
|
||||
{"cast", no_argument, NULL, 'c'},
|
||||
{"no_filter", no_argument, NULL, 'f'},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{NULL, 0, NULL, '\0'}};
|
||||
|
||||
int option_index = 0;
|
||||
int opt = 0;
|
||||
int verbosity = 0;
|
||||
while ((opt = getopt_long(argc, argv, "i:k:s:S:u:p:cfv", long_options,
|
||||
&option_index)) != -1) {
|
||||
switch (opt) {
|
||||
case 'i': {
|
||||
std::string license_id(optarg);
|
||||
if (!license_id.compare("gp")) {
|
||||
default_config_ = ConfigTestEnv(kGooglePlayServer);
|
||||
} else if (!license_id.compare("cp")) {
|
||||
default_config_ = ConfigTestEnv(kContentProtectionUatServer);
|
||||
} else if (!license_id.compare("st")) {
|
||||
default_config_ = ConfigTestEnv(kContentProtectionStagingServer);
|
||||
} else {
|
||||
std::cout << "Invalid license server id" << optarg << std::endl;
|
||||
show_usage = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'k': {
|
||||
std::string key_id(optarg);
|
||||
default_config_.set_key_id(key_id);
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
std::string certificate(a2bs_hex(optarg));
|
||||
default_config_.set_license_service_certificate(certificate);
|
||||
break;
|
||||
}
|
||||
case 'S': {
|
||||
std::string certificate(a2bs_hex(optarg));
|
||||
default_config_.set_provisioning_service_certificate(certificate);
|
||||
break;
|
||||
}
|
||||
case 'u': {
|
||||
std::string server(optarg);
|
||||
default_config_.set_license_server(server);
|
||||
break;
|
||||
}
|
||||
case 'p': {
|
||||
std::string server(optarg);
|
||||
default_config_.set_provisioning_server(server);
|
||||
break;
|
||||
}
|
||||
case 'c': {
|
||||
is_cast_receiver = true;
|
||||
break;
|
||||
}
|
||||
case 'f': {
|
||||
filter_tests = false;
|
||||
break;
|
||||
}
|
||||
case 'v': {
|
||||
++verbosity;
|
||||
break;
|
||||
}
|
||||
case '?': {
|
||||
show_usage = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (show_usage) {
|
||||
show_menu(argv[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
g_cutoff = static_cast<LogPriority>(verbosity);
|
||||
|
||||
// Displays server url, port and key Id being used
|
||||
std::cout << std::endl;
|
||||
std::cout << "Default Server: " << default_config_.license_server()
|
||||
<< std::endl;
|
||||
std::cout << "Default KeyID: " << default_config_.key_id() << std::endl
|
||||
<< std::endl;
|
||||
|
||||
// Figure out which tests are appropriate for OEMCrypto, based on features
|
||||
// supported.
|
||||
wvoec::global_features.Initialize(is_cast_receiver, force_load_test_keybox);
|
||||
// If the user requests --no_filter, we don't change the filter, otherwise, we
|
||||
// filter out features that are not supported.
|
||||
if (filter_tests) {
|
||||
::testing::GTEST_FLAG(filter) =
|
||||
wvoec::global_features.RestrictFilter(::testing::GTEST_FLAG(filter));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
@@ -10,18 +10,32 @@
|
||||
#include "config_test_env.h"
|
||||
#include "crypto_session.h"
|
||||
#include "metrics_collections.h"
|
||||
#include "string_conversions.h"
|
||||
|
||||
namespace wvcdm {
|
||||
// This is the base class for Widevine CDM integration tests. It's main use is
|
||||
// to configure OEMCrypto to use a test keybox.
|
||||
class WvCdmTestBase : public ::testing::Test {
|
||||
public:
|
||||
WvCdmTestBase() {}
|
||||
WvCdmTestBase() : config_(default_config_) {}
|
||||
virtual ~WvCdmTestBase() {}
|
||||
virtual void SetUp();
|
||||
virtual std::string binary_key_id() const { return a2bs_hex(config_.key_id()); }
|
||||
|
||||
// Returns true if the test program should continue, if false, the caller
|
||||
// should exit. This should be called by main() to allow the user to pass in
|
||||
// command line switches.
|
||||
static bool Initialize(int argc, char **argv);
|
||||
// Install a test keybox, if appropriate.
|
||||
static void InstallTestRootOfTrust();
|
||||
|
||||
// The default test configuration. This is influenced by command line
|
||||
// arguments before any tests are created.
|
||||
static ConfigTestEnv default_config_;
|
||||
|
||||
// Configuration for an individual test. This is initialized to be the
|
||||
// default configuration, but can be modified by the test itself.
|
||||
ConfigTestEnv config_;
|
||||
};
|
||||
|
||||
class TestCryptoSession : public CryptoSession {
|
||||
|
||||
17
libwvdrmengine/cdm/core/test/test_main.cpp
Normal file
17
libwvdrmengine/cdm/core/test/test_main.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
|
||||
// Use in place of the gtest_main in order to initialize the WvCdmTestBase using
|
||||
// command line parameters.
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "test_base.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
if (!wvcdm::WvCdmTestBase::Initialize(argc, argv)) return 0;
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user