<commit_before>import unittest
from sslyze.plugins.hsts_plugin import HstsPlugin
from sslyze.server_connectivity import ServerConnectivityInfo


class HstsPluginTestCase(unittest.TestCase):

    def test_hsts_enabled(self):
        server_info = ServerConnectivityInfo(hostname='hsts.badssl.com')
        server_info.test_connectivity_to_server()

        plugin = HstsPlugin()
        plugin_result = plugin.process_task(server_info, 'hsts')

        self.assertTrue(plugin_result.hsts_header)

        self.assertTrue(plugin_result.as_text())
        self.assertTrue(plugin_result.as_xml())

    def test_hsts_disabled(self):
        server_info = ServerConnectivityInfo(hostname='www.google.com')
        server_info.test_connectivity_to_server()

        plugin = HstsPlugin()
        plugin_result = plugin.process_task(server_info, 'hsts')

        self.assertFalse(plugin_result.hsts_header)

        self.assertTrue(plugin_result.as_text())
        self.assertTrue(plugin_result.as_xml())<commit_msg>Add tests for HPKP<commit_after>import unittest
from sslyze.plugins.hsts_plugin import HstsPlugin
from sslyze.server_connectivity import ServerConnectivityInfo


class HstsPluginTestCase(unittest.TestCase):

    def test_hsts_enabled(self):
        server_info = ServerConnectivityInfo(hostname='hsts.badssl.com')
        server_info.test_connectivity_to_server()

        plugin = HstsPlugin()
        plugin_result = plugin.process_task(server_info, 'hsts')

        self.assertTrue(plugin_result.hsts_header)

        self.assertTrue(plugin_result.as_text())
        self.assertTrue(plugin_result.as_xml())

    def test_hsts_and_hpkp_disabled(self):
        server_info = ServerConnectivityInfo(hostname='www.google.com')
        server_info.test_connectivity_to_server()

        plugin = HstsPlugin()
        plugin_result = plugin.process_task(server_info, 'hsts')

        self.assertFalse(plugin_result.hsts_header)
        self.assertFalse(plugin_result.hpkp_header)

        self.assertTrue(plugin_result.as_text())
        self.assertTrue(plugin_result.as_xml())

    def test_hpkp_enabled(self):
        server_info = ServerConnectivityInfo(hostname='madavi.de')
        server_info.test_connectivity_to_server()

        plugin = HstsPlugin()
        plugin_result = plugin.process_task(server_info, 'hsts')

        self.assertTrue(plugin_result.hpkp_header)
        self.assertTrue(plugin_result.verified_certificate_chain)

        self.assertTrue(plugin_result.as_text())
        self.assertTrue(plugin_result.as_xml())
{'fraction_non_alphanumeric': 0.08919449901768173, 'fraction_numerical': 0.0, 'mean_word_length': 4.001964636542239, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '632201', 'n_tokens_mistral': 771, 'n_tokens_neox': 767, 'n_words': 93}