Esempio n. 1
0
    def test_runtime_error(self):
        with self.assertRaises(RuntimeError) as ctx:
            smime_sign(
                signer_cert_path=self.signer_key_path,
                signer_key_path=self.recipient_cert_path,
                recipient_cert_path=self.signer_key_path,
                content=self.maniphest_json,
                output_format='PEM',
            )

        self.assertRegexpMatches(str(ctx.exception),
                                 r'OpenSSL failed with #[\d]+: .*')
Esempio n. 2
0
    def test_incorrect_format_error(self):
        with self.assertRaises(ValueError) as ctx:
            smime_sign(
                signer_cert_path=self.signer_cert_path,
                signer_key_path=self.signer_key_path,
                recipient_cert_path=self.recipient_cert_path,
                content=self.maniphest_json,
                output_format='INCORRECT',
            )

        self.assertEqual(str(ctx.exception),
                         ("{output_format}' not found in the set of supported "
                          "formats: {supported_formats}").format(
                              output_format='INCORRECT',
                              supported_formats=", ".join(
                                  ('SMIME', 'PEM', 'DER')),
                          ))
Esempio n. 3
0
    def test_relative_recipient_cert_error(self):
        relative_recipient_cert = "files/recipient.pem"

        with self.assertRaises(ValueError) as ctx:
            smime_sign(
                signer_cert_path=self.signer_cert_path,
                signer_key_path=self.signer_key_path,
                recipient_cert_path=relative_recipient_cert,
                content=self.maniphest_json,
                output_format='SMIME',
            )

        self.assertEqual(
            str(ctx.exception),
            "{file_list} must be absolute paths to existing files".format(
                file_list=", ".join([
                    self.signer_cert_path,
                    self.signer_key_path,
                    relative_recipient_cert,
                ]), ))
Esempio n. 4
0
    def test_pem_format(self):
        actual_smime = smime_sign(
            signer_cert_path=self.signer_cert_path,
            signer_key_path=self.signer_key_path,
            recipient_cert_path=self.recipient_cert_path,
            content=self.maniphest_json,
            output_format='PEM',
        )

        with tempfile.NamedTemporaryFile(delete=True) as temp:
            temp.write(actual_smime)
            temp.flush()

            self.assertTrue(
                smime_verify(
                    signer_cert_path=self.signer_cert_path,
                    content_path=self.manifest_json_path,
                    signature_path=path.abspath(temp.name),
                    signature_format='PEM',
                ))