Esempio n. 1
0
    def test_unexpected_content_rule(self):
        fs = fs_domain.AbstractFileSystem(
            fs_domain.DiskBackedFileSystem(TEST_DATA_DIR))

        CANONICAL_DATA_DIR = os.path.join(TEST_DATA_DIR, 'canonical')
        canonical_fs = fs_domain.AbstractFileSystem(
            fs_domain.DiskBackedFileSystem(CANONICAL_DATA_DIR))

        rule = tar_file_string.HasUnexpectedContent(['hello.c', 'Makefile'
                                                     ]).set_fs(canonical_fs)

        file_name = 'incorrect-contents.tar.gz'
        encoded_content = base64.b64encode(fs.get(file_name, mode='rb'))
        self.assertTrue(rule.eval(encoded_content))

        file_name = 'good.tar.gz'
        encoded_content = base64.b64encode(fs.get(file_name, mode='rb'))
        self.assertFalse(rule.eval(encoded_content))
Esempio n. 2
0
    def test_matches_base64encoded_file_rule(self):
        TEST_DATA_DIR = 'extensions/rules/testdata'
        fs = fs_domain.AbstractFileSystem(
            fs_domain.DiskBackedFileSystem(TEST_DATA_DIR))

        file_names = ['test.c', 'test.png', 'test.tar.gz']

        for file_name in file_names:
            encoded_content = base64.b64encode(fs.get(file_name))
            rule = unicode_string.MatchesBase64EncodedFile(
                file_name).set_fs(fs)
            self.assertFuzzyTrue(rule.eval(encoded_content))
Esempio n. 3
0
 def test_get(self):
     fs = fs_domain.AbstractFileSystem(
         fs_domain.DiskBackedFileSystem(feconf.TESTS_DATA_DIR))
     self.assertTrue(fs.get('img.png'))
     with self.assertRaisesRegexp(IOError, 'No such file or directory'):
         fs.get('non_existent_file.png')
Esempio n. 4
0
 def setUp(self):
     super(DiskBackedFileSystemUnitTests, self).setUp()
     self.user_email = '*****@*****.**'
     self.user_id = self.get_user_id_from_email(self.user_email)
     self.fs = fs_domain.AbstractFileSystem(
         fs_domain.DiskBackedFileSystem(feconf.TESTS_DATA_DIR))