Example #1
0
    def test_parse(self):
        pem = Pem(self.pem_contents)

        self.assertEqual(pem.private_key, self.private_key)
        self.assertEqual(pem.certificate, self.certificate)

        with self.assertRaises(KeyError):
            pem.csr

        with self.assertRaises(KeyError):
            pem.get("FOO BAR")
Example #2
0
    def test_parse_custom_content(self):
        pem = Pem(trim("""Hi, please take this.
        -----BEGIN FOOBAR-----
        HELLO/WORKD===
        -----END FOOBAR-----
        regards,
        kind of mail signature comes here
        """) + "\n")

        self.assertEqual(
            trim(pem.get("FOOBAR")),
            trim("""-----BEGIN FOOBAR-----
                    HELLO/WORKD===
                    -----END FOOBAR-----"""))
Example #3
0
    def test_parse_bad_format(self):
        with self.assertRaises(BadFormatError):
            # Partial contents raises format error
            Pem(trim("""-----BEGIN RSA PRIVATE KEY-----
            MIICXQIBAAKBgQCmcXbusrr8zQr8snIb0OVQibVfgv7zPjh/5xdcrKOejJzp3epA
            AF4TITeFR9vzWIwkmkcRoY+IbQNhh7kefGUYD47bvVamJMtq5cGYVs0HngT+KTMa
            NGH/G44KkFIOaz/b5d/JNKONrlqwxqXS+m6IY4l/E1Ff25ZjND5TaEvI1wIDAQAB
            """) + "\n")

        with self.assertRaises(BadFormatError):
            # No section content raises format error
            Pem("""HELLO WORLD
            HOW'S GOING????
            """)
Example #4
0
    def test_parse_cr(self):
        pem = Pem(self.pem_contents.replace('\n', '\r'))

        self.assertEqual(pem.private_key, self.private_key)
        self.assertEqual(pem.certificate, self.certificate)