コード例 #1
0
    def test_add_tasks_description_and_empty_playbook_description(self):
        """
        Given:
            - A playbook file with missing playbook description and missing tasks descriptions.

        When:
            - Running the add_description function of update_playbook.py.
            - User's choice not to update the description of the playbook.

        Then:
            - Validate that an empty description was added to the file.
            - Validate that empty descriptions were added only to the desired tasks.
        """
        schema_path = os.path.normpath(
            os.path.join(__file__, "..", "..", "..", "common", "schemas", '{}.yml'.format('playbook')))
        base_yml = PlaybookYMLFormat(SOURCE_FORMAT_PLAYBOOK_COPY, path=schema_path, verbose=True)
        base_yml.data = {
            "tasks": {
                "1": {
                    "type": "playbook",
                    "task": {
                    }
                },
                "2": {
                    "type": "something",
                    "task": {
                        "description": "else"
                    }
                },
                "3": {
                    "type": "something",
                    "task": {
                    }
                },
                "4": {
                    "type": "playbook",
                    "task": {
                    }
                },
                "5": {
                    "type": "start",
                    "task": {
                    }
                },
                "6": {
                    "type": "title",
                    "task": {
                    }
                },
            }
        }
        base_yml.add_description()
        assert base_yml.data.get('description') == ''
        assert base_yml.data['tasks']['1']['task']['description'] == ''
        assert base_yml.data['tasks']['2']['task']['description'] == 'else'
        assert 'description' not in base_yml.data['tasks']['3']['task']
        assert base_yml.data['tasks']['4']['task']['description'] == ''
        assert base_yml.data['tasks']['5']['task']['description'] == ''
        assert base_yml.data['tasks']['6']['task']['description'] == ''
コード例 #2
0
def test_playbook_task_description_name(source_path):
    base_yml = PlaybookYMLFormat(source_path)
    base_yml.add_description()
    base_yml.update_playbook_task_name()

    assert 'description' in base_yml.yml_data['tasks']['7']['task']
    assert base_yml.yml_data['tasks']['29']['task']['name'] == 'File Enrichment - Virus Total Private API'
    assert base_yml.yml_data['tasks']['25']['task']['description'] == 'Check if there is a SHA256 hash in context.'
コード例 #3
0
def test_playbook_task_description_name(source_path):
    schema_path = os.path.normpath(
        os.path.join(__file__, "..", "..", "..", "common", "schemas", '{}.yml'.format('playbook')))
    base_yml = PlaybookYMLFormat(source_path, path=schema_path)
    base_yml.add_description()
    base_yml.update_playbook_task_name()
    base_yml.remove_copy_and_dev_suffixes_from_subplaybook()

    assert 'description' in base_yml.data['tasks']['7']['task']
    assert base_yml.data['tasks']['29']['task']['name'] == 'File Enrichment - Virus Total Private API'
    assert base_yml.data['tasks']['25']['task']['description'] == 'Check if there is a SHA256 hash in context.'
コード例 #4
0
def test_add_playbook_description(user_input):
    """
    Given:
        - A playbook file with missing playbook description and missing tasks descriptions.

    When:
        - Running the add_description function of update_playbook.py.
        - User's choice to update the description of the playbook with the description: 'User-entered description'.

    Then:
        - Validate that a description field with the given description message was added to the file.
        - Validate that empty descriptions were added only to the desired tasks.
    """
    user_responses = [Mock(), Mock(), Mock()]
    user_responses[0] = 'err'  # test invalid input by user
    user_responses[1] = 'y'
    user_responses[2] = 'User-entered description'
    user_input.side_effect = user_responses

    schema_path = os.path.normpath(
        os.path.join(__file__, "..", "..", "..", "common", "schemas",
                     '{}.yml'.format('playbook')))
    base_yml = PlaybookYMLFormat(SOURCE_FORMAT_PLAYBOOK_COPY,
                                 path=schema_path,
                                 verbose=True)
    base_yml.data = {
        "tasks": {
            "1": {
                "type": "playbook",
                "task": {}
            },
            "2": {
                "type": "something",
                "task": {
                    "description": "else"
                }
            },
            "3": {
                "type": "something",
                "task": {}
            },
        }
    }
    base_yml.add_description()
    assert base_yml.data.get('description') == 'User-entered description'
    assert base_yml.data['tasks']['1']['task']['description'] == ''
    assert base_yml.data['tasks']['2']['task']['description'] == 'else'
    assert 'description' not in base_yml.data['tasks']['3']['task']
コード例 #5
0
def test_add_playbooks_description():
    schema_path = os.path.normpath(
        os.path.join(__file__, "..", "..", "..", "common", "schemas", '{}.yml'.format('playbook')))
    base_yml = PlaybookYMLFormat(SOURCE_FORMAT_PLAYBOOK_COPY, path=schema_path)
    base_yml.data = {
        "tasks": {
            "1": {
                "type": "playbook",
                "task": {
                }
            },
            "2": {
                "type": "something",
                "task": {
                    "description": "else"
                }
            },
            "3": {
                "type": "something",
                "task": {
                }
            },
            "4": {
                "type": "playbook",
                "task": {
                }
            },
            "5": {
                "type": "start",
                "task": {
                }
            },
            "6": {
                "type": "title",
                "task": {
                }
            },
        }
    }
    base_yml.add_description()
    assert 'description' not in base_yml.data
    assert base_yml.data['tasks']['1']['task']['description'] == ''
    assert base_yml.data['tasks']['2']['task']['description'] == 'else'
    assert 'description' not in base_yml.data['tasks']['3']['task']
    assert base_yml.data['tasks']['4']['task']['description'] == ''
    assert base_yml.data['tasks']['5']['task']['description'] == ''
    assert base_yml.data['tasks']['6']['task']['description'] == ''