Source release 14.2.0
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "clock.h"
|
||||
#include "crypto_key.h"
|
||||
#include "crypto_session.h"
|
||||
#include "initialization_data.h"
|
||||
#include "license.h"
|
||||
@@ -15,6 +16,8 @@
|
||||
#include "properties.h"
|
||||
#include "service_certificate.h"
|
||||
#include "string_conversions.h"
|
||||
#include "test_base.h"
|
||||
#include "test_printers.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
|
||||
namespace wvcdm {
|
||||
@@ -142,10 +145,24 @@ const CryptoSession::SupportedCertificateTypes kDefaultSupportedCertTypes = {
|
||||
true
|
||||
};
|
||||
|
||||
class MockCryptoSession : public CryptoSession {
|
||||
const std::string kFakeEntitlementKeyId =
|
||||
a2bs_hex("2a538231c616c67143032a645f9c545d");
|
||||
const std::string kFakeEntitledKeyId =
|
||||
a2bs_hex("f93c7a81e62d4e9a988ff20bca60f52d");
|
||||
const std::string kFakeUnpaddedKey =
|
||||
a2bs_hex("b2047e7fab08b3a4dac76b7b82e8cd4d");
|
||||
const std::string kFakePaddedKey =
|
||||
a2bs_hex("42f804e9ce0fa693692e1c4ffaeb0e14"
|
||||
"10101010101010101010101010101010");
|
||||
const std::string kFakeKeyTooLong =
|
||||
a2bs_hex("d4bc8605d662878a46adb2adb6bf3c0b30a54a0c2f");
|
||||
const std::string kFakeKeyTooShort = a2bs_hex("06e247e7f924208011");
|
||||
const std::string kFakeIv = a2bs_hex("3d515a3ee0be1687080ac59da9e0d69a");
|
||||
|
||||
class MockCryptoSession : public TestCryptoSession {
|
||||
public:
|
||||
MockCryptoSession(metrics::CryptoMetrics* crypto_metrics)
|
||||
: CryptoSession(crypto_metrics) { }
|
||||
: TestCryptoSession(crypto_metrics) { }
|
||||
MOCK_METHOD0(IsOpen, bool());
|
||||
MOCK_METHOD1(GenerateRequestId, bool(std::string*));
|
||||
MOCK_METHOD1(UsageInformationSupport, bool(bool*));
|
||||
@@ -157,12 +174,16 @@ class MockCryptoSession : public CryptoSession {
|
||||
MOCK_METHOD3(GenerateSubSessionNonce,
|
||||
bool(const std::string& sub_session_key_id, bool* exists,
|
||||
uint32_t* nonce));
|
||||
MOCK_METHOD1(LoadEntitledContentKeys,
|
||||
CdmResponseType(const std::vector<CryptoKey>& key_array));
|
||||
};
|
||||
|
||||
class MockPolicyEngine : public PolicyEngine {
|
||||
public:
|
||||
MockPolicyEngine(CryptoSession* crypto)
|
||||
: PolicyEngine("mock_session_id", NULL, crypto) {}
|
||||
MOCK_METHOD1(SetEntitledLicenseKeys,
|
||||
void(const std::vector<video_widevine::WidevinePsshData_EntitledKey>&));
|
||||
};
|
||||
|
||||
class MockClock : public Clock {
|
||||
@@ -183,22 +204,40 @@ class MockInitializationData : public InitializationData {
|
||||
// Protobuf generated classes
|
||||
using video_widevine::LicenseRequest_ContentIdentification;
|
||||
using video_widevine::ClientIdentification;
|
||||
using video_widevine::License;
|
||||
using video_widevine::License_KeyContainer;
|
||||
using video_widevine::LicenseRequest;
|
||||
using video_widevine::SignedMessage;
|
||||
using video_widevine::WidevinePsshData_EntitledKey;
|
||||
|
||||
// gmock methods
|
||||
using ::testing::_;
|
||||
using ::testing::Eq;
|
||||
using ::testing::NotNull;
|
||||
using ::testing::PrintToStringParamName;
|
||||
using ::testing::Return;
|
||||
using ::testing::SetArgPointee;
|
||||
using ::testing::UnorderedElementsAre;
|
||||
using ::testing::Values;
|
||||
|
||||
class CdmLicenseTest : public ::testing::Test {
|
||||
class CdmLicenseTestPeer : public CdmLicense {
|
||||
public:
|
||||
CdmLicenseTestPeer(const CdmSessionId& session_id, Clock* clock)
|
||||
: CdmLicense(session_id, clock) {}
|
||||
|
||||
using CdmLicense::HandleNewEntitledKeys;
|
||||
|
||||
void set_entitlement_keys(License license) {
|
||||
entitlement_keys_.CopyFrom(license.key());
|
||||
}
|
||||
};
|
||||
|
||||
class CdmLicenseTest : public WvCdmTestBase {
|
||||
protected:
|
||||
CdmLicenseTest(const std::string& pssh = (kCencInitDataHdr + kCencPssh))
|
||||
: pssh_(pssh) {}
|
||||
virtual void SetUp() {
|
||||
WvCdmTestBase::SetUp();
|
||||
clock_ = new MockClock();
|
||||
crypto_session_ = new MockCryptoSession(&crypto_metrics_);
|
||||
init_data_ = new MockInitializationData(CENC_INIT_DATA_FORMAT, pssh_);
|
||||
@@ -218,11 +257,11 @@ class CdmLicenseTest : public ::testing::Test {
|
||||
}
|
||||
|
||||
virtual void CreateCdmLicense() {
|
||||
cdm_license_ = new CdmLicense(kCdmSessionId, clock_);
|
||||
cdm_license_ = new CdmLicenseTestPeer(kCdmSessionId, clock_);
|
||||
clock_ = NULL;
|
||||
}
|
||||
|
||||
CdmLicense* cdm_license_;
|
||||
CdmLicenseTestPeer* cdm_license_;
|
||||
MockClock* clock_;
|
||||
metrics::CryptoMetrics crypto_metrics_;
|
||||
MockCryptoSession* crypto_session_;
|
||||
@@ -413,6 +452,85 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidation) {
|
||||
EXPECT_EQ(kNonce, license_request.key_control_nonce());
|
||||
}
|
||||
|
||||
struct EntitledKeyVariant {
|
||||
EntitledKeyVariant(const char* name, const std::string& key,
|
||||
bool should_succeed)
|
||||
: name(name),
|
||||
key(key),
|
||||
should_succeed(should_succeed) {}
|
||||
const std::string name;
|
||||
const std::string key;
|
||||
const bool should_succeed;
|
||||
|
||||
friend void PrintTo(const EntitledKeyVariant& self, std::ostream* os) {
|
||||
*os << self.name;
|
||||
}
|
||||
};
|
||||
|
||||
class CdmLicenseEntitledKeyTest
|
||||
: public CdmLicenseTest,
|
||||
public ::testing::WithParamInterface<EntitledKeyVariant> {};
|
||||
|
||||
TEST_P(CdmLicenseEntitledKeyTest, LoadsEntitledKeys) {
|
||||
EntitledKeyVariant variant = GetParam();
|
||||
|
||||
// Set up a known, fake entitlement key
|
||||
License entitlement_license;
|
||||
License_KeyContainer* entitlement_key = entitlement_license.add_key();
|
||||
entitlement_key->set_type(
|
||||
video_widevine::License_KeyContainer_KeyType_ENTITLEMENT);
|
||||
entitlement_key->set_id(kFakeEntitlementKeyId);
|
||||
|
||||
// Set up a fake entitled key that matches the entitlement key
|
||||
std::vector<WidevinePsshData_EntitledKey> entitled_keys(1);
|
||||
WidevinePsshData_EntitledKey& padded_key = entitled_keys[0];
|
||||
padded_key.set_entitlement_key_id(kFakeEntitlementKeyId);
|
||||
padded_key.set_key_id(kFakeEntitledKeyId);
|
||||
padded_key.set_key(variant.key);
|
||||
padded_key.set_iv(kFakeIv);
|
||||
|
||||
// Set the expected downstream calls
|
||||
EXPECT_CALL(*crypto_session_, IsOpen())
|
||||
.WillOnce(Return(true));
|
||||
|
||||
if (variant.should_succeed) {
|
||||
EXPECT_CALL(*crypto_session_, LoadEntitledContentKeys(_))
|
||||
.WillOnce(Return(KEY_ADDED));
|
||||
EXPECT_CALL(*policy_engine_, SetEntitledLicenseKeys(_))
|
||||
.Times(1);
|
||||
} else {
|
||||
EXPECT_CALL(*crypto_session_, LoadEntitledContentKeys(_))
|
||||
.Times(0);
|
||||
EXPECT_CALL(*policy_engine_, SetEntitledLicenseKeys(_))
|
||||
.Times(0);
|
||||
}
|
||||
|
||||
// Set up the CdmLicense with the mocks and fake entitlement key
|
||||
CreateCdmLicense();
|
||||
EXPECT_TRUE(cdm_license_->Init(
|
||||
kToken, kClientTokenDrmCert, kEmptyString, true,
|
||||
kDefaultServiceCertificate, crypto_session_, policy_engine_));
|
||||
cdm_license_->set_entitlement_keys(entitlement_license);
|
||||
|
||||
// Call the function under test and check its return value
|
||||
CdmResponseType ret = cdm_license_->HandleNewEntitledKeys(entitled_keys);
|
||||
|
||||
if (variant.should_succeed) {
|
||||
EXPECT_EQ(KEY_ADDED, ret);
|
||||
} else {
|
||||
EXPECT_NE(KEY_ADDED, ret);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
EntitledKeyTests, CdmLicenseEntitledKeyTest,
|
||||
Values(
|
||||
EntitledKeyVariant("UnpaddedKey", kFakeUnpaddedKey, true),
|
||||
EntitledKeyVariant("PaddedKey", kFakePaddedKey, true),
|
||||
EntitledKeyVariant("KeyTooLong", kFakeKeyTooLong, true),
|
||||
EntitledKeyVariant("KeyTooShort", kFakeKeyTooShort, false)),
|
||||
PrintToStringParamName());
|
||||
|
||||
// TODO(jfore): The pssh has changed in ways that are not compatible with
|
||||
//sublicenses. Restructure or remove sublicense support including this test.
|
||||
TEST_F(SubLicenseTest, DISABLED_VerifySubSessionData) {
|
||||
|
||||
Reference in New Issue
Block a user