Add error details when offline license is not found

[ Merge of http://go/wvgerrit/171310 ]

Offline license not found errors are identified by CdmResponseEnum
347 (KEYSET_ID_NOT_FOUND_4). No addition file system information
is shared.

Checks for file existance use the stat command. The stat call can
return error codes from errno.h when the command fails.
These are now converted into sub error codes and returned along with
the offline license file not found error.

This also includes a change to log stat errors other than
ENOENT (no such file or directory) as a warning rather than verbose.

Bug: 276225520
Test: file_store_unittest, file_utils_unittest, GtsMediaTestCases
Change-Id: Ic09d036549582cd65783b49fa96ffefc4bf562c7
This commit is contained in:
Rahul Frias
2023-04-23 18:47:43 -07:00
parent 5409567ef9
commit 9d1c9ca76a
10 changed files with 183 additions and 38 deletions

View File

@@ -4432,6 +4432,7 @@ class MockFileSystem : public wvutil::FileSystem {
MOCK_METHOD(std::unique_ptr<File>, Open, (const std::string&, int flags),
(override));
MOCK_METHOD(bool, Exists, (const std::string&), (override));
MOCK_METHOD(bool, Exists, (const std::string&, int*), (override));
MOCK_METHOD(bool, Remove, (const std::string&), (override));
MOCK_METHOD(ssize_t, FileSize, (const std::string&), (override));
MOCK_METHOD(bool, List, (const std::string&, std::vector<std::string>*),
@@ -4640,6 +4641,9 @@ TEST_F(DeviceFilesTest, RetrieveAtscCertificate) {
// Call to Open will return a unique_ptr, freeing this object.
MockFile* file = new MockFile();
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path), NotNull()))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
@@ -4908,6 +4912,9 @@ TEST_F(DeviceFilesTest, RetrieveDefaultCertificateNeverExpires) {
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path), NotNull()))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(device_certificate_path)))
.WillOnce(Return(data.size()));
EXPECT_CALL(file_system, Open(StrEq(device_certificate_path), _))
@@ -4955,6 +4962,9 @@ TEST_P(RetrieveDefaultCertificateTest, ErrorScenarios) {
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path), NotNull()))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(device_certificate_path)))
.WillOnce(Return(data.size()));
EXPECT_CALL(file_system, Open(StrEq(device_certificate_path), _))
@@ -5009,6 +5019,10 @@ TEST_F(DeviceFilesTest, RetrieveCertificateWithoutKeyType) {
EXPECT_CALL(file_system, Exists(StrEq(device_legacy_certificate_path)))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system,
Exists(StrEq(device_legacy_certificate_path), NotNull()))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(device_default_certificate_path)))
.Times(AtLeast(1))
.WillRepeatedly(Return(false));
@@ -5311,7 +5325,7 @@ TEST_F(DeviceFilesTest, RetrieveLicenses) {
// Call to Open will return a unique_ptr, freeing this object.
MockFile* file = new MockFile();
EXPECT_CALL(file_system, Exists(StrEq(license_path)))
EXPECT_CALL(file_system, Exists(StrEq(license_path), NotNull()))
.WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(license_path)))
.WillOnce(Return(size));
@@ -5383,7 +5397,8 @@ TEST_F(DeviceFilesTest, AppParametersBackwardCompatibility) {
// Call to Open will return a unique_ptr, freeing this object.
MockFile* file = new MockFile();
EXPECT_CALL(file_system, Exists(StrEq(license_path))).WillOnce(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(license_path), NotNull()))
.WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(license_path)))
.WillOnce(Return(size));
EXPECT_CALL(file_system, Open(StrEq(license_path), _))
@@ -5474,10 +5489,9 @@ TEST_F(DeviceFilesTest, DeleteLicense) {
// Call to Open will return a unique_ptr, freeing this object.
MockFile* file = new MockFile();
EXPECT_CALL(file_system, Exists(StrEq(license_path)))
.Times(2)
.WillOnce(Return(true))
.WillOnce(Return(false));
EXPECT_CALL(file_system, Exists(StrEq(license_path))).WillOnce(Return(false));
EXPECT_CALL(file_system, Exists(StrEq(license_path), NotNull()))
.WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(license_path)))
.WillOnce(Return(size));
EXPECT_CALL(file_system, Open(StrEq(license_path), _))
@@ -5579,10 +5593,12 @@ TEST_F(DeviceFilesTest, OkpInfo_FileDoesNotExist) {
MockFileSystem file_system;
DeviceFiles device_files(&file_system);
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
int errno_value = ENOENT;
const std::string kOkpInfoPath =
device_base_path_ + DeviceFiles::GetOkpInfoFileName();
EXPECT_CALL(file_system, Exists(kOkpInfoPath)).WillOnce(Return(false));
EXPECT_CALL(file_system, Exists(StrEq(kOkpInfoPath), NotNull()))
.WillRepeatedly(DoAll(SetArgPointee<1>(errno_value), (Return(false))));
okp::SystemFallbackInfo info;
EXPECT_FALSE(device_files.RetrieveOkpInfo(&info));
@@ -5641,7 +5657,8 @@ TEST_F(DeviceFilesTest, OkpInfo_StoreAndRetrieve) {
// Set retrieve expectations.
file = new MockFile();
EXPECT_CALL(file_system, Exists(kOkpInfoPath)).WillOnce(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(kOkpInfoPath), NotNull()))
.WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(kOkpInfoPath))
.WillOnce(Return(serialized.size()));
EXPECT_CALL(file_system, Open(kOkpInfoPath, _))
@@ -5676,6 +5693,7 @@ TEST_P(DeviceFilesDeleteMultipleUsageInfoTest, DeleteAllButOne) {
file_path += kUsageInfoFileName;
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(_, NotNull())).WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(file_path))
.WillOnce(Return(kHashedUsageInfoFileWithThreeKeySetIds.size()));
@@ -5733,6 +5751,7 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteAllKeySetIds) {
// File read expectations.
MockFile* file_in = new MockFile();
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(_, NotNull())).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, FileSize(file_path))
.WillOnce(Return(kHashedUsageInfoFileWithThreeKeySetIds.size()));
EXPECT_CALL(file_system, Open(file_path, wvutil::FileSystem::kReadOnly))
@@ -5763,6 +5782,7 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteNone) {
file_path += kUsageInfoFileName;
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(_, NotNull())).WillRepeatedly(Return(true));
// Call, not providing any key set IDs. Should return true without any
// action, assuming the file exists.
@@ -5803,6 +5823,7 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteOne) {
file_path += kUsageInfoFileName;
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(_, NotNull())).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, FileSize(file_path))
.WillOnce(Return(kHashedUsageInfoFileWithTwoKeySetIds.size()));
@@ -5857,6 +5878,7 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, BadFile) {
// File is missing hash.
MockFile* file_in = new MockFile();
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(_, NotNull())).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, FileSize(file_path))
.WillOnce(Return(kHashlessUsageInfoFile.size()));
EXPECT_CALL(file_system, Open(file_path, wvutil::FileSystem::kReadOnly))
@@ -5903,9 +5925,9 @@ TEST_F(DeviceFilesUsageInfoTest, ListUsageIds) {
if (index >= 0) {
// Call to Open will return a unique_ptr, freeing this object.
MockFile* file = new MockFile();
EXPECT_CALL(file_system, Exists(StrEq(path)))
.Times(2)
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path))).WillOnce(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path), NotNull()))
.WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(path)))
.Times(2)
.WillRepeatedly(Return(file_data.size()));
@@ -6038,9 +6060,9 @@ TEST_P(DeviceFilesUsageInfoTest, Retrieve) {
if (index >= 0) {
// Call to Open will return a unique_ptr, freeing this object.
MockFile* file = new MockFile();
EXPECT_CALL(file_system, Exists(StrEq(path)))
.Times(2)
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path))).WillOnce(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path), NotNull()))
.WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(path)))
.Times(2)
.WillRepeatedly(Return(file_data.size()));
@@ -6101,9 +6123,9 @@ TEST_P(DeviceFilesUsageInfoTest, ListKeySetIds) {
if (index >= 0) {
// Call to Open will return a unique_ptr, freeing this object.
MockFile* file = new MockFile();
EXPECT_CALL(file_system, Exists(StrEq(path)))
.Times(2)
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path))).WillOnce(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path), NotNull()))
.WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(path)))
.Times(2)
.WillRepeatedly(Return(file_data.size()));
@@ -6153,9 +6175,9 @@ TEST_P(DeviceFilesUsageInfoTest, ListProviderSessionTokenIds) {
if (index >= 0) {
// Call to Open will return a unique_ptr, freeing this object.
MockFile* file = new MockFile();
EXPECT_CALL(file_system, Exists(StrEq(path)))
.Times(2)
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path))).WillOnce(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path), NotNull()))
.WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(path)))
.Times(2)
.WillRepeatedly(Return(file_data.size()));
@@ -6215,7 +6237,8 @@ TEST_P(DeviceFilesUsageInfoTest, RetrieveByProviderSessionToken) {
kUsageInfoTestData[index < 0 ? 0 : index]
.usage_data.provider_session_token;
EXPECT_CALL(file_system, Exists(StrEq(path))).WillOnce(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path), NotNull()))
.WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(path)))
.WillOnce(Return(file_data.size()));
EXPECT_CALL(file_system, Open(StrEq(path), _))
@@ -6299,9 +6322,9 @@ TEST_P(DeviceFilesUsageInfoTest, UpdateUsageInfo) {
(index < 0) ? kEmptyUsageInfoFileData
: kUsageInfoTestData[max_index_by_app_id].file_data;
EXPECT_CALL(file_system, Exists(StrEq(path)))
.Times(2)
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path))).WillOnce(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path), NotNull()))
.WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(path)))
.WillOnce(Return(file_data.size()));
EXPECT_CALL(*file, Read(NotNull(), Eq(file_data.size())))
@@ -6344,7 +6367,8 @@ TEST_P(DeviceFilesHlsAttributesTest, Read) {
std::string path = device_base_path_ + param->key_set_id +
DeviceFiles::GetHlsAttributesFileNameExtension();
EXPECT_CALL(file_system, Exists(StrEq(path))).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path), NotNull()))
.WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(path)))
.WillRepeatedly(Return(param->file_data.size()));
EXPECT_CALL(file_system, Open(StrEq(path), _))
@@ -6452,7 +6476,8 @@ TEST_P(DeviceFilesUsageTableTest, Read) {
std::string path = device_base_path_ + DeviceFiles::GetUsageTableFileName();
const std::string& file_data = kUsageTableInfoTestData[index].file_data;
EXPECT_CALL(file_system, Exists(StrEq(path))).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path), NotNull()))
.WillOnce(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(path)))
.WillRepeatedly(Return(file_data.size()));
EXPECT_CALL(file_system, Open(StrEq(path), _))
@@ -6505,7 +6530,8 @@ TEST_F(DeviceFilesUsageTableTest, ReadWithoutLruData) {
const std::string path =
device_base_path_ + DeviceFiles::GetUsageTableFileName();
MockFileSystem file_system;
EXPECT_CALL(file_system, Exists(StrEq(path))).WillRepeatedly(Return(true));
EXPECT_CALL(file_system, Exists(StrEq(path), NotNull()))
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(path)))
.WillRepeatedly(Return(kUsageTableWithoutLruData.size()));
EXPECT_CALL(file_system, Open(StrEq(path), _))
@@ -6619,7 +6645,7 @@ TEST_F(DeviceFilesTest, RetrieveOemCertificateSuccess) {
device_base_path_ + wvutil::kOemCertificateFileName;
// Call to Open will return a unique_ptr, freeing this object.
MockFile* read_file = new MockFile();
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path), NotNull()))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(device_certificate_path)))
@@ -6650,7 +6676,7 @@ TEST_F(DeviceFilesTest, RetrieveOemCertificateRandomCertFail) {
std::string ramdom_cert = "random_cert";
// Call to Open will return a unique_ptr, freeing this object.
MockFile* read_file = new MockFile();
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path), NotNull()))
.Times(AtLeast(1))
.WillRepeatedly(Return(true));
EXPECT_CALL(file_system, FileSize(StrEq(device_certificate_path)))
@@ -6676,9 +6702,10 @@ TEST_F(DeviceFilesTest, RetrieveOemCertificateNotFoundFail) {
MockFileSystem file_system;
const std::string device_certificate_path =
device_base_path_ + wvutil::kOemCertificateFileName;
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
int errno_value = ENOENT;
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path), NotNull()))
.Times(AtLeast(1))
.WillRepeatedly(Return(false));
.WillRepeatedly(DoAll(SetArgPointee<1>(errno_value), (Return(false))));
DeviceFiles device_files(&file_system);
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));