Esempio n. 1
0
    def test_extrn_path_with_long_filename(self):
        safe_file_name = os.path.split(
            fileclient.Client(self.opts)._extrn_path(
                'https://test.com/' + ('A' * 254), 'base'))[-1]
        assert safe_file_name == 'A' * 254

        oversized_file_name = os.path.split(
            fileclient.Client(self.opts)._extrn_path(
                'https://test.com/' + ('A' * 255), 'base'))[-1]
        assert len(oversized_file_name) < 256
        assert oversized_file_name != 'A' * 255

        oversized_file_with_query_params = os.path.split(
            fileclient.Client(self.opts)._extrn_path(
                'https://test.com/file?' + ('A' * 255), 'base'))[-1]
        assert len(oversized_file_with_query_params) < 256
Esempio n. 2
0
    def test_extrn_path_with_long_filename(self):
        safe_file_name = os.path.split(
            fileclient.Client(self.opts)._extrn_path(
                "https://test.com/" + ("A" * 254), "base"))[-1]
        assert safe_file_name == "A" * 254

        oversized_file_name = os.path.split(
            fileclient.Client(self.opts)._extrn_path(
                "https://test.com/" + ("A" * 255), "base"))[-1]
        assert len(oversized_file_name) < 256
        assert oversized_file_name != "A" * 255

        oversized_file_with_query_params = os.path.split(
            fileclient.Client(self.opts)._extrn_path(
                "https://test.com/file?" + ("A" * 255), "base"))[-1]
        assert len(oversized_file_with_query_params) < 256
Esempio n. 3
0
    def test_cache_extrn_path_invalid(self):
        """
        Tests for extrn_filepath for a given url
        """
        file_name = "http://localhost:8000/../../../../../usr/bin/bad"

        ret = fileclient.Client(self.opts)._extrn_path(file_name, "base")
        assert ret == "Invalid path"
Esempio n. 4
0
    def test_cache_extrn_path_valid(self):
        """
        Tests for extrn_filepath for a given url
        """
        file_name = "http://localhost:8000/test/location/src/dev/usr/file"

        ret = fileclient.Client(self.opts)._extrn_path(file_name, "base")
        assert ret == os.path.join("__test__", "extrn_files", "base", ret)
Esempio n. 5
0
 def test_cache_raises_exception_on_non_eexist_ioerror(self):
     '''
     If makedirs raises other than EEXIST errno, an exception should be raised.
     '''
     with patch('os.path.isfile', lambda prm: False):
         with patch('os.makedirs', self._fake_makedir(num=errno.EROFS)):
             with self.assertRaises(OSError):
                 with fileclient.Client(
                         self.opts)._cache_loc('testfile') as c_ref_itr:
                     assert c_ref_itr == '/__test__/files/base/testfile'
Esempio n. 6
0
 def test_cache_skips_makedirs_on_race_condition(self):
     '''
     If cache contains already a directory, do not raise an exception.
     '''
     with patch('os.path.isfile', lambda prm: False):
         for exists in range(2):
             with patch('os.makedirs', self._fake_makedir()):
                 with fileclient.Client(
                         self.opts)._cache_loc('testfile') as c_ref_itr:
                     assert c_ref_itr == os.sep + os.sep.join(
                         ['__test__', 'files', 'base', 'testfile'])
Esempio n. 7
0
 def test_cache_skips_makedirs_on_race_condition(self):
     """
     If cache contains already a directory, do not raise an exception.
     """
     with patch("os.path.isfile", lambda prm: False):
         for exists in range(2):
             with patch("os.makedirs", self._fake_makedir()):
                 with fileclient.Client(
                         self.opts)._cache_loc("testfile") as c_ref_itr:
                     assert c_ref_itr == os.sep + os.sep.join(
                         ["__test__", "files", "base", "testfile"])
Esempio n. 8
0
    def test_limit_traversal(self):
        '''
        1) Set up a deep directory structure
        2) Enable the configuration option for 'limit_directory_traversal'
        3) Ensure that we can find SLS files in a directory so long as there is an SLS file in a directory above.
        4) Ensure that we cannot find an SLS file in a directory that does not have an SLS file in a directory above.
        '''
        file_client_opts = self.get_config('master', from_scratch=True)
        file_client_opts['fileserver_limit_traversal'] = True

        ret = fileclient.Client(file_client_opts).list_states('base')
        self.assertIn('test_deep.test', ret)
        self.assertIn('test_deep.a.test', ret)
        self.assertNotIn('test_deep.b.2.test', ret)
Esempio n. 9
0
 def setUp(self):
     self.file_client = fileclient.Client(self.master_opts)