Home | History | Annotate | Download | only in vts
      1 /*
      2  * Copyright (C) 2019 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "utility/ValidateXml.h"
     18 
     19 #include <dirent.h>
     20 #include <stdlib.h>
     21 #include <sys/stat.h>
     22 #include <unistd.h>
     23 
     24 #include <string>
     25 
     26 #include <android-base/strings.h>
     27 
     28 static std::vector<std::string> get_files_in_dirs(const char* dir_path) {
     29     std::vector<std::string> files;
     30     std::unique_ptr<DIR, decltype(&closedir)> d(opendir(dir_path), closedir);
     31 
     32     if (d == nullptr) {
     33         return files;
     34     }
     35 
     36     struct dirent* de;
     37     while ((de = readdir(d.get()))) {
     38         if (de->d_type != DT_REG) {
     39             continue;
     40         }
     41         if (android::base::EndsWith(de->d_name, ".xml")) {
     42             files.push_back(de->d_name);
     43         }
     44     }
     45     return files;
     46 }
     47 
     48 TEST(CheckConfig, defaultPermissions) {
     49     RecordProperty("description",
     50                    "Verify that the default-permissions file "
     51                    "is valid according to the schema");
     52 
     53     std::vector<const char*> locations = {"/vendor/etc/default-permissions",
     54                                           "/odm/etc/default-permissions"};
     55 
     56     for (const char* dir_path : locations) {
     57         std::vector<std::string> files = get_files_in_dirs(dir_path);
     58         for (auto& file_name : files) {
     59             EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(file_name.c_str(), {dir_path},
     60                                                     "/data/local/tmp/default-permissions.xsd");
     61         }
     62     }
     63 }
     64