1#!/usr/bin/env python 2# 3# Copyright (C) 2017 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17from abc import ABCMeta 18from abc import abstractmethod 19 20from vts.utils.python.file import file_utils 21 22class KernelSelinuxFileTestBase(object): 23 """Abstract test for the formatting of a selinux file. 24 25 Individual files can inherit from this class and define the correct path, 26 file content, and permissions. 27 """ 28 __metaclass__ = ABCMeta 29 30 @abstractmethod 31 def get_path(self): 32 """Return the full path of this selinux file.""" 33 pass 34 35 def result_correct(self, file_contents): 36 """Return True if the file contents are correct. 37 38 Subclasses define the requirements for the selinux file and validate 39 that the contents of a file are correct. 40 41 Args: 42 file_contents: String, the contents of an selinux file 43 44 Returns: 45 True if the contents are correct, False otherwise. 46 """ 47 return True 48 49 def get_permission_checker(self): 50 """Gets the function handle to use for validating file permissions. 51 52 Return the function that will check if the permissions are correct. 53 By default, return the IsReadOnly function from file_utils. 54 55 Returns: 56 function which takes one argument (the unix file permission bits 57 in octal format) and returns True if the permissions are correct, 58 False otherwise. 59 """ 60 return file_utils.IsReadOnly 61