from unittest import TestCase

from jwcrypto import jwk

import pem_file_helper


class TestPemFileHelper(TestCase):

    pem = pem_file_helper.PemFileHelper()

    def test_set_private_key_from_pem_file(self):
        self.pem.private_key_pem_file_location = "resources/keys/test/privatekey.pem"
        private_key = self.pem.set_private_key_from_pem_file()
        expected_private_key_details = {
            "kid": "<KEY>",
            "thumbprint": "<KEY>",
            "kty": "RSA",
            "n": "<KEY>"
                 + "<KEY>"
                 + "<KEY>"
                 + "<KEY>",
            "e": "AQAB"
        }
        expected_private_key = jwk.JWK(**expected_private_key_details)
        self.assertEqual(private_key, expected_private_key)

    def test_set_public_key_from_pem_file(self):
        public_key = self.pem.set_public_key_from_pem_file()
        expected_public_key_details = {
            "kid": "<KEY>",
            "thumbprint": "stU_K9M99AU8WVS1-pHpcw02XanpwOWSwhQBQk8MaaM",
            "kty": "RSA",
            "n": "<KEY>
                 + "<KEY>"
                 + "<KEY>"
                 + "<KEY>",
            "e": "AQAB"
        }
        expected_public_key = jwk.JWK(**expected_public_key_details)
        self.assertEqual(public_key, expected_public_key)

    def test_get_pubic_key(self):
        public_key = self.pem.get_pubic_key()
        expected_public_key_details = {
            "kid": "<KEY>",
            "thumbprint": "stU_K9M99AU8WVS1-pHpcw02XanpwOWSwhQBQk8MaaM",
            "kty": "RSA",
            "n": "23_ittMCVfOApzuZWeWQk0iPFMe41lmAURF8lFTQIK6JXWHDmQUfg0_iES9NpS7oVwVucS5i0rJz09cBMQ9g9XSVYwaYPWm-2Lc2-"
                 + "pXimYCxrTFx1_eY51HlgKV9M-b-dJboyOWuGeyFUM3OVxQEB6UN5XOKHtcRFFkIYtXbBDBsbDte7dWMQYHG75TYa-37WVHbzvoJ"
                 + "Op5luK_AJrY4Z0SZgV5mGWGVz17UoilRJipXXvV7IeDXZDgTqQG1dYAXISN3ajAdkQVGgrVBf9Q4zVWrFaDq8RfrbVGbWVwFNl"
                 + "<KEY>-XDc7TegHk7dw",
            "e": "AQAB"
        }
        expected_public_key = jwk.JWK(**expected_public_key_details)
        self.assertEqual(public_key, expected_public_key)

    def test_get_private_key(self):
        self.pem.private_key_pem_file_location = "resources/keys/test/privatekey.pem"
        private_key = self.pem.set_private_key_from_pem_file()
        expected_private_key_details = {
            'd': '<KEY>'
                 'it1c3nS7OM0_YjbvcdvmNKZamzvyZQBDoIdkBXBX3sJCSK9zFCiJXkCHjGMIHgClM-FzeUo-BDlBZhILgy1mfIlFwMnzYyL1UHa88'
                 'gt61XFPD9eWEvPhnvkiYYS7904utxujYK54svF-59_yXWVyQfI7KalYedx1AlH0jF9sQ7J4WrBYYaOJhiq5gV16w5RtOoJghZ2aI'
                 'hTL9Thg0XhnlWuR_L4y79G5jwZcjKCSxCuX2O9OMQ',
            'dp': '<KEY>'
                  '<KEY>',
            'dq': '<KEY>'
                  '<KEY>',
            'e': 'AQAB',
            'kid': '<KEY>',
            'kty': 'RSA',
            'n': '43WyOeBlUTACUIdEw0HlL5N12FibPKlj9Ia_f07Rzm5V94_3QMynf2iwwzHTadHM5yku-wFcTM0LyTu6wEp6WIa9dKPdIQhMvsNA'
                 'gf9rN9KKeyb0usvZt54qOzuDPaaauY2pD2als2WNXBZd3CgrWqZmom-MPknFcfkhT4zl7LOnBbMzIn0v4sd5jjBF-xExxwkmKriu'
                 'CN_4luK7Wm5iWNTSqOiciMCOey-l3rhxDUZT8BmCE6PM8wDUercHNyoj3najQwxG09wVS2m2joQArk-y9mYfJKffIS70iyFwaD1O'
                 '7lzNPyn2Cm8FP_Z0mCg_JOHgM4ZaR63mPGk9cfRdoQ',
            'p': '<KEY>
                 '7z469lIechvmxz3NScDFgt__yySHSkTaAfkNIgd4OO2ap4SQnEUUU_kQ63BYjfxn53lg7p0M',
            'q': '<KEY>'
                 '8NaHAE8pQhooTwaiwy5e3qA2P6Woz0WVBFUy4bmtcdjtwcMSLrp95EZ5BnDQ0LKX8qkt30s',
            'qi': 'ipmXLLoJMJDYbo256jQB0p6q9hU3f8RusPoAJ354s6-3g8u19cMzAWvNMUgG2U2BEMKm6O5I3fsh5Sd4wR3xDhEzjUVkPCrHKh'
                  'rT_scHd0gljNFsp7elZ6JkhbVZXwLA-Fp08frLMFrgP2-oOQ-DS4MWZe1OauMy4e_fHt2C1mg'
        }
        expected_private_key = jwk.JWK(**expected_private_key_details)
        self.assertEqual(private_key, expected_private_key)

from unittest import TestCase

from jwcrypto import jwk

import pem_file_helper


class TestPemFileHelper(TestCase):

    pem = pem_file_helper.PemFileHelper()

    def test_set_private_key_from_pem_file(self):
        self.pem.private_key_pem_file_location = "resources/keys/test/privatekey.pem"
        private_key = self.pem.set_private_key_from_pem_file()
        expected_private_key_details = {
            "kid": "<KEY>",
            "thumbprint": "<KEY>",
            "kty": "RSA",
            "n": "<KEY>"
                 + "<KEY>"
                 + "<KEY>"
                 + "<KEY>",
            "e": "AQAB"
        }
        expected_private_key = jwk.JWK(**expected_private_key_details)
        self.assertEqual(private_key, expected_private_key)

    def test_set_public_key_from_pem_file(self):
        public_key = self.pem.set_public_key_from_pem_file()
        expected_public_key_details = {
            "kid": "<KEY>",
            "thumbprint": "stU_K9M99AU8WVS1-pHpcw02XanpwOWSwhQBQk8MaaM",
            "kty": "RSA",
            "n": "<KEY>
                 + "<KEY>"
                 + "<KEY>"
                 + "<KEY>",
            "e": "AQAB"
        }
        expected_public_key = jwk.JWK(**expected_public_key_details)
        self.assertEqual(public_key, expected_public_key)

    def test_get_pubic_key(self):
        public_key = self.pem.get_pubic_key()
        expected_public_key_details = {
            "kid": "<KEY>",
            "thumbprint": "stU_K9M99AU8WVS1-pHpcw02XanpwOWSwhQBQk8MaaM",
            "kty": "RSA",
            "n": "23_ittMCVfOApzuZWeWQk0iPFMe41lmAURF8lFTQIK6JXWHDmQUfg0_iES9NpS7oVwVucS5i0rJz09cBMQ9g9XSVYwaYPWm-2Lc2-"
                 + "pXimYCxrTFx1_eY51HlgKV9M-b-dJboyOWuGeyFUM3OVxQEB6UN5XOKHtcRFFkIYtXbBDBsbDte7dWMQYHG75TYa-37WVHbzvoJ"
                 + "Op5luK_AJrY4Z0SZgV5mGWGVz17UoilRJipXXvV7IeDXZDgTqQG1dYAXISN3ajAdkQVGgrVBf9Q4zVWrFaDq8RfrbVGbWVwFNl"
                 + "<KEY>-XDc7TegHk7dw",
            "e": "AQAB"
        }
        expected_public_key = jwk.JWK(**expected_public_key_details)
        self.assertEqual(public_key, expected_public_key)

    def test_get_private_key(self):
        self.pem.private_key_pem_file_location = "resources/keys/test/privatekey.pem"
        private_key = self.pem.set_private_key_from_pem_file()
        expected_private_key_details = {
            'd': '<KEY>'
                 'it1c3nS7OM0_YjbvcdvmNKZamzvyZQBDoIdkBXBX3sJCSK9zFCiJXkCHjGMIHgClM-FzeUo-BDlBZhILgy1mfIlFwMnzYyL1UHa88'
                 'gt61XFPD9eWEvPhnvkiYYS7904utxujYK54svF-59_yXWVyQfI7KalYedx1AlH0jF9sQ7J4WrBYYaOJhiq5gV16w5RtOoJghZ2aI'
                 'hTL9Thg0XhnlWuR_L4y79G5jwZcjKCSxCuX2O9OMQ',
            'dp': '<KEY>'
                  '<KEY>',
            'dq': '<KEY>'
                  '<KEY>',
            'e': 'AQAB',
            'kid': '<KEY>',
            'kty': 'RSA',
            'n': '43WyOeBlUTACUIdEw0HlL5N12FibPKlj9Ia_f07Rzm5V94_3QMynf2iwwzHTadHM5yku-wFcTM0LyTu6wEp6WIa9dKPdIQhMvsNA'
                 'gf9rN9KKeyb0usvZt54qOzuDPaaauY2pD2als2WNXBZd3CgrWqZmom-MPknFcfkhT4zl7LOnBbMzIn0v4sd5jjBF-xExxwkmKriu'
                 'CN_4luK7Wm5iWNTSqOiciMCOey-l3rhxDUZT8BmCE6PM8wDUercHNyoj3najQwxG09wVS2m2joQArk-y9mYfJKffIS70iyFwaD1O'
                 '7lzNPyn2Cm8FP_Z0mCg_JOHgM4ZaR63mPGk9cfRdoQ',
            'p': '<KEY>
                 '7z469lIechvmxz3NScDFgt__yySHSkTaAfkNIgd4OO2ap4SQnEUUU_kQ63BYjfxn53lg7p0M',
            'q': '<KEY>'
                 '8NaHAE8pQhooTwaiwy5e3qA2P6Woz0WVBFUy4bmtcdjtwcMSLrp95EZ5BnDQ0LKX8qkt30s',
            'qi': 'ipmXLLoJMJDYbo256jQB0p6q9hU3f8RusPoAJ354s6-3g8u19cMzAWvNMUgG2U2BEMKm6O5I3fsh5Sd4wR3xDhEzjUVkPCrHKh'
                  'rT_scHd0gljNFsp7elZ6JkhbVZXwLA-Fp08frLMFrgP2-oOQ-DS4MWZe1OauMy4e_fHt2C1mg'
        }
        expected_private_key = jwk.JWK(**expected_private_key_details)
        self.assertEqual(private_key, expected_private_key)
