From bfde8267636048c31f8151861c0dea37ac50126c Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Fri, 6 Mar 2020 15:55:24 -0800 Subject: [PATCH] Unit test for OEMCrypto_LoadUsageEntry in multiple sessions Merge from Widevine repo of http://go/wvgerrit/95283 If an entry is loaded in a second session, the error should be OEMCrypto_ERROR_INVALID_SESSION. Bug: 150647218 Test: ran unit tests Change-Id: I4e666ce6626303a36b16997f0a012d57a7039697 Change-Id: Id0e73dec5879ec9ec4e8ab8ebe1590c568e7f0af --- .../oemcrypto/test/oemcrypto_test.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index e8649e2b..1cd58a3a 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -5178,6 +5178,32 @@ TEST_P(OEMCryptoUsageTableTest, CreateAndLoadMultipleEntriesAPI16) { OEMCrypto_CreateNewUsageEntry(s2.session_id(), &usage_entry_number)); } +// An entry can be loaded in only one session at a time. +TEST_P(OEMCryptoUsageTableTest, LoadEntryInMultipleSessions) { + // Entry Count: we start each test with an empty header. + LicenseWithUsageEntry entry; + entry.license_messages().set_api_version(license_api_version_); + Session& s = entry.session(); + // Make first entry 0. + ASSERT_NO_FATAL_FAILURE(entry.MakeOfflineAndClose(this)); + const uint32_t usage_entry_number = s.usage_entry_number(); + EXPECT_EQ(usage_entry_number, 0u); // Should be only entry in this test. + + // Load an entry, then try to create a second. + ASSERT_NO_FATAL_FAILURE(s.open()); + // Reload entry 0. + ASSERT_NO_FATAL_FAILURE(s.ReloadUsageEntry()); + + // Create an entry, then try to load a second. + Session s2; + ASSERT_NO_FATAL_FAILURE(s2.open()); + // Try to load entry 0 into session 2. + ASSERT_EQ(OEMCrypto_ERROR_INVALID_SESSION, + OEMCrypto_LoadUsageEntry(s2.session_id(), usage_entry_number, + s.encrypted_usage_entry().data(), + s.encrypted_usage_entry().size())); +} + // Test generic encrypt when the license uses a PST. TEST_P(OEMCryptoUsageTableTest, GenericCryptoEncrypt) { LicenseWithUsageEntry entry;