Exemplo n.º 1
0
 def test_valid_repo_data(self):
     self.mfs = mockfs.replace_builtins()
     self.mfs.add_entries({jimmy_schema_path: self.jimmy_schema,
                           jimmy_yaml_path: self.mock_jimmy_yaml})
     schema = yaml_reader.read(jimmy_schema_path)
     repo_data = yaml_reader.read(jimmy_yaml_path)
     jsonschema.validate(repo_data, schema)
Exemplo n.º 2
0
 def test_valid_repo_data(self):
     self.mfs = mockfs.replace_builtins()
     self.mfs.add_entries({
         jimmy_schema_path: self.jimmy_schema,
         jimmy_yaml_path: self.mock_jimmy_yaml
     })
     schema = yaml_reader.read(jimmy_schema_path)
     repo_data = yaml_reader.read(jimmy_yaml_path)
     jsonschema.validate(repo_data, schema)
Exemplo n.º 3
0
 def test_validation_fail_for_additional_properties(self):
     with open(jimmy_yaml_path, 'r') as f:
         jimmy_yaml = f.read()
         mock_jimmy_yaml = "\n".join([jimmy_yaml, "test:\n"])
     self.mfs = mockfs.replace_builtins()
     self.mfs.add_entries({jimmy_yaml_path: mock_jimmy_yaml,
                           jimmy_schema_path: self.jimmy_schema})
     schema = yaml_reader.read(jimmy_schema_path)
     jimmy_yaml_data = yaml_reader.read(jimmy_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(jimmy_yaml_data, schema)
     assert excinfo.value.message == "Additional properties are not allowed ('test' was unexpected)"
Exemplo n.º 4
0
 def test_validation_fail_for_additional_properties(self):
     with open(jimmy_yaml_path, 'r') as f:
         jimmy_yaml = f.read()
         mock_jimmy_yaml = "\n".join([jimmy_yaml, "test:\n"])
     self.mfs = mockfs.replace_builtins()
     self.mfs.add_entries({
         jimmy_yaml_path: mock_jimmy_yaml,
         jimmy_schema_path: self.jimmy_schema
     })
     schema = yaml_reader.read(jimmy_schema_path)
     jimmy_yaml_data = yaml_reader.read(jimmy_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(jimmy_yaml_data, schema)
     assert excinfo.value.message == "Additional properties are not allowed ('test' was unexpected)"
Exemplo n.º 5
0
 def test_ldap_validation_fail_if_access_name_is_not_string(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'ldap:',
           '  server: ldap://mirantis.com:3268',
           '  root_bind:',
           '    dn: dc=mirantis,dc=com',
           '    allow_blank: false',
           '  search:',
           '    user_filter: userPrincipalName={0}',
           '  manager:',
           '    name: [email protected]',
           '    password: passwd',
           '  access:',
           '  - name: 123',
           '    permissions:',
           '    - overall',
           '    - credentials',
           '    - gerrit',
           'cli_user:'******'  name: jenkins-manager',
           '  public_key: ssh-rsa AAB'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "123 is not of type 'string'"
Exemplo n.º 6
0
 def test_valid_oneof_ldap_data(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'ldap:',
           '  server: ldap://mirantis.com:3268',
           '  root_bind:',
           '    dn: dc=mirantis,dc=com',
           '    allow_blank: false',
           '  search:',
           '    user_filter: userPrincipalName={0}',
           '  manager:',
           '    name: [email protected]',
           '    password: passwd',
           '  access:',
           '  - name: amihura',
           '    permissions:',
           '    - overall',
           '    - credentials',
           '    - gerrit',
           'cli_user:'******'  name: jenkins-manager',
           '  public_key: sssh-rsa AAAAB3NzaC'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 7
0
 def setup_method(self, method):
     with open(pipeline_libraries_schema_path, 'r') as f:
         mock_pipeline_libraries_schema = f.read()
     self.mfs = mockfs.replace_builtins()
     self.mfs.add_entries(
         {pipeline_libraries_schema_path: mock_pipeline_libraries_schema})
     self.schema = yaml_reader.read(pipeline_libraries_schema_path)
Exemplo n.º 8
0
 def test_validation_fail_if_libraries_is_not_array(self):
     self.mfs.add_entries(
         {jenkins_yaml_path: '\n'.join(['libraries: 123'])})
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "123 is not of type 'array'"
Exemplo n.º 9
0
 def test_validation_fail_for_unsecured_additional_properties(self):
     self.mfs.add_entries(
         {jenkins_yaml_path: '\n'.join(['unsecured: true', 'test: test'])})
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "Additional properties are not allowed ('test' was unexpected)"
Exemplo n.º 10
0
 def test_ldap_validation_fail_if_permissions_not_enum(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'ldap:',
           '  server: ldap://mirantis.com:3268',
           '  root_bind:',
           '    dn: dc=mirantis,dc=com',
           '    allow_blank: false',
           '  search:',
           '    user_filter: userPrincipalName={0}',
           '  manager:',
           '    name: [email protected]',
           '    password: passwd',
           '  access:',
           '  - name: test',
           '    permissions:',
           '    - test',
           '    - credentials',
           '    - gerrit',
           'cli_user:'******'  name: jenkins-manager',
           '  public_key: sssh-rsa AAAAB3NzaC'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'test' is not one of " \
                                     "['overall', 'credentials', 'gerrit', 'manage-ownership', " \
                                     "'slave', 'job', 'run', 'view', 'scm']"
Exemplo n.º 11
0
 def test_validation_fail_if_unsecured_not_bool(self):
     self.mfs.add_entries(
         {jenkins_yaml_path: '\n'.join(['unsecured: 123'])})
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "123 is not of type 'boolean'"
Exemplo n.º 12
0
 def test_valid_oneof_unsecured_data(self):
     self.mfs.add_entries(
         {jenkins_yaml_path: '\n'.join([
             'unsecured: true',
         ])})
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 13
0
 def setup_method(self, method):
     with open(credentials_schema_path, 'r') as f:
         mock_credentials_schema = f.read()
     self.mfs = mockfs.replace_builtins()
     self.mfs.add_entries(
         {credentials_schema_path: mock_credentials_schema})
     self.schema = yaml_reader.read(credentials_schema_path)
Exemplo n.º 14
0
 def test_validation_fail_for_host_required_property(self):
     self.mfs.add_entries(
         {jenkins_yaml_path: '\n'.join(['enable: True', 'port: 4730'])})
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'host' is a required property"
Exemplo n.º 15
0
 def test_valid_oneof_unsecured_data(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'unsecured: true',
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 16
0
 def test_validation_fail_if_host_is_not_string(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join(['host: 123', 'enable: True', 'port: 4730'])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "123 is not of type 'string'"
Exemplo n.º 17
0
    def test_validation_fail_for_envs_required_property(self):

        # Create config without envs entry
        with open(jimmy_yaml_path, 'r') as f:
            mock_jimmy_yaml = ""
            for line in f:
                if line.startswith("envs:"):
                    break
                mock_jimmy_yaml += line

        self.mfs = mockfs.replace_builtins()
        self.mfs.add_entries({jimmy_yaml_path: mock_jimmy_yaml,
                              jimmy_schema_path: self.jimmy_schema})
        schema = yaml_reader.read(jimmy_schema_path)
        jimmy_yaml_data = yaml_reader.read(jimmy_yaml_path)
        with pytest.raises(jsonschema.ValidationError) as excinfo:
            jsonschema.validate(jimmy_yaml_data, schema)
        assert excinfo.value.message == "'envs' is a required property"
Exemplo n.º 18
0
 def test_validation_fail_for_pipelines_required_property(self):
     self.mfs = mockfs.replace_builtins()
     self.mfs.add_entries({
         jimmy_schema_path:
         self.jimmy_schema,
         jimmy_yaml_path:
         '\n'.join([
             'module-directories:', '  - ./modules', 'defaults:',
             '  inject:',
             '    jenkins_cli_path: /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar',
             'setup:', '  - name: setup', 'teardown:', '  - name: teardown',
             'envs:', '  main:', '    jenkins_url: http://localhost:8080'
         ])
     })
     schema = yaml_reader.read(jimmy_schema_path)
     jimmy_yaml_data = yaml_reader.read(jimmy_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(jimmy_yaml_data, schema)
     assert excinfo.value.message == "'pipelines' is a required property"
Exemplo n.º 19
0
 def test_validation_fail_if_unsecured_not_bool(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'unsecured: 123'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "123 is not of type 'boolean'"
Exemplo n.º 20
0
 def test_valid_repo_data(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'host: zuul01-test.infra.mirantis.net',
           'enable: True',
           'port: 4730'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 21
0
 def test_validation_fail_if_libraries_is_not_array(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'libraries: 123'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "123 is not of type 'array'"
Exemplo n.º 22
0
 def test_valid_repo_data(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'user:'******'  email: [email protected]',
           '  name: Jenkins'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 23
0
 def test_valid_oneof_ssh_data(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join([
             '    ssh:', '    - scope: global', '      username: user2',
             '      private_key: /home/user/.ssh/id_rsa'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 24
0
 def test_ssh_validation_fail_for_private_key_required_property(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join(
             ['    ssh:', '    - scope: global', '      username: user2'])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'private_key' is a required property"
Exemplo n.º 25
0
    def test_fails_if_node_is_set_but_envvars_are_empty(self):
        self.mfs.add_entries({
            jenkins_yaml_path:
            '\n'.join(['  node1: {}', '  node2:', '    -label1'])
        })
        node_envvars_data = yaml_reader.read(jenkins_yaml_path)

        with pytest.raises(jsonschema.ValidationError) as excinfo:
            jsonschema.validate(node_envvars_data, self.schema)
        assert excinfo.value.message == "{} does not have enough properties"
Exemplo n.º 26
0
 def test_file_validation_fail_for_file_required_property(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join(
             ['    file:', '    - scope: global', '      id: secret-key'])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'file' is a required property"
Exemplo n.º 27
0
 def test_valid_data(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join([
             '  node1:', '    -label1', '    -label2', '  node2:',
             '    -label1'
         ])
     })
     node_envvars_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(node_envvars_data, self.schema)
Exemplo n.º 28
0
 def test_valid_repo_data(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join([
             'host: zuul01-test.infra.mirantis.net', 'enable: True',
             'port: 4730'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 29
0
 def test_validation_fail_for_host_required_property(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'enable: True',
           'port: 4730'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'host' is a required property"
Exemplo n.º 30
0
    def test_validation_fail_for_envs_required_property(self):

        # Create config without envs entry
        with open(jimmy_yaml_path, 'r') as f:
            mock_jimmy_yaml = ""
            for line in f:
                if line.startswith("envs:"):
                    break
                mock_jimmy_yaml += line

        self.mfs = mockfs.replace_builtins()
        self.mfs.add_entries({
            jimmy_yaml_path: mock_jimmy_yaml,
            jimmy_schema_path: self.jimmy_schema
        })
        schema = yaml_reader.read(jimmy_schema_path)
        jimmy_yaml_data = yaml_reader.read(jimmy_yaml_path)
        with pytest.raises(jsonschema.ValidationError) as excinfo:
            jsonschema.validate(jimmy_yaml_data, schema)
        assert excinfo.value.message == "'envs' is a required property"
Exemplo n.º 31
0
 def test_validation_fail_for_name_required_property(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'user:'******'  email: [email protected]',
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'name' is a required property"
Exemplo n.º 32
0
 def test_validation_fail_for_unsecured_additional_properties(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'unsecured: true',
           'test: test'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "Additional properties are not allowed ('test' was unexpected)"
Exemplo n.º 33
0
 def test_valid_oneof_ssh_data(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           '    ssh:',
           '    - scope: global',
           '      username: user2',
           '      private_key: /home/user/.ssh/id_rsa'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 34
0
 def test_valid_oneof_token_data(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join([
             '    token:', '    - scope: global', '      username: user',
             '      description: test token credentials',
             '      id: this-is-token-credentials-id'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 35
0
 def test_valid_oneof_file_data(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join([
             '    file:', '    - scope: global', '      id: secret-key',
             '      file: /home/user/secret_key',
             '      description: Secret key'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 36
0
 def test_validation_fail_for_file_additional_properties(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join([
             '    file:', '    - scope: global', '      id: secret-key',
             '      file: /home/user/secret_file', '      test: test'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "Additional properties are not allowed ('test' was unexpected)"
Exemplo n.º 37
0
 def test_validation_fail_for_ssh_additional_properties(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join([
             '    ssh:', '    - scope: global', '      username: user2',
             '      private_key: /home/user/.ssh/id_rsa', '      test: test'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "Additional properties are not allowed ('test' was unexpected)"
Exemplo n.º 38
0
 def test_token_validation_fail_for_id_required_property(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join([
             '    token:', '    - scope: global', '      username: user',
             '      description: test token credentials'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'id' is a required property"
Exemplo n.º 39
0
 def test_validation_fail_for_password_required_property(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           '    basic_auth:',
           '    - key_name: testauth',
           '      username: user'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'password' is a required property"
Exemplo n.º 40
0
 def test_validation_fail_if_name_is_not_string(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'user:'******'  email: [email protected]',
           '  name: 123'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "123 is not of type 'string'"
Exemplo n.º 41
0
 def test_validation_fail_if_file_is_not_string(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join([
             '    file:', '    - scope: global', '      id: secret-key',
             '      file: 123', '      description: Secret key'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "123 is not of type 'string'"
Exemplo n.º 42
0
 def test_validation_fail_if_private_key_is_not_string(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join([
             '    ssh:', '    - scope: system', '      username: user2',
             '      passphrase: psprs', '      private_key: 123'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "123 is not of type 'string'"
Exemplo n.º 43
0
 def test_validation_fail_if_descr_is_not_string(self):
     self.mfs.add_entries({
         jenkins_yaml_path:
         '\n'.join([
             '    password:'******'    - scope: global', '      username: user',
             '      password: passwd', '      description: 123'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "123 is not of type 'string'"
Exemplo n.º 44
0
 def test_validation_fail_if_host_is_not_string(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'host: 123',
           'enable: True',
           'port: 4730'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "123 is not of type 'string'"
Exemplo n.º 45
0
 def test_ssh_validation_fail_for_private_key_required_property(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           '    ssh:',
           '    - scope: global',
           '      username: user2'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'private_key' is a required property"
Exemplo n.º 46
0
 def test_file_validation_fail_for_file_required_property(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           '    file:',
           '    - scope: global',
           '      id: secret-key'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'file' is a required property"
Exemplo n.º 47
0
 def test_valid_oneof_file_data(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           '    file:',
           '    - scope: global',
           '      id: secret-key',
           '      file: /home/user/secret_key',
           '      description: Secret key'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 48
0
 def test_valid_oneof_token_data(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           '    token:',
           '    - scope: global',
           '      username: user',
           '      description: test token credentials',
           '      id: this-is-token-credentials-id'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 49
0
 def test_validation_fail_if_port_is_not_number(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'host: zuul01-test.infra.mirantis.net',
           'enable: True',
           'port: test'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'test' is not of type 'number'"
Exemplo n.º 50
0
 def test_password_validation_fail_for_username_property(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           '    password:'******'    - scope: global',
           '      password: passwd',
           '      description: test username/password user'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'username' is a required property"
Exemplo n.º 51
0
 def test_validation_fail_if_password_is_not_string(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           '    basic_auth:',
           '    - key_name: testauth',
           '      username: user',
           '      password: 123'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "123 is not of type 'string'"
Exemplo n.º 52
0
 def test_token_validation_fail_for_id_required_property(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           '    token:',
           '    - scope: global',
           '      username: user',
           '      description: test token credentials'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'id' is a required property"
Exemplo n.º 53
0
 def test_validation_fail_for_additional_properties(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'user:'******'  email: [email protected]',
           '  name: Jenkins',
           '  test: 123'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "Additional properties are not allowed ('test' was unexpected)"
Exemplo n.º 54
0
 def test_valid_repo_data(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'servers:',
           '  - username: test-username',
           '    url: http://test.com',
           '    servername: test-gerrit-name',
           '    hostname: test-hostname',
           '    auth_key: /var/lib/jenkins/.ssh/id_rsa'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 55
0
 def test_valid_repo_data(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           'admin_email: CI <*****@*****.**>',
           'agent_tcp_port: 50000',
           'location_url: http://example.com/jenkins/',
           'markup_format: raw-html',
           'num_of_executors: 2',
           'scm_checkout_retry_count: 1'
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     jsonschema.validate(repo_data, self.schema)
Exemplo n.º 56
0
 def test_file_validation_fail_if_scope_is_not_enum(self):
     self.mfs.add_entries({jenkins_yaml_path: '\n'.join(
         [
           '    file:',
           '    - scope: test',
           '      id: secret-key',
           '      file: /home/user/secret_key',
         ])
     })
     repo_data = yaml_reader.read(jenkins_yaml_path)
     with pytest.raises(jsonschema.ValidationError) as excinfo:
         jsonschema.validate(repo_data, self.schema)
     assert excinfo.value.message == "'test' is not one of ['global', 'system']"