Removed provisioning loop in unittests.
[ Merge of http://go/wvgerrit/98467 ] The issue with intermediate provisioning request failures with the development provisioning server has been resolved in b/139206968. This change removes the provisioning retry loop which was a workaround for the CDM unit tests. Should the issue re-arise, it would be useful to detect it in our unit tests. Bug: 139361531 Test: Linux unit tests Change-Id: Ib44c56c740efea562803d3f8f93ffd62bd95e485
This commit is contained in:
@@ -329,84 +329,52 @@ void WvCdmTestBase::Provision() {
|
||||
// for test vs. production server.
|
||||
provisioning_server_url.assign(config_.provisioning_server());
|
||||
|
||||
// TODO(b/139361531): Remove loop once provisioning service is stable.
|
||||
std::string http_message;
|
||||
size_t attempt_num = 0;
|
||||
bool provision_success = false;
|
||||
do {
|
||||
if (attempt_num > 0) {
|
||||
// Sleep between attempts.
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
++attempt_num;
|
||||
|
||||
// Make request.
|
||||
UrlRequest url_request(provisioning_server_url);
|
||||
if (!url_request.is_connected()) {
|
||||
LOGE("Failed to connect to provisioning server: url = %s",
|
||||
provisioning_server_url.c_str());
|
||||
continue;
|
||||
}
|
||||
url_request.PostCertRequestInQueryString(prov_request);
|
||||
|
||||
// Receive and parse response.
|
||||
if (!url_request.GetResponse(&http_message)) {
|
||||
LOGE("Failed to get provisioning response");
|
||||
continue;
|
||||
}
|
||||
|
||||
LOGV("http_message: \n%s\n", http_message.c_str());
|
||||
|
||||
if (binary_provisioning_) {
|
||||
// extract provisioning response from received message
|
||||
// Extracts signed response from JSON string, result is serialized
|
||||
// protobuf.
|
||||
static const std::string kMessageStart = "\"signedResponse\": \"";
|
||||
static const std::string kMessageEnd = "\"";
|
||||
std::string protobuf_response;
|
||||
if (!ExtractSignedMessage(http_message, kMessageStart, kMessageEnd,
|
||||
&protobuf_response)) {
|
||||
LOGE(
|
||||
"Failed to extract signed serialized response from JSON "
|
||||
"response");
|
||||
continue;
|
||||
}
|
||||
|
||||
LOGV("Extracted response message: \n%s\n", protobuf_response.c_str());
|
||||
|
||||
// base64 decode response to yield binary protobuf
|
||||
std::vector<uint8_t> response_vec(Base64SafeDecode(protobuf_response));
|
||||
if (response_vec.empty() && !protobuf_response.empty()) {
|
||||
LOGE("Failed to decode base64 of response: response = %s",
|
||||
protobuf_response.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string binary_protobuf_response(response_vec.begin(),
|
||||
response_vec.end());
|
||||
|
||||
if (cdm_engine.HandleProvisioningResponse(
|
||||
binary_protobuf_response, &cert, &wrapped_key) != NO_ERROR) {
|
||||
LOGE("Failed to handle provisioning response");
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (cdm_engine.HandleProvisioningResponse(http_message, &cert,
|
||||
&wrapped_key) != NO_ERROR) {
|
||||
LOGE("Failed to handle binary provisioning response");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
provision_success = true;
|
||||
} while (attempt_num <= kDefaultMaxProvisioningAttempts &&
|
||||
!provision_success);
|
||||
|
||||
if (attempt_num > 1) {
|
||||
LOGW("Provisioning request failed at least once: attempts = %zu",
|
||||
attempt_num);
|
||||
// Make request.
|
||||
UrlRequest url_request(provisioning_server_url);
|
||||
if (!url_request.is_connected()) {
|
||||
LOGE("Failed to connect to provisioning server: url = %s",
|
||||
provisioning_server_url.c_str());
|
||||
}
|
||||
url_request.PostCertRequestInQueryString(prov_request);
|
||||
|
||||
// Receive and parse response.
|
||||
std::string http_message;
|
||||
ASSERT_TRUE(url_request.GetResponse(&http_message))
|
||||
<< "Failed to get provisioning response";
|
||||
LOGV("http_message: \n%s\n", http_message.c_str());
|
||||
|
||||
if (binary_provisioning_) {
|
||||
// extract provisioning response from received message
|
||||
// Extracts signed response from JSON string, result is serialized
|
||||
// protobuf.
|
||||
static const std::string kMessageStart = "\"signedResponse\": \"";
|
||||
static const std::string kMessageEnd = "\"";
|
||||
std::string protobuf_response;
|
||||
const bool extract_ok = ExtractSignedMessage(
|
||||
http_message, kMessageStart, kMessageEnd, &protobuf_response);
|
||||
ASSERT_TRUE(extract_ok) << "Failed to extract signed serialized "
|
||||
"response from JSON response";
|
||||
LOGV("Extracted response message: \n%s\n", protobuf_response.c_str());
|
||||
|
||||
ASSERT_FALSE(protobuf_response.empty())
|
||||
<< "Protobuf response is unexpectedly empty";
|
||||
|
||||
// base64 decode response to yield binary protobuf
|
||||
const std::vector<uint8_t> response_vec(
|
||||
Base64SafeDecode(protobuf_response));
|
||||
ASSERT_FALSE(response_vec.empty())
|
||||
<< "Failed to decode base64 of response: response = "
|
||||
<< protobuf_response;
|
||||
|
||||
const std::string binary_protobuf_response(response_vec.begin(),
|
||||
response_vec.end());
|
||||
|
||||
ASSERT_EQ(NO_ERROR, cdm_engine.HandleProvisioningResponse(
|
||||
binary_protobuf_response, &cert, &wrapped_key));
|
||||
} else {
|
||||
ASSERT_EQ(NO_ERROR, cdm_engine.HandleProvisioningResponse(
|
||||
http_message, &cert, &wrapped_key));
|
||||
}
|
||||
ASSERT_TRUE(provision_success)
|
||||
<< "Failed to provision: message = " << http_message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,6 @@ namespace wvcdm {
|
||||
// to configure OEMCrypto to use a test keybox.
|
||||
class WvCdmTestBase : public ::testing::Test {
|
||||
public:
|
||||
// Default number of provisioning try attempts.
|
||||
constexpr static size_t kDefaultMaxProvisioningAttempts = 10;
|
||||
|
||||
WvCdmTestBase();
|
||||
~WvCdmTestBase() override {}
|
||||
void SetUp() override;
|
||||
|
||||
Reference in New Issue
Block a user