From eb846100d452f975568603b39ae81c3e2a4da164 Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Wed, 13 Oct 2021 21:04:09 +0000 Subject: [PATCH] Update OTA Keybox tests Merge from Widevine repo of http://go/wvgerrit/135982 The basic test was failing when using the testbed oemcrypto because the testbed deletes its keybox on each initialization. The test would terminate and re-initialize oemcrypto whenever all the crypto sessions are deleted. This has been fixed by holding a crypto session alive until the end of the test. bug: 187646550 Test: test only code Merged-In: I48a3771bf5fd4aae8d262b8c7bf42f004d9b9f4c Change-Id: I48a3771bf5fd4aae8d262b8c7bf42f004d9b9f4c --- .../cdm/core/test/keybox_ota_test.cpp | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/libwvdrmengine/cdm/core/test/keybox_ota_test.cpp b/libwvdrmengine/cdm/core/test/keybox_ota_test.cpp index 36dd09a9..44b5c81b 100644 --- a/libwvdrmengine/cdm/core/test/keybox_ota_test.cpp +++ b/libwvdrmengine/cdm/core/test/keybox_ota_test.cpp @@ -82,6 +82,27 @@ TEST_F(CdmOtaKeyboxTest, BasicTest) { FileSystem file_system; TestCdmEngine cdm_engine(&file_system, std::shared_ptr(new EngineMetrics)); + // Create a singleton crypto session to prevent OEMCrypto from being + // terminated. This is really only needed when running the test against the + // testbed OEMCrypto which does not save its keybox across init/terminate. + metrics::CryptoMetrics crypto_metrics; + std::unique_ptr crypto_session( + CryptoSession::MakeCryptoSession(&crypto_metrics)); + // Remove any existing certificate. + cdm_engine.Unprovision(kSecurityLevelL1); + std::string system_id; + CdmResponseType system_id_status = + cdm_engine.QueryStatus(kLevelDefault, QUERY_KEY_SYSTEM_ID, &system_id); + if (system_id_status == NO_ERROR) { + std::cout << " " + << "System ID before test: " << system_id << "\n"; + } else { + std::cout << " " + << "Could not find system id before test. "; + PrintTo(system_id_status, &std::cout); + std::cout << "\n"; + } + CdmSessionId session_id; ConfigTestEnv config = WvCdmTestBase::default_config_; @@ -97,6 +118,17 @@ TEST_F(CdmOtaKeyboxTest, BasicTest) { } std::cout << "First provisioning process.\n"; Provision(&cdm_engine); + system_id_status = + cdm_engine.QueryStatus(kLevelDefault, QUERY_KEY_SYSTEM_ID, &system_id); + if (system_id_status == NO_ERROR) { + std::cout << " " + << "System ID after first provisioning: " << system_id << "\n"; + } else { + std::cout << " " + << "Could not find system id after first provisioning. "; + PrintTo(system_id_status, &std::cout); + std::cout << "\n"; + } // After the first provisioning pass, we try to open a session again. If the // first provisioning was to install a keybox, this provisioning should be to @@ -111,6 +143,17 @@ TEST_F(CdmOtaKeyboxTest, BasicTest) { } std::cout << "Second provisioning process.\n"; Provision(&cdm_engine); + system_id_status = + cdm_engine.QueryStatus(kLevelDefault, QUERY_KEY_SYSTEM_ID, &system_id); + if (system_id_status == NO_ERROR) { + std::cout << " " + << "System ID after second provisioning: " << system_id << "\n"; + } else { + std::cout << " " + << "Could not find system id after second provisioning. "; + PrintTo(system_id_status, &std::cout); + std::cout << "\n"; + } // After the second provisioning pass, we should be able to open a session // and continue.