Android CDM: Restored secure stop tests.
[ Semi-revert of http://ag/20183443 ] [ Merge of http://go/wvgerrit/168898 ] These tests were removed from Android last quarter; however, they now need to be restored. These tests will be removed in Android V. To help with ambiguity around where the CDM is operating on a single or set of usage info messages, the variables have been renamed to propery indicate plurality. Bug: 263319220 Test: cdm_extended_duration_test Test: request_license_test Test: libwvdrmdrmplugin_hal_test Change-Id: I38b16dd5811069fafaeab5ffc19d0f8a8095f0cf
This commit is contained in:
@@ -5,8 +5,6 @@
|
||||
//
|
||||
// #define LOG_NDEBUG 0
|
||||
#define LOG_TAG "WVDrmPluginHalTest"
|
||||
#include "WVDrmPlugin.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
@@ -15,16 +13,18 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "WVDrmPlugin.h"
|
||||
#include "WVErrors.h"
|
||||
#include "cdm_client_property_set.h"
|
||||
#include "cdm_random.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "media/stagefright/MediaErrors.h"
|
||||
#include "media/stagefright/foundation/ABase.h"
|
||||
#include "string_conversions.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
#include "wv_cdm_types.h"
|
||||
#include "wv_content_decryption_module.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
typedef std::vector<::aidl::android::hardware::drm::KeyValue> KeyedVector;
|
||||
@@ -47,6 +47,8 @@ using ::aidl::android::hardware::drm::KeyValue;
|
||||
using ::aidl::android::hardware::drm::OfflineLicenseState;
|
||||
using ::aidl::android::hardware::drm::ProvideProvisionResponseResult;
|
||||
using ::aidl::android::hardware::drm::ProvisionRequest;
|
||||
using ::aidl::android::hardware::drm::SecureStop;
|
||||
using ::aidl::android::hardware::drm::SecureStopId;
|
||||
using ::aidl::android::hardware::drm::SecurityLevel;
|
||||
using ::aidl::android::hardware::drm::Status;
|
||||
|
||||
@@ -54,6 +56,7 @@ using ::testing::_;
|
||||
using ::testing::AllOf;
|
||||
using ::testing::Args;
|
||||
using ::testing::AtLeast;
|
||||
using ::testing::Contains;
|
||||
using ::testing::DefaultValue;
|
||||
using ::testing::DoAll;
|
||||
using ::testing::ElementsAreArray;
|
||||
@@ -89,7 +92,10 @@ using wvcdm::CdmOfflineLicenseState;
|
||||
using wvcdm::CdmProvisioningRequest;
|
||||
using wvcdm::CdmProvisioningResponse;
|
||||
using wvcdm::CdmQueryMap;
|
||||
using wvcdm::CdmSecureStopId;
|
||||
using wvcdm::CdmSecurityLevel;
|
||||
using wvcdm::CdmUsageReport;
|
||||
using wvcdm::CdmUsageReportList;
|
||||
using wvcdm::EMPTY_ORIGIN;
|
||||
using wvcdm::kCertificateWidevine;
|
||||
using wvcdm::KEY_ID_SIZE;
|
||||
@@ -133,6 +139,7 @@ using wvcdm::QUERY_VALUE_SECURITY_LEVEL_L3;
|
||||
using wvcdm::SESSION_ID_PREFIX;
|
||||
using wvcdm::WvCdmEventListener;
|
||||
using wvutil::Base64Encode;
|
||||
using wvutil::CdmRandom;
|
||||
|
||||
namespace {
|
||||
const std::string kEmptyString;
|
||||
@@ -157,93 +164,107 @@ const char kSerializedMetricsHex[] =
|
||||
"0";
|
||||
|
||||
#define N_ELEM(a) (sizeof(a) / sizeof(a[0]))
|
||||
} // anonymous namespace
|
||||
|
||||
class MockCDM : public WvContentDecryptionModule {
|
||||
public:
|
||||
MOCK_METHOD(CdmResponseType, OpenSession,
|
||||
(const CdmKeySystem &, CdmClientPropertySet *,
|
||||
const CdmIdentifier &, WvCdmEventListener *, CdmSessionId *),
|
||||
(override));
|
||||
public:
|
||||
virtual ~MockCDM() {}
|
||||
|
||||
MOCK_METHOD(CdmResponseType, CloseSession, (const CdmSessionId &),
|
||||
(override));
|
||||
MOCK_METHOD(CdmResponseType, OpenSession,
|
||||
(const CdmKeySystem &, CdmClientPropertySet *,
|
||||
const CdmIdentifier &, WvCdmEventListener *, CdmSessionId *),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, GenerateKeyRequest,
|
||||
(const CdmSessionId &, const CdmKeySetId &, const std::string &,
|
||||
const CdmInitData &, const CdmLicenseType, CdmAppParameterMap &,
|
||||
CdmClientPropertySet *, const CdmIdentifier &, CdmKeyRequest *),
|
||||
(override));
|
||||
MOCK_METHOD(CdmResponseType, CloseSession, (const CdmSessionId &), (override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, AddKey,
|
||||
(const CdmSessionId &, const CdmKeyResponse &, CdmKeySetId *),
|
||||
(override));
|
||||
MOCK_METHOD(CdmResponseType, GenerateKeyRequest,
|
||||
(const CdmSessionId &, const CdmKeySetId &, const std::string &,
|
||||
const CdmInitData &, const CdmLicenseType, CdmAppParameterMap &,
|
||||
CdmClientPropertySet *, const CdmIdentifier &, CdmKeyRequest *),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, RemoveKeys, (const CdmSessionId &), (override));
|
||||
MOCK_METHOD(CdmResponseType, AddKey,
|
||||
(const CdmSessionId &, const CdmKeyResponse &, CdmKeySetId *),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, RestoreKey,
|
||||
(const CdmSessionId &, const CdmKeySetId &), (override));
|
||||
MOCK_METHOD(CdmResponseType, RemoveKeys, (const CdmSessionId &), (override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, QueryStatus,
|
||||
(wvcdm::RequestedSecurityLevel, const std::string &,
|
||||
std::string *),
|
||||
(override));
|
||||
MOCK_METHOD(CdmResponseType, RestoreKey,
|
||||
(const CdmSessionId &, const CdmKeySetId &), (override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, QuerySessionStatus,
|
||||
(const CdmSessionId &, CdmQueryMap *), (override));
|
||||
MOCK_METHOD(CdmResponseType, QueryStatus,
|
||||
(wvcdm::RequestedSecurityLevel, const std::string &,
|
||||
std::string *),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, QueryKeyStatus,
|
||||
(const CdmSessionId &, CdmQueryMap *), (override));
|
||||
MOCK_METHOD(CdmResponseType, QuerySessionStatus,
|
||||
(const CdmSessionId &, CdmQueryMap *), (override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, QueryOemCryptoSessionId,
|
||||
(const CdmSessionId &, CdmQueryMap *), (override));
|
||||
MOCK_METHOD(CdmResponseType, QueryKeyStatus,
|
||||
(const CdmSessionId &, CdmQueryMap *), (override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, GetProvisioningRequest,
|
||||
(CdmCertificateType, const std::string &, const CdmIdentifier &,
|
||||
const std::string &, wvcdm::RequestedSecurityLevel,
|
||||
CdmProvisioningRequest *, std::string *),
|
||||
(override));
|
||||
MOCK_METHOD(CdmResponseType, QueryOemCryptoSessionId,
|
||||
(const CdmSessionId &, CdmQueryMap *), (override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, HandleProvisioningResponse,
|
||||
(const CdmIdentifier &, const CdmProvisioningResponse &,
|
||||
wvcdm::RequestedSecurityLevel, std::string *, std::string *),
|
||||
(override));
|
||||
MOCK_METHOD(CdmResponseType, GetProvisioningRequest,
|
||||
(CdmCertificateType, const std::string &, const CdmIdentifier &,
|
||||
const std::string &, wvcdm::RequestedSecurityLevel,
|
||||
CdmProvisioningRequest *, std::string *),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, Unprovision,
|
||||
(CdmSecurityLevel, const CdmIdentifier &), (override));
|
||||
MOCK_METHOD(CdmResponseType, HandleProvisioningResponse,
|
||||
(const CdmIdentifier &, const CdmProvisioningResponse &,
|
||||
wvcdm::RequestedSecurityLevel, std::string *, std::string *),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(bool, IsProvisioned,
|
||||
(CdmSecurityLevel, const std::string &, const std::string &,
|
||||
bool),
|
||||
(override));
|
||||
MOCK_METHOD(CdmResponseType, Unprovision,
|
||||
(CdmSecurityLevel, const CdmIdentifier &), (override));
|
||||
|
||||
MOCK_METHOD(bool, IsValidServiceCertificate, (const std::string &),
|
||||
(override));
|
||||
MOCK_METHOD(bool, IsProvisioned,
|
||||
(CdmSecurityLevel, const std::string &, const std::string &, bool),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, GetMetrics,
|
||||
(const CdmIdentifier &, drm_metrics::WvCdmMetrics *), (override));
|
||||
MOCK_METHOD(CdmResponseType, GetUsageInfo,
|
||||
(const std::string &, const CdmIdentifier &, CdmUsageReportList *),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, GetDecryptHashError,
|
||||
(const CdmSessionId &, std::string *), (override));
|
||||
MOCK_METHOD(CdmResponseType, GetUsageInfo,
|
||||
(const std::string &, const CdmSecureStopId &,
|
||||
const CdmIdentifier &, CdmUsageReport *),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, ListStoredLicenses,
|
||||
(CdmSecurityLevel, const CdmIdentifier &,
|
||||
std::vector<std::string> *),
|
||||
(override));
|
||||
MOCK_METHOD(CdmResponseType, RemoveAllUsageInfo,
|
||||
(const std::string &, const CdmIdentifier &), (override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, GetOfflineLicenseState,
|
||||
(const std::string &, CdmSecurityLevel, const CdmIdentifier &,
|
||||
CdmOfflineLicenseState *),
|
||||
(override));
|
||||
MOCK_METHOD(CdmResponseType, ReleaseUsageInfo,
|
||||
(const CdmKeyResponse &, const CdmIdentifier &), (override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, RemoveOfflineLicense,
|
||||
(const std::string &, CdmSecurityLevel, const CdmIdentifier &),
|
||||
(override));
|
||||
MOCK_METHOD(bool, IsValidServiceCertificate, (const std::string &),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, StoreAtscLicense,
|
||||
(const CdmIdentifier &, wvcdm::RequestedSecurityLevel,
|
||||
const std::string &, const std::string &),
|
||||
(override));
|
||||
MOCK_METHOD(CdmResponseType, GetMetrics,
|
||||
(const CdmIdentifier &, drm_metrics::WvCdmMetrics *), (override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, GetDecryptHashError,
|
||||
(const CdmSessionId &, std::string *), (override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, ListStoredLicenses,
|
||||
(CdmSecurityLevel, const CdmIdentifier &,
|
||||
std::vector<std::string> *),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, GetOfflineLicenseState,
|
||||
(const std::string &, CdmSecurityLevel, const CdmIdentifier &,
|
||||
CdmOfflineLicenseState *),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, RemoveOfflineLicense,
|
||||
(const std::string &, CdmSecurityLevel, const CdmIdentifier &),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(CdmResponseType, StoreAtscLicense,
|
||||
(const CdmIdentifier &, wvcdm::RequestedSecurityLevel,
|
||||
const std::string &, const std::string &),
|
||||
(override));
|
||||
};
|
||||
|
||||
class MockCrypto : public WVGenericCryptoInterface {
|
||||
@@ -280,6 +301,8 @@ public:
|
||||
(override));
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
template <uint8_t DIGIT>
|
||||
CdmResponseType setSessionIdOnMap(testing::Unused, CdmQueryMap *map) {
|
||||
static const char oecId[] = {DIGIT + '0', '\0'};
|
||||
@@ -968,6 +991,62 @@ TEST_F(WVDrmPluginHalTest, RejectsAtscUnprovisionDeviceRequests) {
|
||||
ASSERT_EQ(Status::ERROR_DRM_CANNOT_HANDLE, status);
|
||||
}
|
||||
|
||||
TEST_F(WVDrmPluginHalTest, GetsSecureStops) {
|
||||
static constexpr uint32_t kStopSize = 53;
|
||||
static constexpr uint32_t kStopCount = 7;
|
||||
|
||||
CdmUsageReportList fakeSecureStops;
|
||||
for (uint32_t i = 0; i < kStopCount; ++i) {
|
||||
fakeSecureStops.push_back(CdmRandom::RandomData(kStopSize));
|
||||
}
|
||||
|
||||
const std::string app_id = "my_app_id";
|
||||
EXPECT_CALL(*mCdm, GetUsageInfo(app_id, _, _))
|
||||
.WillOnce(DoAll(SetArgPointee<2>(fakeSecureStops),
|
||||
testing::Return(CdmResponseType(wvcdm::NO_ERROR))));
|
||||
|
||||
auto ret = mPlugin->setPropertyString("appId", app_id);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
|
||||
std::vector<SecureStop> secureStops;
|
||||
ret = mPlugin->getSecureStops(&secureStops);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
|
||||
CdmUsageReportList stops;
|
||||
for (const auto &stop : secureStops) {
|
||||
stops.emplace_back(stop.opaqueData.begin(), stop.opaqueData.end());
|
||||
}
|
||||
|
||||
EXPECT_EQ(kStopCount, stops.size());
|
||||
|
||||
for (const CdmUsageReport &expectedSecureStop : fakeSecureStops) {
|
||||
EXPECT_THAT(stops, Contains(expectedSecureStop));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(WVDrmPluginHalTest, ReleasesAllSecureStops) {
|
||||
const std::string app_id = "";
|
||||
EXPECT_CALL(*mCdm, RemoveAllUsageInfo(app_id, _)).Times(1);
|
||||
|
||||
auto ret = mPlugin->setPropertyString("appId", app_id);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
|
||||
ret = mPlugin->releaseAllSecureStops();
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
TEST_F(WVDrmPluginHalTest, ReleasesSecureStop) {
|
||||
static constexpr uint32_t kMessageSize = 128;
|
||||
const CdmKeyResponse releaseMessage = CdmRandom::RandomData(kMessageSize);
|
||||
|
||||
EXPECT_CALL(*mCdm, ReleaseUsageInfo(releaseMessage, _)).Times(1);
|
||||
|
||||
SecureStopId stopId;
|
||||
stopId.secureStopId.assign(releaseMessage.begin(), releaseMessage.end());
|
||||
auto ret = mPlugin->releaseSecureStop(stopId);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
TEST_F(WVDrmPluginHalTest, ReturnsExpectedPropertyValues) {
|
||||
CdmQueryMap l1Map;
|
||||
l1Map[QUERY_KEY_SECURITY_LEVEL] = QUERY_VALUE_SECURITY_LEVEL_L1;
|
||||
|
||||
Reference in New Issue
Block a user