Esempio n. 1
0
 def test_default_cwd(self, p):
     set_cwd(tempfile.mkdtemp())
     cuckoo_create()
     with chdir(cwd()):
         decide_cwd(".")
         cuckoo_init(logging.INFO, self.ctx)
         p.assert_called_once_with("cuckoo community")
Esempio n. 2
0
 def test_default_cwd(self, p):
     set_cwd(tempfile.mkdtemp())
     cuckoo_create()
     with chdir(cwd()):
         decide_cwd(".")
         cuckoo_init(logging.INFO, self.ctx)
         p.assert_called_once_with("cuckoo community")
Esempio n. 3
0
def test_is32bit_path():
    p = Process()

    mzdos0 = os.path.abspath("tests/files/mzdos0")
    icardres = os.path.abspath("tests/files/icardres.dll")

    with chdir("cuckoo/data/analyzer/windows"):
        # File not found.
        with pytest.raises(CuckooError) as e:
            p.is32bit(path="thisisnotafile")
        e.match("File not found")

        # No MZ header.
        with pytest.raises(CuckooError) as e:
            p.is32bit(path=__file__)
        e.match("returned by is32bit")
        e.match("Invalid DOS file")

        # This is a MZ-DOS executable rather than a PE file.
        assert p.is32bit(path=mzdos0) is True

        # TODO Add a 32-bit PE executable.

        # This is a 64-bit PE file.
        assert p.is32bit(path=icardres) is False
Esempio n. 4
0
    def test_pull_repository(self):
        # reset
        LibraryCheckerService.is_repository_updated = False
        with utils.chdir(
                str(onlinejudge.utils.user_cache_dir /
                    'library-checker-problems')):
            # the first commit https://github.com/yosupo06/library-checker-problems/commit/fb33114329382695b1a17655843b490b04a08ab6
            subprocess.check_call([
                'git', 'reset', '--hard',
                'fb33114329382695b1a17655843b490b04a08ab6'
            ])

        # ensure that it automatically runs `$ git pull`
        self.assertEqual(
            LibraryCheckerProblem.from_url(
                'https://judge.yosupo.jp/problem/aplusb').
            download_sample_cases(), [
                TestCase(name='example_00',
                         input_name='example_00.in',
                         input_data=b'1234 5678\n',
                         output_name='example_00.out',
                         output_data=b'6912\n'),
                TestCase(name='example_01',
                         input_name='example_01.in',
                         input_data=b'1000000000 1000000000\n',
                         output_name='example_01.out',
                         output_data=b'2000000000\n'),
            ])
Esempio n. 5
0
def test_is32bit_path():
    p = Process()

    mzdos0 = os.path.abspath("tests/files/mzdos0")
    icardres = os.path.abspath("tests/files/icardres.dll")

    with chdir("cuckoo/data/analyzer/windows"):
        # File not found.
        with pytest.raises(CuckooError) as e:
            p.is32bit(path="thisisnotafile")
        e.match("File not found")

        # No MZ header.
        with pytest.raises(CuckooError) as e:
            p.is32bit(path=__file__)
        e.match("returned by is32bit")
        e.match("Invalid DOS file")

        # This is a MZ-DOS executable rather than a PE file.
        assert p.is32bit(path=mzdos0) is True

        # TODO Add a 32-bit PE executable.

        # This is a 64-bit PE file.
        assert p.is32bit(path=icardres) is False
Esempio n. 6
0
def test_is32bit_process():
    p = Process()

    with chdir("cuckoo/data/analyzer/windows"):
        # Normally the user shouldn't be able to access the SYSTEM process.
        with pytest.raises(CuckooError) as e:
            p.is32bit(pid=4)
        e.match("process access denied$")
Esempio n. 7
0
def test_is32bit_process():
    p = Process()

    with chdir("cuckoo/data/analyzer/windows"):
        # Normally the user shouldn't be able to access the SYSTEM process.
        with pytest.raises(CuckooError) as e:
            p.is32bit(pid=4)
        e.match("process access denied$")
Esempio n. 8
0
def test_is32bit_process():
    p = Process()

    with chdir("cuckoo/data/analyzer/windows"):
        # Normally (i.e., when not Administrator) the user shouldn't be able
        # to access the lsass.exe process.
        with pytest.raises(CuckooError) as e:
            p.is32bit(process_name="lsass.exe")
        e.match("process access denied$")
Esempio n. 9
0
    def test_is_up_to_date(self):
        """应该能探测是否是已经merge过的"""
        with setup2repos('prj_uptodate') as (path, repo, fork_path, fork_repo):

            with self.clone_clean(path) as work_path:
                with chdir(work_path):
                    gyt.call(['git', 'pull', fork_path])
                    gyt.call(['git', 'push', 'origin', 'master'])

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            ok_(pullreq.is_up_to_date())
Esempio n. 10
0
    def test_is_up_to_date(self):
        """应该能探测是否是已经merge过的"""
        with setup2repos('prj_uptodate') as (path, repo, fork_path, fork_repo):

            with self.clone_clean(path) as work_path:
                with chdir(work_path):
                    gyt.call(['git', 'pull', fork_path])
                    gyt.call(['git', 'push', 'origin', 'master'])

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            ok_(pullreq.is_up_to_date())
Esempio n. 11
0
    def test_get_diffs(self):
        """应该能够得到所有将合并的diff"""
        with setup2repos('prj4') as (path, repo, fork_path, fork_repo):

            # make some change in origin repo, too
            with clone(path) as work_path:
                with chdir(work_path):
                    with open('b', 'w') as f:
                        f.write('b')

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            diffs = pullreq.get_diff()
            # should not contain file b in origin
            eq_(diffs.length, 1)
Esempio n. 12
0
    def test_get_diffs(self):
        """应该能够得到所有将合并的diff"""
        with setup2repos('prj4') as (path, repo, fork_path, fork_repo):

            # make some change in origin repo, too
            with clone(path) as work_path:
                with chdir(work_path):
                    with open('b', 'w') as f:
                        f.write('b')

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            diffs = pullreq.get_diff()
            # should not contain file b in origin
            eq_(diffs.length, 1)
Esempio n. 13
0
    def test_documentation_of(self) -> None:
        get_random_string = lambda: ''.join(
            [random.choice('0123456789abcdef') for _ in range(64)])
        random_relative_hpp = get_random_string()
        random_absolute_hpp = get_random_string()
        random_unsupported_absolute_hpp = get_random_string()
        random_no_document_hpp = get_random_string()
        random_relative_md = get_random_string()
        random_absolute_md = get_random_string()
        random_unsupported_absolute_md = get_random_string()
        random_standalone_page_md = get_random_string()

        files = {
            pathlib.Path('src', 'a', 'b', 'relative.hpp'):
            random_relative_hpp.encode(),
            pathlib.Path('src', 'a', 'b', 'absolute.hpp'):
            random_absolute_hpp.encode(),
            pathlib.Path('src', 'a', 'b', 'unsupported-absolute.hpp'):
            random_unsupported_absolute_hpp.encode(),
            pathlib.Path('src', 'a', 'b', 'no-document.hpp'):
            random_no_document_hpp.encode(),
            pathlib.Path('docs', 'x', 'y', 'relative.md'):
            textwrap.dedent(f"""\
                ---
                title: relative.md
                documentation_of: ../../../src/a/b/relative.hpp
                ---

                {random_relative_md}
                """).encode(),
            pathlib.Path('docs', 'x', 'y', 'unsupported-absolute.md'):
            textwrap.dedent(f"""\
                ---
                title: unsupported-absolute.md
                documentation_of: src/a/b/unsupported-absolute.hpp
                ---

                {random_unsupported_absolute_md}
                """).encode(),
            pathlib.Path('docs', 'x', 'y', 'absolute.md'):
            textwrap.dedent(f"""\
                ---
                title: absolute.md
                documentation_of: //src/a/b/absolute.hpp
                ---

                {random_absolute_md}
                """).encode(),
            pathlib.Path('docs', 'x', 'y', 'standalone-page.md'):
            textwrap.dedent(f"""\
                ---
                title: standalone page
                ---

                {random_standalone_page_md}
                """).encode(),
        }

        destination_dir = pathlib.Path('.verify-helper', 'markdown')
        expected: Dict[pathlib.Path, List[str]] = {
            destination_dir / 'src' / 'a' / 'b' / 'relative.hpp.md':
            [random_relative_hpp, random_relative_md],
            destination_dir / 'src' / 'a' / 'b' / 'absolute.hpp.md':
            [random_absolute_hpp, random_absolute_md],
            destination_dir / 'src' / 'a' / 'b' / 'unsupported-absolute.hpp.md':
            [random_unsupported_absolute_hpp, random_unsupported_absolute_md],
            destination_dir / 'src' / 'a' / 'b' / 'no-document.hpp.md':
            [random_no_document_hpp],
            destination_dir / 'docs' / 'x' / 'y' / 'standalone-page.md':
            [random_standalone_page_md],
        }

        with utils.load_files_pathlib(files) as tempdir:
            with utils.chdir(tempdir):
                onlinejudge_verify.main.subcommand_docs()
                for path, keywords in expected.items():
                    self.assertTrue((tempdir / path).exists())
                    with open(tempdir / path) as fh:
                        content = fh.read()
                    for keyword in keywords:
                        self.assertIn(keyword, content)