示例#1
0
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()
    }
示例#2
0
文件: utils.py 项目: dcos/dcos
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,
    }
示例#3
0
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,
    }
示例#4
0
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])
示例#5
0
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
示例#6
0
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,
    }
示例#7
0
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
示例#8
0
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',
        }
    }
示例#9
0
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',
        }
    }
示例#10
0
    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
示例#11
0
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'
        }
    }
示例#12
0
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()
    }
示例#13
0
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'
        }
    }
示例#14
0
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
示例#16
0
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'
            }
        }
示例#17
0
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)
示例#18
0
 def testTwo(self):
     self.failUnless(mod.validate("abcdef6","abcdef6"))      #testing a valid string
示例#19
0
 def testOne(self):
     self.failUnless(mod.validate("abc345def6","abc345def6"))    #testing a valid string
示例#20
0
 def testTwelve(self):
     self.failIf(mod.validate("**_&&","**_&&"))          #testing strings consisting of only special characters
示例#21
0
 def testEleven(self):
     self.failIf(mod.validate("",""))                    #testing empty strings
示例#22
0
def validate_ok(new_arguments):
    assert gen.validate(arguments=make_arguments(new_arguments)) == {
        'status': 'ok',
    }
示例#23
0
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,
    }
示例#24
0
 def testEight(self):
     self.failIf(mod.validate("123","123"))      #testing strings smaller in length and having only numbers        
示例#25
0
 def testSeven(self):
     self.failIf(mod.validate("abc","abc"))      #testing strings smaller in length and having only alphabets       
示例#26
0
 def testSix(self):
     self.failIf(mod.validate("1234567","1234567"))  #testing strings consisting of only numerics        
示例#27
0
 def testFive(self):
     self.failIf(mod.validate("abcdefg","abcdefg"))  #testing strings consisting of only alphabets               
示例#28
0
 def testFour(self):
     self.failIf(mod.validate("abc34","abc34"))      #testing strings of length 6 or less        
示例#29
0
 def testThree(self):
     self.failIf(mod.validate("abcdef45","ghijkl45"))        #testing strings that do not match       
示例#30
0
def validate_helper(arguments):
    return gen.validate(arguments=arguments)
示例#31
0
 def testNine(self):
     self.failIf(mod.validate("ab_cde34*","ab_cde34*"))      #testing strings containing special characters with alpha-numeric fields
示例#32
0
def validate_success(new_arguments, key):
    assert gen.validate(arguments=make_arguments(new_arguments)) == {
        'status': 'ok',
    }
示例#33
0
 def testTen(self):
     self.failIf(mod.validate("abcde34","abcde3*"))      #testing a valid string with a invalid string(do not match)
示例#34
0
文件: utils.py 项目: bernadinm/dcos
def validate_success(new_arguments):
    assert gen.validate(arguments=make_arguments(new_arguments)) == {
        'status': 'ok',
    }
示例#35
0
def validate_helper(arguments):
    return gen.validate(arguments=arguments)