def manifest_cli_create(self, args, expected_result):
        """
        execute the CLI manifest tool with the given arguments on our
        sample JAR. Verifies that the resulting output manifest is
        identical to the expected result.
        """

        # the result we expect to see from running the script
        with open(get_data_fn(expected_result)) as f:
            expected_result = f.read()

        # the invocation of the script
        src_jar = get_data_fn("manifest-sample1.jar")
        with NamedTemporaryFile() as tmp_out:
            cmd = ["manifest", "-c", src_jar, "-m", tmp_out.name] + args.split()

            # rather than trying to actually execute the script in a
            # subprocess, we'll give it an output file call it in the
            # current process. This prevents issues when there's already
            # an installed version of python-javatools present which may
            # be down-version from the one being tested. Calling the
            # manifest utility by name will use the installed rather than
            # local dev copy. Might be able to tweak this, but for now,
            # this is safer.
            main(cmd)
            result = tmp_out.read()

            self.assertEqual(result, expected_result,
                         "Result of \"%r\" does not match expected output."
                         " Expected:\n%s\nReceived:\n%s"
                         % (cmd, expected_result, result))
예제 #2
0
    def manifest_cli_create(self, args, expected_result):
        """
        execute the CLI manifest tool with the given arguments on our
        sample JAR. Verifies that the resulting output manifest is
        identical to the expected result.
        """

        # the result we expect to see from running the script
        with open(get_data_fn(expected_result)) as f:
            expected_result = f.read()

        # the invocation of the script
        src_jar = get_data_fn("manifest-sample1.jar")
        with NamedTemporaryFile() as tmp_out:
            cmd = ["manifest", "-c", src_jar, "-m", tmp_out.name
                   ] + args.split()

            # rather than trying to actually execute the script in a
            # subprocess, we'll give it an output file call it in the
            # current process. This prevents issues when there's already
            # an installed version of python-javatools present which may
            # be down-version from the one being tested. Calling the
            # manifest utility by name will use the installed rather than
            # local dev copy. Might be able to tweak this, but for now,
            # this is safer.
            main(cmd)
            result = tmp_out.read()

            self.assertEqual(
                result, expected_result,
                "Result of \"%r\" does not match expected output."
                " Expected:\n%s\nReceived:\n%s" %
                (cmd, expected_result, result))
    def test_cli_sign_and_verify(self):
        src = get_data_fn("manifest-sample3.jar")
        key_alias = "SAMPLE3"
        cert = get_data_fn("javatools-cert.pem")
        key = get_data_fn("javatools.pem")
        with NamedTemporaryFile() as tmp_jar:
            copyfile(src, tmp_jar.name)
            cmd = ["manifest", "-s", cert, key, key_alias, tmp_jar.name]
            self.assertEqual(main(cmd), 0, "Command %s returned non-zero status"
                             % " ".join(cmd))

            error_message = verify(cert, tmp_jar.name, key_alias)
            self.assertIsNone(error_message,
                              "Verification of JAR which we just signed failed: %s"
                              % error_message)
예제 #4
0
    def test_cli_sign_and_verify(self):
        src = get_data_fn("manifest-sample3.jar")
        key_alias = "SAMPLE3"
        cert = get_data_fn("javatools-cert.pem")
        key = get_data_fn("javatools.pem")
        with NamedTemporaryFile() as tmp_jar:
            copyfile(src, tmp_jar.name)
            cmd = ["manifest", "-s", cert, key, key_alias, tmp_jar.name]
            self.assertEqual(
                main(cmd), 0,
                "Command %s returned non-zero status" % " ".join(cmd))

            error_message = verify(cert, tmp_jar.name, key_alias)
            self.assertIsNone(
                error_message,
                "Verification of JAR which we just signed failed: %s" %
                error_message)
예제 #5
0
 def test_cli_verify_nok(self):
     jar_file = get_data_fn("cli-verify-nok.jar")
     self.assertEqual(1, main(["-v", jar_file]))
예제 #6
0
 def test_cli_verify_nok(self):
     jar_file = get_data_fn("test_manifest/cli-verify-nok.jar")
     self.assertEqual(1, main(["argv0", "v", jar_file]))
예제 #7
0
 def test_cli_verify_ok(self):
     jar_file = get_data_fn("cli-verify-ok.jar")
     self.assertEqual(0, main(["argv0", "v", jar_file]))
예제 #8
0
 def test_cli_verify_nok(self):
     jar_file = get_data_fn("test_manifest/cli-verify-nok.jar")
     self.assertEqual(1, main(["argv0", "v", jar_file]))
예제 #9
0
 def test_cli_verify_nok(self):
     jar_file = get_data_fn("cli-verify-nok.jar")
     self.assertEqual(1, main(["-v", jar_file]))