def test_sophos_firewall_rule_update_command(requests_mock): """ Scenario: Update an existing rule. Given: - User has provided valid credentials. When: - sophos_firewall_rule_update is called. Then: - Ensure outputs prefix is correct. - Ensure a sample value from the API matches what is generated in the context. """ from sophos_firewall import Client, sophos_firewall_rule_update_command mock_response = load_mock_response('rule_set.xml') requests_mock.post(REQUEST_URL, text=mock_response) mock_response = load_mock_response('rule_get.xml') requests_mock.get(REQUEST_URL, text=mock_response) client = Client(base_url=BASE_URL, verify=False, auth=('uname', 'passwd'), proxy=False) result = sophos_firewall_rule_update_command(client, { 'name': 'forunitest2', 'policy_type': 'b' }) assert result.outputs_prefix == 'SophosFirewall.SecurityPolicy' assert result.outputs.get('Name') == 'forunitest2'
def test_sophos_firewall_web_filter_add_command(requests_mock): """ Scenario: Add a new web filter. Given: - User has provided valid credentials. When: - sophos_firewall_web_filter_add is called. Then: - Ensure outputs prefix is correct. - Ensure a sample value from the API matches what is generated in the context. """ from sophos_firewall import Client, sophos_firewall_web_filter_add_command mock_response = load_mock_response('web_filter_set.xml') requests_mock.post(REQUEST_URL, text=mock_response) mock_response = load_mock_response('web_filter_get.xml') requests_mock.get(REQUEST_URL, text=mock_response) client = Client(base_url=BASE_URL, verify=False, auth=('uname', 'passwd'), proxy=False) result = sophos_firewall_web_filter_add_command(client, { 'name': 'b', 'default_action': 'Allow' }) assert result.outputs_prefix == 'SophosFirewall.WebFilterPolicy' assert result.outputs.get('Name') == 'unitest'
def test_sophos_firewall_services_add_command(requests_mock): """ Scenario: Add a new service. Given: - User has provided valid credentials. When: - sophos_firewall_services_add is called. Then: - Ensure outputs prefix is correct. - Ensure a sample value from the API matches what is generated in the context. """ from sophos_firewall import Client, sophos_firewall_services_add_command mock_response = load_mock_response('services_set.xml') requests_mock.post(REQUEST_URL, text=mock_response) mock_response = load_mock_response('services_get.xml') requests_mock.get(REQUEST_URL, text=mock_response) client = Client(base_url=BASE_URL, verify=False, auth=('uname', 'passwd'), proxy=False) result = sophos_firewall_services_add_command(client, { 'name': 'b', 'service_type': 'IP', 'protocol_name': 'ARGUS' }) assert result.outputs_prefix == 'SophosFirewall.Services' assert result.outputs.get('Name') == 'unitest2'
def test_sophos_firewall_user_update_command(requests_mock): """ Scenario: Update an existing user. Given: - User has provided valid credentials. When: - sophos_firewall_user_update is called. Then: - Ensure outputs prefix is correct. - Ensure a sample value from the API matches what is generated in the context. """ from sophos_firewall import Client, sophos_firewall_user_update_command mock_response = load_mock_response('user_set.xml') requests_mock.post(REQUEST_URL, text=mock_response) mock_response = load_mock_response('user_get.xml') requests_mock.get(REQUEST_URL, text=mock_response) client = Client(base_url=BASE_URL, verify=False, auth=('uname', 'passwd'), proxy=False) result = sophos_firewall_user_update_command( client, { 'name': 'b', 'username': '******', 'password': '******', 'email': '[email protected]' }) assert result.outputs_prefix == 'SophosFirewall.User' assert result.outputs.get('Name') == 'unitest3'
def test_sophos_firewall_app_category_get_command(requests_mock): """ Scenario: Get a single app category. Given: - User has provided valid credentials. When: - sophos_firewall_app_category_get is called. Then: - Ensure outputs prefix is correct. - Ensure a sample value from the API matches what is generated in the context. """ from sophos_firewall import Client, sophos_firewall_app_category_get_command mock_response = load_mock_response('app_category_get.xml') requests_mock.get(REQUEST_URL, text=mock_response) client = Client(base_url=BASE_URL, verify=False, auth=('uname', 'passwd'), proxy=False) result = sophos_firewall_app_category_get_command(client, name='b') assert result.outputs_prefix == 'SophosFirewall.ApplicationFilterCategory' assert result.outputs.get('Name') == 'Conferencing'
def test_sophos_firewall_app_policy_delete_command(requests_mock): """ Scenario: Delete an existing app policy. Given: - User has provided valid credentials. When: - sophos_firewall_app_policy_delete is called. Then: - Ensure outputs prefix is correct. - Ensure a sample value from the API matches what is generated in the context. """ from sophos_firewall import Client, sophos_firewall_app_policy_delete_command mock_response = load_mock_response('app_policy_set.xml') requests_mock.post(REQUEST_URL, text=mock_response) client = Client(base_url=BASE_URL, verify=False, auth=('uname', 'passwd'), proxy=False) result = sophos_firewall_app_policy_delete_command(client, 'forunitest') assert result.outputs_prefix == 'SophosFirewall.ApplicationFilterPolicy' assert result.outputs.get('Name') == 'forunitest'
def test_sophos_firewall_rule_group_list_command(requests_mock): """ Scenario: List all rule groups. Given: - User has provided valid credentials. When: - sophos_firewall_rule_group_list is called. Then: - Ensure outputs prefix is correct. - Ensure a sample value from the API matches what is generated in the context. """ from sophos_firewall import Client, sophos_firewall_rule_group_list_command mock_response = load_mock_response('rule_group_list.xml') requests_mock.get(REQUEST_URL, text=mock_response) client = Client(base_url=BASE_URL, verify=False, auth=('uname', 'passwd'), proxy=False) result = sophos_firewall_rule_group_list_command(client, 0, 10) assert result.outputs_prefix == 'SophosFirewall.SecurityPolicyGroup' assert len(result.outputs) == 4 assert result.outputs[0].get('Name') == 'Traffic to Internal Zones'
def test_prepare_builder_params(requests_mock): """ Scenario: Prepare list objects for builder Given: - User has provided valid credentials. When: - Before a builder is used. Then: - Ensure the correct item is returned from the function based on the arguments. """ from sophos_firewall import Client, prepare_builder_params mock_response = load_mock_response('rule_get.xml') requests_mock.get(REQUEST_URL, text=mock_response) client = Client(base_url=BASE_URL, verify=False, auth=('uname', 'passwd'), proxy=False) result = prepare_builder_params(client, {'members': ['Identity', 'Member']}, True, 'rule', 'SecurityPolicy', {'members': 'new'}) assert result == {'members': ['new']}
def test_sophos_firewall_web_filter_list_command(requests_mock): """ Scenario: List all web filters. Given: - User has provided valid credentials. When: - sophos_firewall_web_filter_list is called. Then: - Ensure number of items is correct. - Ensure outputs prefix is correct. - Ensure a sample value from the API matches what is generated in the context. """ from sophos_firewall import Client, sophos_firewall_web_filter_list_command mock_response = load_mock_response('web_filter_list.xml') requests_mock.get(REQUEST_URL, text=mock_response) client = Client(base_url=BASE_URL, verify=False, auth=('uname', 'passwd'), proxy=False) result = sophos_firewall_web_filter_list_command(client, 0, 10) assert result.outputs_prefix == 'SophosFirewall.WebFilterPolicy' assert len(result.outputs) == 10 assert result.outputs[0].get('Name') == 'xy1'