These are a set of CLs merged from the wv cdm repo to the android repo. * Update service certificate. Author: Gene Morgan <gmorgan@google.com> [ Merge of http://go/wvgerrit/28065 ] The updated service certificate fixes a number of failing tests. There are still some that fail, apparently due to mismatches with key set IDs and usage tables. Also updated QA server URL to point to QA proxy (although neither can be used by this client). Also fixed segfault in CdmTest.ListUsageRecords. * Add CDM APIs for Handling Service Certificates. Author: Gene Morgan <gmorgan@google.com> [ Merge of http://go/wvgerrit/28064 ] The responsibility for managing Service Certificates has been moved out of the CDM. Instead, provide CDM and CdmEngine methods to generate a service certificate request message, and handle a service certificate response. The API client can use these calls if it needs to get the service certificate from the License Server. These functions assume the request and response are base64 (web-safe) encoded (see b/37481392). Not all servers are operating this way yet. Any adaptations for non-compliant servers is handled outside the CDM. See test WvCdmEnginePreProvTest::ServiceCertificateRequestResponse in cdm_engine_test.cpp for an example of this. These changes also eliminate the stored init_data and deferred license type which were used to perform a service certificate request during a license request. * Fix and rename ClosesSessionWithoutReturningError test. Author: Edwin Wong <edwinwong@google.com> [ Merge of http://go/wvgerrit/27880 ] ClosesSessionWithoutReturningError should not check for Status::OK since it is expecting an error code back. The test is renamed to ClosesSessionWithError. Test: libwvdrmdrmplugin_hidl_test BUG: 62205215 * Get rid of default service certificate. Author: Gene Morgan <gmorgan@google.com> [ Merge of http://go/wvgerrit/27981 ] Instead, we need at least two service certs - one for the QA/Test servers, and one for UAT (and prod?) There are still some issues around the signature verififcation of the service cert, and in license_unittest.cpp, the use of the default service cert has been commented out. I don't know why this test needs a service cert. If it really does, then the same mechanism that is used elsewhere for selecting a specific server type will be needed here. BUG: 71650075 Test: Not currently passing. Will be addressed in a subsequent commit in the chain. Change-Id: Ieab815fb202c809ad5714cd0364c4bdfa068f77d
156 lines
6.1 KiB
C++
156 lines
6.1 KiB
C++
// Copyright 2017 Google Inc. All Rights Reserved.
|
|
//
|
|
// This file contains unit tests for the WvContentDecryptionModule class
|
|
// that pertain to collecting and reporting metrics.
|
|
|
|
#include "gmock/gmock.h"
|
|
#include "log.h"
|
|
#include "metrics.pb.h"
|
|
#include "test_base.h"
|
|
#include "test_printers.h"
|
|
#include "wv_cdm_types.h"
|
|
#include "wv_content_decryption_module.h"
|
|
|
|
using ::testing::Eq;
|
|
using ::testing::StrEq;
|
|
using ::testing::Ge;
|
|
using ::testing::Test;
|
|
using wvcdm::CdmResponseType;
|
|
|
|
namespace wvcdm {
|
|
|
|
// This class is used to test the metrics-related feaures of the
|
|
// WvContentDecryptionModule class.
|
|
class WvContentDecryptionModuleMetricsTest : public ::testing::Test {
|
|
protected:
|
|
|
|
wvcdm::WvContentDecryptionModule decryptor_;
|
|
};
|
|
|
|
TEST_F(WvContentDecryptionModuleMetricsTest, NoMetrics) {
|
|
// Get metrics before any operations are performed.
|
|
std::string serialized_metrics;
|
|
decryptor_.GetSerializedMetrics(&serialized_metrics);
|
|
EXPECT_TRUE(serialized_metrics.empty());
|
|
}
|
|
|
|
TEST_F(WvContentDecryptionModuleMetricsTest, EngineOnlyMetrics) {
|
|
std::string request;
|
|
std::string provisioning_server_url;
|
|
CdmCertificateType cert_type = kCertificateWidevine;
|
|
std::string cert_authority, cert, wrapped_key;
|
|
|
|
// This call will create a CdmEngine instance with an EngineMetrics instance.
|
|
EXPECT_EQ(wvcdm::NO_ERROR,
|
|
decryptor_.GetProvisioningRequest(cert_type, cert_authority,
|
|
kDefaultCdmIdentifier, &request,
|
|
&provisioning_server_url));
|
|
std::string serialized_metrics;
|
|
decryptor_.GetSerializedMetrics(&serialized_metrics);
|
|
|
|
// Spot check some metric values.
|
|
drm_metrics::MetricsGroup metrics;
|
|
ASSERT_TRUE(metrics.ParseFromString(serialized_metrics));
|
|
EXPECT_THAT(metrics.metric_size(), Eq(0));
|
|
ASSERT_THAT(metrics.metric_sub_group_size(), Eq(1));
|
|
ASSERT_THAT(metrics.metric_sub_group(0).metric_size(), Ge(6));
|
|
EXPECT_THAT(metrics.metric_sub_group(0).metric_sub_group_size(), Eq(0));
|
|
EXPECT_THAT(metrics.metric_sub_group(0).metric(0).name(),
|
|
StrEq("/drm/widevine/oemcrypto/initialization_mode"));
|
|
// Can't check the initialization mode value. Different devices will have
|
|
// different values.
|
|
EXPECT_THAT(
|
|
metrics.metric_sub_group(0).metric(5).name(),
|
|
StrEq("/drm/widevine/cdm_engine/"
|
|
"get_provisioning_request/time/count{error:0}"));
|
|
EXPECT_THAT(metrics.metric_sub_group(0).metric(5).value().int_value(), Eq(1));
|
|
}
|
|
|
|
|
|
TEST_F(WvContentDecryptionModuleMetricsTest, EngineAndSessionMetrics) {
|
|
CdmSessionId session_id;
|
|
wvcdm::CdmKeySystem key_system("com.widevine");
|
|
|
|
// Openning the session will fail with NEEDS_PROVISIONING error. But it will
|
|
// still create some session-level stats.
|
|
EXPECT_EQ(CdmResponseType::NEED_PROVISIONING,
|
|
decryptor_.OpenSession(key_system, NULL,
|
|
kDefaultCdmIdentifier, NULL, &session_id));
|
|
|
|
// The metrics will have a single engine and single session stats.
|
|
std::string serialized_metrics;
|
|
decryptor_.GetSerializedMetrics(&serialized_metrics);
|
|
|
|
// Spot check some metric values.
|
|
drm_metrics::MetricsGroup metrics;
|
|
ASSERT_TRUE(metrics.ParseFromString(serialized_metrics));
|
|
// The outer container will never have metrics.
|
|
EXPECT_THAT(metrics.metric_size(), Eq(0));
|
|
ASSERT_THAT(metrics.metric_sub_group_size(), Eq(1));
|
|
ASSERT_THAT(metrics.metric_sub_group(0).metric_size(), Ge(6));
|
|
|
|
// Validate engine-level metrics.
|
|
EXPECT_THAT(metrics.metric_sub_group(0).metric(0).name(),
|
|
StrEq("/drm/widevine/oemcrypto/initialization_mode"));
|
|
EXPECT_THAT(metrics.metric_sub_group(0).metric(5).name(),
|
|
StrEq("/drm/widevine/cdm_engine/open_session/count{error:7}"));
|
|
EXPECT_THAT(metrics.metric_sub_group(0).metric(5).value().int_value(), Eq(1));
|
|
|
|
// Validate a session-level metric.
|
|
EXPECT_THAT(metrics.metric_sub_group(0).metric_sub_group_size(), Eq(1));
|
|
EXPECT_THAT(
|
|
metrics.metric_sub_group(0).metric_sub_group(0).metric(0).name(),
|
|
StrEq("/drm/widevine/cdm_session/session_id"));
|
|
}
|
|
|
|
TEST_F(WvContentDecryptionModuleMetricsTest, MultipleEngineMetric) {
|
|
CdmSessionId session_id;
|
|
wvcdm::CdmKeySystem key_system("com.widevine");
|
|
CdmIdentifier identifier = { "foo", "bar", "baz" };
|
|
|
|
// Openning the session will fail with NEEDS_PROVISIONING error. But it will
|
|
// still create some session-level stats.
|
|
EXPECT_EQ(CdmResponseType::NEED_PROVISIONING,
|
|
decryptor_.OpenSession(key_system, NULL,
|
|
kDefaultCdmIdentifier, NULL, &session_id));
|
|
// Open a second engine with a custom identifier.
|
|
EXPECT_EQ(CdmResponseType::NEED_PROVISIONING,
|
|
decryptor_.OpenSession(key_system, NULL,
|
|
identifier, NULL, &session_id));
|
|
|
|
// The metrics will now have two engines with single session stats each.
|
|
std::string serialized_metrics;
|
|
decryptor_.GetSerializedMetrics(&serialized_metrics);
|
|
|
|
// Spot check some metric values.
|
|
drm_metrics::MetricsGroup metrics;
|
|
ASSERT_TRUE(metrics.ParseFromString(serialized_metrics));
|
|
// The outer container will never have metrics.
|
|
EXPECT_THAT(metrics.metric_size(), Eq(0));
|
|
|
|
// Two engine-level metrics are expected.
|
|
ASSERT_THAT(metrics.metric_sub_group_size(), Eq(2));
|
|
|
|
for (int i = 0; i < metrics.metric_sub_group_size(); i++) {
|
|
// Validate the engine-level metric.
|
|
ASSERT_THAT(metrics.metric_sub_group(i).metric_size(), Ge(6));
|
|
EXPECT_THAT(metrics.metric_sub_group(i).metric(0).name(),
|
|
StrEq("/drm/widevine/oemcrypto/initialization_mode"));
|
|
EXPECT_THAT(metrics.metric_sub_group(i).metric(5).name(),
|
|
StrEq("/drm/widevine/cdm_engine/open_session/count{error:7}"));
|
|
EXPECT_THAT(metrics.metric_sub_group(i).metric(5).value().int_value(),
|
|
Eq(1));
|
|
|
|
// Validate a session-level metric.
|
|
EXPECT_THAT(metrics.metric_sub_group(i).metric_sub_group_size(), Eq(1));
|
|
EXPECT_THAT(
|
|
metrics.metric_sub_group(i).metric_sub_group(0).metric(0).name(),
|
|
StrEq("/drm/widevine/cdm_session/session_id"));
|
|
}
|
|
|
|
// Verify that the second metrics app package name is set.
|
|
EXPECT_THAT(metrics.metric_sub_group(1).app_package_name(), StrEq("baz"));
|
|
}
|
|
|
|
}
|