Source release v3.0.1 + third_party
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "cdm_test_printers.h"
|
||||
#include "license_request.h"
|
||||
#include "log.h"
|
||||
#include "OEMCryptoCENC.h"
|
||||
#include "override.h"
|
||||
#include "properties_ce.h"
|
||||
#include "scoped_ptr.h"
|
||||
@@ -103,6 +104,12 @@ const std::vector<uint8_t> kOutput1 = a2b_hex(
|
||||
"4884604c8da8a53ce33db9ff8f1c5bb6bb97f37b39906bf41596555c1bcce9ed"
|
||||
"08a899cd760ff0899a1170c2f224b9c52997a0785b7fe170805fd3e8b1127659");
|
||||
|
||||
const std::string kValue = "A Value";
|
||||
const std::string kNewValue = "A New Value";
|
||||
|
||||
const std::string kParamName = "PARAM";
|
||||
const std::string kParamName2 = "PARAM2";
|
||||
|
||||
|
||||
class CdmTest : public Test,
|
||||
public Cdm::IEventListener {
|
||||
@@ -423,6 +430,20 @@ TEST_F(CdmTest, Initialize) {
|
||||
}
|
||||
|
||||
TEST_F(CdmTest, DeviceCertificateRequest) {
|
||||
uint32_t nonce = 0;
|
||||
uint8_t buffer[1];
|
||||
size_t size = 0;
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_Initialize());
|
||||
int result = OEMCrypto_RewrapDeviceRSAKey(
|
||||
0, buffer, 0, buffer, 0, &nonce, buffer, 0, buffer, buffer, &size);
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_Terminate());
|
||||
if (result == OEMCrypto_ERROR_NOT_IMPLEMENTED) {
|
||||
LOGW("WARNING: Skipping DeviceCertificateRequest because the device does "
|
||||
"not support provisioning. If you are using a baked-in certificate, "
|
||||
"this is expected. Otherwise, something is wrong.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear any existing certificates.
|
||||
g_host->remove("cert.bin");
|
||||
|
||||
@@ -1075,4 +1096,84 @@ TEST_F(CdmTest, ServerCertificateProvisioning) {
|
||||
Mock::VerifyAndClear(this);
|
||||
}
|
||||
|
||||
TEST_F(CdmTest, SetAppParameters) {
|
||||
// Must use privacy_mode = false to ensure that the message is in plain-text.
|
||||
std::string session_id;
|
||||
ASSERT_NO_FATAL_FAILURE(RecreateCdm(false /* privacy_mode */));
|
||||
Cdm::Status status = cdm_->createSession(Cdm::kTemporary, &session_id);
|
||||
ASSERT_EQ(Cdm::kSuccess, status);
|
||||
|
||||
// Set a new app parameter, and check by getting.
|
||||
std::string result;
|
||||
status = cdm_->setAppParameter(kParamName, kValue);
|
||||
ASSERT_EQ(Cdm::kSuccess, status);
|
||||
status = cdm_->getAppParameter(kParamName, &result);
|
||||
ASSERT_EQ(Cdm::kSuccess, status);
|
||||
ASSERT_EQ(kValue, result);
|
||||
|
||||
// Try to get using a null result.
|
||||
status = cdm_->getAppParameter(kParamName, NULL);
|
||||
ASSERT_EQ(Cdm::kInvalidAccess, status);
|
||||
|
||||
// Try to get using an empty key.
|
||||
status = cdm_->getAppParameter("", &result);
|
||||
ASSERT_EQ(Cdm::kInvalidAccess, status);
|
||||
|
||||
// Try to set using an empty key.
|
||||
status = cdm_->setAppParameter("", kValue);
|
||||
ASSERT_EQ(Cdm::kInvalidAccess, status);
|
||||
|
||||
// Try to remove using an empty key.
|
||||
status = cdm_->removeAppParameter("");
|
||||
ASSERT_EQ(Cdm::kInvalidAccess, status);
|
||||
|
||||
// Change an existing app parameter.
|
||||
status = cdm_->setAppParameter(kParamName, kNewValue);
|
||||
ASSERT_EQ(Cdm::kSuccess, status);
|
||||
status = cdm_->getAppParameter(kParamName, &result);
|
||||
ASSERT_EQ(Cdm::kSuccess, status);
|
||||
ASSERT_EQ(kNewValue, result);
|
||||
|
||||
// Remove an existing app parameter, check for invalid access when it's gone.
|
||||
status = cdm_->removeAppParameter(kParamName);
|
||||
ASSERT_EQ(Cdm::kSuccess, status);
|
||||
status = cdm_->getAppParameter(kParamName, &result);
|
||||
ASSERT_EQ(Cdm::kInvalidAccess, status);
|
||||
|
||||
// Try to remove an absent value.
|
||||
status = cdm_->removeAppParameter(kParamName2);
|
||||
ASSERT_EQ(Cdm::kInvalidAccess, status);
|
||||
|
||||
// Set some values to check for.
|
||||
status = cdm_->setAppParameter(kParamName, kValue);
|
||||
ASSERT_EQ(Cdm::kSuccess, status);
|
||||
status = cdm_->setAppParameter(kParamName2, kNewValue);
|
||||
ASSERT_EQ(Cdm::kSuccess, status);
|
||||
|
||||
// Send a generate request to ensure the parameter is in the message.
|
||||
std::string message;
|
||||
EXPECT_CALL(*this, onMessage(session_id, Cdm::kLicenseRequest, _)).WillOnce(
|
||||
SaveArg<2>(&message));
|
||||
status = cdm_->generateRequest(session_id, Cdm::kCenc, kCencInitData);
|
||||
EXPECT_EQ(Cdm::kSuccess, status);
|
||||
EXPECT_TRUE(!message.empty() && message.find(kValue) != std::string::npos);
|
||||
Mock::VerifyAndClear(this);
|
||||
|
||||
// Ensure that the value is still present and correct.
|
||||
status = cdm_->getAppParameter(kParamName, &result);
|
||||
ASSERT_EQ(Cdm::kSuccess, status);
|
||||
ASSERT_EQ(kValue, result);
|
||||
status = cdm_->getAppParameter(kParamName2, &result);
|
||||
ASSERT_EQ(Cdm::kSuccess, status);
|
||||
ASSERT_EQ(kNewValue, result);
|
||||
|
||||
// Clear all the parameters.
|
||||
status = cdm_->clearAppParameters();
|
||||
ASSERT_EQ(Cdm::kSuccess, status);
|
||||
status = cdm_->getAppParameter(kParamName, &result);
|
||||
ASSERT_EQ(Cdm::kInvalidAccess, status);
|
||||
status = cdm_->getAppParameter(kParamName2, &result);
|
||||
ASSERT_EQ(Cdm::kInvalidAccess, status);
|
||||
}
|
||||
|
||||
} // namespace widevine
|
||||
|
||||
Reference in New Issue
Block a user