Unit test for kInactiveUnused usage reports
Merge from Widevine repo of http://go/wvgerrit/50422 This CL adds unit tests to verify that a usage report can have the status kInactiveUnused. bug: 79556142 test: unit test code only Change-Id: I10f71ac2e585ef33727aa8f80d867d80fe156ab8
This commit is contained in:
@@ -4531,6 +4531,30 @@ TEST_P(UsageTableTestWithMAC, OnlineLicense) {
|
||||
s.TestDecryptCTR(false, OEMCrypto_ERROR_UNKNOWN_FAILURE));
|
||||
}
|
||||
|
||||
TEST_P(UsageTableTestWithMAC, OnlineLicenseUnused) {
|
||||
std::string pst = "my_pst";
|
||||
Session s;
|
||||
ASSERT_NO_FATAL_FAILURE(s.open());
|
||||
ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s));
|
||||
ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage(
|
||||
0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired,
|
||||
s.get_nonce(), pst));
|
||||
ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign());
|
||||
ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry());
|
||||
ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys(pst, new_mac_keys_));
|
||||
ASSERT_NO_FATAL_FAILURE(s.UpdateUsageEntry(&encrypted_usage_header_));
|
||||
// No decrypt. We do not use this license.
|
||||
ASSERT_NO_FATAL_FAILURE(s.GenerateVerifyReport(pst, kUnused));
|
||||
// Flag the entry as inactive.
|
||||
ASSERT_NO_FATAL_FAILURE(s.DeactivateUsageEntry(pst));
|
||||
ASSERT_NO_FATAL_FAILURE(s.UpdateUsageEntry(&encrypted_usage_header_));
|
||||
// It should report as inactive.
|
||||
ASSERT_NO_FATAL_FAILURE(s.GenerateVerifyReport(pst, kInactiveUnused));
|
||||
// Decrypt should fail.
|
||||
ASSERT_NO_FATAL_FAILURE(
|
||||
s.TestDecryptCTR(false, OEMCrypto_ERROR_UNKNOWN_FAILURE));
|
||||
}
|
||||
|
||||
TEST_P(UsageTableTestWithMAC, ForbidReportWithNoUpdate) {
|
||||
std::string pst = "my_pst";
|
||||
Session s;
|
||||
@@ -5125,6 +5149,49 @@ TEST_P(UsageTableTestWithMAC, DeactivateOfflineLicense) {
|
||||
EXPECT_EQ(kInactiveUsed, s3.pst_report().status());
|
||||
}
|
||||
|
||||
TEST_P(UsageTableTestWithMAC, DeactivateOfflineLicenseUnused) {
|
||||
std::string pst = "my_pst";
|
||||
Session s1;
|
||||
ASSERT_NO_FATAL_FAILURE(LoadOfflineLicense(s1, pst));
|
||||
|
||||
ASSERT_NO_FATAL_FAILURE(s1.open());
|
||||
ASSERT_NO_FATAL_FAILURE(s1.ReloadUsageEntry());
|
||||
ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s1));
|
||||
ASSERT_NO_FATAL_FAILURE(
|
||||
s1.LoadTestKeys(pst, new_mac_keys_)); // Reload the license
|
||||
// No Decrypt. This license is unused.
|
||||
ASSERT_NO_FATAL_FAILURE(s1.DeactivateUsageEntry(pst)); // Then deactivate.
|
||||
// After deactivate, should not be able to decrypt.
|
||||
ASSERT_NO_FATAL_FAILURE(
|
||||
s1.TestDecryptCTR(false, OEMCrypto_ERROR_UNKNOWN_FAILURE));
|
||||
ASSERT_NO_FATAL_FAILURE(s1.UpdateUsageEntry(&encrypted_usage_header_));
|
||||
ASSERT_NO_FATAL_FAILURE(s1.GenerateVerifyReport(pst, kInactiveUnused));
|
||||
ASSERT_NO_FATAL_FAILURE(s1.close());
|
||||
|
||||
Session s2;
|
||||
ASSERT_NO_FATAL_FAILURE(s2.open());
|
||||
ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s2));
|
||||
ASSERT_NO_FATAL_FAILURE(s2.LoadUsageEntry(s1));
|
||||
// Offline license can not be reused if it has been deactivated.
|
||||
uint8_t* pst_ptr = s1.encrypted_license().pst;
|
||||
EXPECT_NE(
|
||||
OEMCrypto_SUCCESS,
|
||||
OEMCrypto_LoadKeys(s2.session_id(), s1.message_ptr(), s1.message_size(),
|
||||
&s1.signature()[0], s1.signature().size(),
|
||||
s1.encrypted_license().mac_key_iv,
|
||||
s1.encrypted_license().mac_keys, s1.num_keys(),
|
||||
s1.key_array(), pst_ptr, pst.length(), NULL,
|
||||
OEMCrypto_ContentLicense));
|
||||
s2.close();
|
||||
// But we can still generate a report.
|
||||
Session s3;
|
||||
ASSERT_NO_FATAL_FAILURE(s3.open());
|
||||
ASSERT_NO_FATAL_FAILURE(s3.LoadUsageEntry(s1));
|
||||
ASSERT_NO_FATAL_FAILURE(s3.UpdateUsageEntry(&encrypted_usage_header_));
|
||||
ASSERT_NO_FATAL_FAILURE(s3.GenerateReport(pst, OEMCrypto_SUCCESS, &s1));
|
||||
EXPECT_EQ(kInactiveUnused, s3.pst_report().status());
|
||||
}
|
||||
|
||||
TEST_P(UsageTableTestWithMAC, BadRange) {
|
||||
std::string pst = "my_pst";
|
||||
Session s;
|
||||
|
||||
Reference in New Issue
Block a user