def test_error_during_validate_calico_network(monkeypatch): monkeypatch.setenv('BOOTSTRAP_ID', 'foobar') logger = logging.getLogger() logger.setLevel(logging.DEBUG) assert gen.validate( { 'bootstrap_url': '', 'bootstrap_variant': '', 'ip_detect_contents': '', # so that ip_detect_filename doesn't get used from onprem_source 'ip6_detect_contents': '', 'exhibitor_storage_backend': 'static', 'master_discovery': 'static', 'cluster_name': 'foobar', 'master_list': '["127.0.0.1"]', 'calico_network_cidr': '', }, extra_sources=[onprem_source] ) == { 'status': 'errors', 'errors': { 'calico_network_cidr': { 'message': 'Incorrect value for `calico_network_cidr`: ``. Only IPv4 subnets are allowed' }, 'bootstrap_url': { 'message': 'Should be a url (http://example.com/bar or file:///path/to/local/cache)' } }, 'unset': set() }
def validate_error(new_arguments, key, message, unset=None): arguments = make_arguments(new_arguments) validate_result = gen.validate(arguments=arguments) assert validate_result == { 'status': 'errors', 'errors': {key: {'message': message}}, 'unset': set() if unset is None else unset, }
def test_error_during_validate_calico_network(monkeypatch): monkeypatch.setenv('BOOTSTRAP_ID', 'foobar') logger = logging.getLogger() logger.setLevel(logging.DEBUG) err_msg = "'' does not appear to be an IPv4 or IPv6 network" with pytest.raises(ValueError, match=err_msg): gen.validate({ 'bootstrap_url': '', 'bootstrap_variant': '', 'ip_detect_contents': '', # so that ip_detect_filename doesn't get used from onprem_source 'ip6_detect_contents': '', 'exhibitor_storage_backend': 'static', 'master_discovery': 'static', 'cluster_name': 'foobar', 'master_list': '["127.0.0.1"]', 'calico_network_cidr': '', }, extra_sources=[onprem_source])
def test_adminrouter_ui_x_frame_options_validation(value): new_arguments = {'adminrouter_x_frame_options': value} expected_error_msg = ( 'X-Frame-Options must be set to one of DENY, SAMEORIGIN, ALLOW-FROM' ) result = gen.validate(arguments=make_arguments(new_arguments)) assert result['status'] == 'errors' assert result['errors']['adminrouter_x_frame_options']['message'] == expected_error_msg
def validate_error_multikey(new_arguments, keys, message, unset=None): assert gen.validate(arguments=make_arguments(new_arguments)) == { 'status': 'errors', 'errors': {key: { 'message': message } for key in keys}, 'unset': set() if unset is None else unset, }
def test_adminrouter_ui_x_frame_options_validation(value): new_arguments = {'adminrouter_x_frame_options': value} expected_error_msg = ( 'X-Frame-Options must be set to one of DENY, SAMEORIGIN, ALLOW-FROM') result = gen.validate(arguments=make_arguments(new_arguments)) assert result['status'] == 'errors' assert result['errors']['adminrouter_x_frame_options'][ 'message'] == expected_error_msg
def test_error_during_validate(): logger = logging.getLogger() logger.setLevel(logging.DEBUG) assert gen.validate({ 'bootstrap_url': '', 'bootstrap_variant': '' }) == { 'status': 'errors', 'errors': { 'bootstrap_url': {'message': 'Should be a url (http://example.com/bar or file:///path/to/local/cache)'} }, 'unset': { 'provider', } }
def test_error_during_validate(): logger = logging.getLogger() logger.setLevel(logging.DEBUG) assert gen.validate({ 'bootstrap_url': '', 'bootstrap_variant': '' }) == { 'status': 'errors', 'errors': { 'bootstrap_url': { 'message': 'Should be a url (http://example.com/bar or file:///path/to/local/cache)' } }, 'unset': { 'provider', } }
def test_no_tls_version_enabled(self): """ Not setting the `adminrouter_tls_version_override` or any of the TLS version configuration options results in error. """ new_arguments = {'adminrouter_tls_1_0_enabled': 'false', 'adminrouter_tls_1_1_enabled': 'false', 'adminrouter_tls_1_2_enabled': 'false'} expected_error_msg = ( 'At least one of adminrouter_tls_1_0_enabled, ' 'adminrouter_tls_1_1_enabled and adminrouter_tls_1_2_enabled must ' "be set to 'true'." ) result = gen.validate(arguments=make_arguments(new_arguments)) assert result['status'] == 'errors' key = 'adminrouter_tls_1_2_enabled' assert result['errors'][key]['message'] == expected_error_msg
def test_error_during_calc(monkeypatch): monkeypatch.setenv('BOOTSTRAP_ID', 'foobar') logger = logging.getLogger() logger.setLevel(logging.DEBUG) assert gen.validate({ 'ip_detect_filename': 'not-a-existing-file', 'bootstrap_variant': '' }, extra_sources=[onprem_source]) == { 'status': 'errors', 'errors': { 'ip_detect_contents': {'message': 'ip-detect script `not-a-existing-file` must exist'} }, 'unset': { 'bootstrap_url', 'cluster_name', 'exhibitor_storage_backend', 'master_discovery' } }
def test_error_during_validate(monkeypatch): monkeypatch.setenv('BOOTSTRAP_ID', 'foobar') logger = logging.getLogger() logger.setLevel(logging.DEBUG) assert gen.validate({ 'bootstrap_url': '', 'bootstrap_variant': '', 'ip_detect_contents': '', # so that ip_detect_filename doesn't get used from onprem_source 'exhibitor_storage_backend': 'static', 'master_discovery': 'static', 'cluster_name': 'foobar', 'master_list': '["127.0.0.1"]', }, extra_sources=[onprem_source]) == { 'status': 'errors', 'errors': { 'bootstrap_url': {'message': 'Should be a url (http://example.com/bar or file:///path/to/local/cache)'}, }, 'unset': set() }
def test_error_during_calc(): logger = logging.getLogger() logger.setLevel(logging.DEBUG) assert gen.validate({ 'ip_detect_filename': 'not-a-existing-file', 'provider': 'onprem', 'bootstrap_variant': '' }) == { 'status': 'errors', 'errors': { 'ip_detect_contents': { 'message': 'ip-detect script: not-a-existing-file must exist' } }, 'unset': { 'bootstrap_id', 'bootstrap_url', 'cluster_name', 'exhibitor_storage_backend', 'master_discovery' } }
def test_error_during_calc(monkeypatch): monkeypatch.setenv('BOOTSTRAP_ID', 'foobar') logger = logging.getLogger() logger.setLevel(logging.DEBUG) assert gen.validate({ 'ip_detect_filename': 'not-a-existing-file', 'bootstrap_variant': '', }, extra_sources=[onprem_source]) == { 'status': 'errors', 'errors': { 'ip_detect_contents': {'message': 'ip-detect script `not-a-existing-file` must exist'} }, 'unset': { 'bootstrap_url', 'cluster_name', 'exhibitor_storage_backend', 'master_discovery' } }
def test_no_tls_version_enabled(self): """ Not setting the `adminrouter_tls_version_override` or any of the TLS version configuration options results in error. """ new_arguments = { 'adminrouter_tls_1_0_enabled': 'false', 'adminrouter_tls_1_1_enabled': 'false', 'adminrouter_tls_1_2_enabled': 'false' } expected_error_msg = ( 'At least one of adminrouter_tls_1_0_enabled, ' 'adminrouter_tls_1_1_enabled and adminrouter_tls_1_2_enabled must ' "be set to 'true'.") result = gen.validate(arguments=make_arguments(new_arguments)) assert result['status'] == 'errors' key = 'adminrouter_tls_1_2_enabled' assert result['errors'][key]['message'] == expected_error_msg
def test_error_during_calc(): logger = logging.getLogger() logger.setLevel(logging.DEBUG) assert gen.validate({ 'ip_detect_filename': 'not-a-existing-file', 'provider': 'onprem', 'bootstrap_variant': '' }) == { 'status': 'errors', 'errors': { 'ip_detect_contents': {'message': 'ip-detect script: not-a-existing-file must exist'} }, 'unset': { 'bootstrap_id', 'bootstrap_url', 'cluster_name', 'exhibitor_storage_backend', 'master_discovery' } }
def do_validate_gen_config(gen_config): # run validate first as this is the only way we have for now to remove "optional" keys gen_config.update(get_gen_extra_args()) return gen.validate(arguments=gen_config)
def testTwo(self): self.failUnless(mod.validate("abcdef6","abcdef6")) #testing a valid string
def testOne(self): self.failUnless(mod.validate("abc345def6","abc345def6")) #testing a valid string
def testTwelve(self): self.failIf(mod.validate("**_&&","**_&&")) #testing strings consisting of only special characters
def testEleven(self): self.failIf(mod.validate("","")) #testing empty strings
def validate_ok(new_arguments): assert gen.validate(arguments=make_arguments(new_arguments)) == { 'status': 'ok', }
def validate_error_multikey(new_arguments, keys, message, unset=None): assert gen.validate(arguments=make_arguments(new_arguments)) == { 'status': 'errors', 'errors': {key: {'message': message} for key in keys}, 'unset': set() if unset is None else unset, }
def testEight(self): self.failIf(mod.validate("123","123")) #testing strings smaller in length and having only numbers
def testSeven(self): self.failIf(mod.validate("abc","abc")) #testing strings smaller in length and having only alphabets
def testSix(self): self.failIf(mod.validate("1234567","1234567")) #testing strings consisting of only numerics
def testFive(self): self.failIf(mod.validate("abcdefg","abcdefg")) #testing strings consisting of only alphabets
def testFour(self): self.failIf(mod.validate("abc34","abc34")) #testing strings of length 6 or less
def testThree(self): self.failIf(mod.validate("abcdef45","ghijkl45")) #testing strings that do not match
def validate_helper(arguments): return gen.validate(arguments=arguments)
def testNine(self): self.failIf(mod.validate("ab_cde34*","ab_cde34*")) #testing strings containing special characters with alpha-numeric fields
def validate_success(new_arguments, key): assert gen.validate(arguments=make_arguments(new_arguments)) == { 'status': 'ok', }
def testTen(self): self.failIf(mod.validate("abcde34","abcde3*")) #testing a valid string with a invalid string(do not match)
def validate_success(new_arguments): assert gen.validate(arguments=make_arguments(new_arguments)) == { 'status': 'ok', }