Esempio n. 1
0
 def test_30b_invalid_config_not_exist(self):
     """
     Verify that missing config files are detected..
     """
     try:
         parse_config("./no-such-config-file")
         self.fail("Did not detect non-existant config file")
     except TaxiiConfigurationException as tce:
         assert 'Config File: ./no-such-config-file does not exist' in tce.args[0]
     finally:
         self._config_cleanup()
Esempio n. 2
0
 def test_30a_invalid_no_config(self):
     """
     Verify that missing config files are detected..
     """
     try:
         # noinspection PyTypeChecker
         parse_config(None)
         self.fail("Did not detect missing config file")
     except TaxiiConfigurationException as tce:
         assert 'Config File: must be specified' in tce.args[0]
     finally:
         self._config_cleanup()
Esempio n. 3
0
 def test_33b_invalid_icon_link_no_such_path(self):
     """
     Verify that site section with icon_link defined but not present will be detected.
     """
     self._make_config(icon_link="./no_such_icon.png")
     try:
         parse_config(self._config)
         self.fail("Did not detect non-existant icon_link")
     except TaxiiConfigurationException as tce:
         assert "Config File: `icon_link` for section `testsite` must exist" in tce.args[0]
     finally:
         self._config_cleanup()
Esempio n. 4
0
    def test_34b_invalid_feed_enabled_bogus(self):
        """
        Verify that site section with feed_enabled not a boolean will be detected.
        """
        self._make_config(feeds_enable="booga")

        try:
            parse_config(self._config)
            self.fail("Did not detect bogus feeds_enable")
        except TaxiiConfigurationException as tce:
            assert "Config File: `feeds_enable` for section `testsite` must be true or false" in tce.args[0]
        finally:
            self._config_cleanup()
Esempio n. 5
0
    def test_37b_invalid_reset_start_date_bogus(self):
        """
        Verify that site section with reset_start_date not a boolean will be detected.
        """
        self._make_config(reset_start_date="booga")

        try:
            parse_config(self._config)
            self.fail("Did not detect bogus reset_start_date")
        except TaxiiConfigurationException as tce:
            assert "Config File: `reset_start_date` for section `testsite` must be true or false" in tce.args[0]
        finally:
            self._config_cleanup()
Esempio n. 6
0
    def test_39b_invalid_use_https_bogus(self):
        """
        Verify that site section with use_https not a boolean will be detected.
        """
        self._make_config(use_https="booga")

        try:
            parse_config(self._config)
            self.fail("Did not detect bogus use_https")
        except TaxiiConfigurationException as tce:
            assert "Config File: `use_https` for section `testsite` must be true or false" in tce.args[0]
        finally:
            self._config_cleanup()
Esempio n. 7
0
    def test_41b_invalid_minutes_to_advance_bogus(self):
        """
        Verify that site section with minutes_to_advance not in the proper format will be detected.
        """
        self._make_config(minutes_to_advance="bogus")

        try:
            parse_config(self._config)
            self.fail("Did not detect bogus minutes_to_advance")
        except TaxiiConfigurationException as tce:
            assert "Config File: `minutes_to_advance` for section `testsite` must be an integer" in tce.args[0]
        finally:
            self._config_cleanup()
Esempio n. 8
0
    def test_32b_invalid_output_path_empty(self):
        """
        Verify that site section with empty output_path is detected.
        """
        self._make_config(output_path="")

        try:
            parse_config(self._config)
            self.fail("Did not detect empty output_path")
        except TaxiiConfigurationException as tce:
            assert "Config File: `output_path` must be defined for section `testsite`" in tce.args[0]
        finally:
            self._config_cleanup()
Esempio n. 9
0
    def test_32a_invalid_output_path_missing(self):
        """
        Verify that site section with missing site is detected.
        """
        self._make_config(output_path=None)

        try:
            parse_config(self._config)
            self.fail("Did not detect missing output_path")
        except TaxiiConfigurationException as tce:
            assert "Config File: section `testsite` has no `output_path` entry (required)" in tce.args[0]
        finally:
            self._config_cleanup()
Esempio n. 10
0
    def test_41c_invalid_minutes_to_advance_too_low(self):
        """
        Verify that site section with minutes_to_advance less than 1.
        """
        self._make_config(minutes_to_advance="0")

        try:
            parse_config(self._config)
            self.fail("Did not detect minutes_to_advance too low")
        except TaxiiConfigurationException as tce:
            assert "Config File: `minutes_to_advance` for section `testsite` must be at least 1" in tce.args[0]
        finally:
            self._config_cleanup()
Esempio n. 11
0
    def test_42b_invalid_ssl_verify_bogus(self):
        """
        Verify that site section with bogus ssl_verify  will be detected.
        """
        self._make_config(ssl_verify="bogus")

        try:
            parse_config(self._config)
            self.fail("Did not detect bogus ssl_verify")
        except TaxiiConfigurationException as tce:
            assert "Config File: `ssl_verify` for section `testsite` must be true or false" in tce.args[0]
        finally:
            self._config_cleanup()
Esempio n. 12
0
    def test_36b_invalid_default_score_bogus(self):
        """
        Verify that site section with default score not an int is properly trapped.
        """
        self._make_config(default_score="foobar")

        try:
            parse_config(self._config)
            self.fail("Did not detect bogus default_score")
        except TaxiiConfigurationException as tce:
            assert "Config File: `default_score` for section `testsite` must be an integer" in tce.args[0]
        finally:
            self._config_cleanup()
Esempio n. 13
0
    def test_47c_invalid_reports_limit_too_low(self):
        """
        Verify that site section with reports_limit less than 1.
        """
        self._make_config(reports_limit="0")

        try:
            parse_config(self._config)
            self.fail("Did not detect reports_limit too low")
        except TaxiiConfigurationException as tce:
            assert "Config File: `reports_limit` for section `testsite` must be at least 1" in tce.args[0]
        finally:
            self._config_cleanup()
Esempio n. 14
0
    def test_36e_invalid_default_score_too_high(self):
        """
        Verify that site section with default score must be at most 100, when strict enabled.
        """
        self._make_config(default_score="101")  # strict mode requires output path existance

        try:
            parse_config(self._config, strict_mode=True)
            self.fail("Did not detect bogus feeds_enable")
        except TaxiiConfigurationException as tce:
            assert "Config File: `default_score` for section `testsite` must be between 1 and 100 (inclusive)" in \
                   tce.args[0]
        finally:
            self._config_cleanup()
Esempio n. 15
0
    def test_38b_invalid_start_date_bogus(self):
        """
        Verify that site section with start_date not in the proper format will be detected.
        """
        self._make_config(start_date="2016-12-01")

        try:
            parse_config(self._config)
            self.fail("Did not detect bogus reset_start_date")
        except TaxiiConfigurationException as tce:
            assert "Config File: `start_date` for section `testsite` must be in the format `%Y-%m-%d %H:%M:%S`" in \
                   tce.args[0]
        finally:
            self._config_cleanup()
Esempio n. 16
0
    def test_40b_invalid_key_and_no_cert(self):
        """
        Verify that site section with key_file specified but no cert_file specified is detected.
        """
        self._make_config(key_file=self._key)

        try:
            parse_config(self._config)
            self.fail("Did not detect missing cert_file")
        except TaxiiConfigurationException as tce:
            assert "Config File: both `cert_file` and `key_file` for section `testsite` must be specified" in tce.args[
                0]
        finally:
            self._config_cleanup()
Esempio n. 17
0
    def test_32c_output_path_not_exists(self):
        """
        Verify that site section with output path defined but not present will have the path created
        """
        td = os.path.abspath("./nonesuch")
        if os.path.exists(td):
            os.rmdir(td)

        self._make_config(output_path=td)
        try:
            parse_config(self._config)
            assert os.path.exists(td)
        finally:
            self._config_cleanup()
            if os.path.exists(td):
                os.rmdir(td)
Esempio n. 18
0
    def test_31d_site_http_normalize(self):
        """
        Verify that site section with http:// is cleaned up.
        """
        self._make_config(site="http://testsite.com")

        check = parse_config(self._config)
        assert check['sites'][0]['site'] == "testsite.com"
Esempio n. 19
0
    def test_31e_site_trailing_slash_normalize(self):
        """
        Verify that site section with trailing / is cleaned up.
        """
        self._make_config(site="http://testsite.com/")

        check = parse_config(self._config)
        assert check['sites'][0]['site'] == "testsite.com"
Esempio n. 20
0
    def test_33a_icon_link_missing(self):
        """
        Verify that missing icon link is safely allowed with a default value of ""
        """
        self._make_config(icon_link=None)

        check = parse_config(self._config)
        assert check['sites'][0]['icon_link'] == ""
Esempio n. 21
0
    def test_32d_invalid_output_path_not_exists_strict(self):
        """
        Verify that site section with output path defined but not present, in strict mode this will stop progress.
        """
        td = os.path.abspath("./nonesuch")
        if os.path.exists(td):
            os.rmdir(td)

        self._make_config(output_path=td)
        try:
            parse_config(self._config, strict_mode=True)
            self.fail("Did not detect non-existant output_file")
        except TaxiiConfigurationException as tce:
            assert "Config File: `output_path` for section `testsite` must already exist" in tce.args[0]
        finally:
            self._config_cleanup()
            if os.path.exists(td):
                os.rmdir(td)
Esempio n. 22
0
    def test_47a_reports_limit_missing(self):
        """
        Verify that site section with reports_limit is missing will have a default value.
        """
        self._make_config(reports_limit=None)

        try:
            check = parse_config(self._config)
            assert check['sites'][0]['reports_limit'] == 10000
        finally:
            self._config_cleanup()
Esempio n. 23
0
    def test_46_ca_cert_missing(self):
        """
        Verify that site section with ca_cert is missing will have a proper default.
        """
        self._make_config(ca_cert=None)

        try:
            check = parse_config(self._config)
            assert check['sites'][0]['ca_cert'] is None
        finally:
            self._config_cleanup()
Esempio n. 24
0
    def test_45_poll_path_missing(self):
        """
        Verify that site section with poll_path is missing will have a proper default.
        """
        self._make_config(poll_path=None)

        try:
            check = parse_config(self._config)
            assert check['sites'][0]['poll_path'] == ""
        finally:
            self._config_cleanup()
Esempio n. 25
0
    def test_43_discovery_path_missing(self):
        """
        Verify that site section with discovery_path is missing will have a proper default.
        """
        self._make_config(discovery_path=None)

        try:
            check = parse_config(self._config)
            assert check['sites'][0]['discovery_path'] == "/services/discovery"
        finally:
            self._config_cleanup()
Esempio n. 26
0
    def test_42a_ssl_verify_missing(self):
        """
        Verify that site section with ssl_verify is missing will have a default of true.
        """
        self._make_config(ssl_verify=None)

        try:
            check = parse_config(self._config)
            assert check['sites'][0]['ssl_verify']
        finally:
            self._config_cleanup()
Esempio n. 27
0
    def test_41a_minutes_to_advance_missing(self):
        """
        Verify that site section with minutes_to_advance is missing will have a default of 60 minutes.
        """
        self._make_config(minutes_to_advance=None)

        try:
            check = parse_config(self._config)
            assert check['sites'][0]['minutes_to_advance'] == 60
        finally:
            self._config_cleanup()
Esempio n. 28
0
    def test_39a_use_https_missing(self):
        """
        Verify that site section with use_https missing will be default to False.
        """
        self._make_config(use_https=None)

        try:
            check = parse_config(self._config)
            assert not check['sites'][0]['use_https']
        finally:
            self._config_cleanup()
Esempio n. 29
0
    def test_36a_default_score_missing(self):
        """
        Verify that site section with default score is missing will be converted to 50.
        """
        self._make_config(default_score=None)

        try:
            check = parse_config(self._config)
            assert check['sites'][0]['default_score'] == 50
        finally:
            self._config_cleanup()
Esempio n. 30
0
    def test_36c_default_score_excessive(self):
        """
        Verify that site section with default score outside of 1-100 is allowed, if not strict mode.
        """
        self._make_config(default_score="150")

        try:
            check = parse_config(self._config)
            assert check['sites'][0]['default_score'] == 150
        finally:
            self._config_cleanup()