Allow ProvisioningHolder to return load status.
[ Merge of http://go/wvgerrit/219452 ] Allow ProvisioningHolder to load the a provisioning response without triggering test failure if the CDM rejects the response. This is to allow testing cases where we expect the CDM to reject the response. VIC-specific: No specialized provisioning dump call. Bug: 391469176 Change-Id: Ief1791f23035fe9b554f8e82e049343aa7e97362
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "cdm_engine.h"
|
||||
#include "config_test_env.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "message_dumper.h"
|
||||
@@ -130,6 +129,49 @@ void ProvisioningHolder::LoadResponse(bool binary_provisioning) {
|
||||
}
|
||||
}
|
||||
|
||||
CdmResponseType ProvisioningHolder::LoadResponseReturnStatus(
|
||||
bool binary_provisioning) {
|
||||
// Preconditions.
|
||||
if (response_.empty()) {
|
||||
ADD_FAILURE() << "No response was fetched";
|
||||
return CdmResponseType(UNKNOWN_ERROR);
|
||||
}
|
||||
|
||||
std::string cdm_prov_response;
|
||||
if (binary_provisioning) {
|
||||
// CDM is expecting the response to be in binary form, response
|
||||
// must be extracted and decoded.
|
||||
std::string base_64_response;
|
||||
if (!ExtractSignedMessage(response_, &base_64_response)) {
|
||||
ADD_FAILURE()
|
||||
<< "Failed to extract signed serialized response from JSON response";
|
||||
return CdmResponseType(UNKNOWN_ERROR);
|
||||
}
|
||||
if (base_64_response.empty()) {
|
||||
ADD_FAILURE()
|
||||
<< "Base64 encoded provisioning response is unexpectedly empty";
|
||||
return CdmResponseType(UNKNOWN_ERROR);
|
||||
}
|
||||
LOGV("Extracted response message: \n%s\n", base_64_response.c_str());
|
||||
|
||||
const std::vector<uint8_t> response_vec =
|
||||
wvutil::Base64SafeDecode(base_64_response);
|
||||
if (response_vec.empty()) {
|
||||
ADD_FAILURE() << "Failed to decode base64 response: " << base_64_response;
|
||||
return CdmResponseType(UNKNOWN_ERROR);
|
||||
}
|
||||
cdm_prov_response.assign(response_vec.begin(), response_vec.end());
|
||||
} else {
|
||||
cdm_prov_response = response_;
|
||||
}
|
||||
// HandleProvisioningResponse() may or may not succeed,
|
||||
// left to caller to determine if this is considered a
|
||||
// test failure.
|
||||
const CdmResponseType status = cdm_engine_->HandleProvisioningResponse(
|
||||
cdm_prov_response, kLevelDefault, &certificate_, &wrapped_key_);
|
||||
return status;
|
||||
}
|
||||
|
||||
bool ProvisioningHolder::ExtractSignedMessage(const std::string& response,
|
||||
std::string* result) {
|
||||
static const std::string kMessageStart = "\"signedResponse\": \"";
|
||||
|
||||
@@ -40,7 +40,11 @@ class ProvisioningHolder {
|
||||
// JSON message of the response to |response_|.
|
||||
void FetchResponse();
|
||||
|
||||
// Loads the response into the |cdm_engine_|, expecting success.
|
||||
void LoadResponse(bool binary_provisioning);
|
||||
// Loads the response into the |cdm_engine_|, returning the
|
||||
// result from CDM.
|
||||
CdmResponseType LoadResponseReturnStatus(bool binary_provisioning);
|
||||
|
||||
const std::string& request() const { return request_; }
|
||||
// Sets the request to be used on next call to FetchResponse().
|
||||
|
||||
Reference in New Issue
Block a user