def test_adapter_remove_rule(bigip, fake_conf, policy_setup): adapter = l7policy_adapter.L7PolicyServiceAdapter(fake_conf) pol = adapter.translate( POL_CONFIGS['redirect_to_url_not_header_remove_rule']) assert pol == { 'name': 'wrapper_policy', 'partition': u'Project_test', 'legacy': True, 'requires': ['http'], 'controls': ['forwarding'], 'rules': [{ 'actions': [{ 'request': True, 'name': '0', 'httpReply': True, 'redirect': True, 'location': 'http://www.example.com' }], 'conditions': [], 'name': u'redirect_to_url_1', 'ordinal': 1 }], 'strategy': 'first-match' } bigip.tm.ltm.policys.policy.create(**pol)
def test_adapter_redirect_to_pool_many_rules(bigip, fake_conf, policy_setup): adapter = l7policy_adapter.L7PolicyServiceAdapter(fake_conf) pol = adapter.translate(POL_CONFIGS['redirect_to_pool_many_rules']) assert pol == \ { "controls": ["forwarding"], "legacy": True, "name": "wrapper_policy", "partition": "Project_test", "requires": ["http"], "rules": [{ "actions": [{ "forward": True, "name": "0", "pool": "/Project_test/Project_test_pool", "request": True }], "conditions": [{ "equals": True, "httpHeader": True, "name": "0", "request": True, "tmName": "X-HEADER", "values": ["test_header"] }, { "contains": True, "httpCookie": True, "name": "1", "request": True, "tmName": "cookie", "values": ["test_cookie"] }, { "httpUri": True, "name": "2", "path": True, "request": True, "startsWith": True, "values": ["/api/cool/site"] }], "name": "redirect_to_pool_1", "ordinal": 1 }], "strategy": "first-match" } bigip.tm.ltm.policys.policy.create(**pol)
def test_adapter_redirect_to_pool_file_type_not_beginswith( bigip, fake_conf, policy_setup): adapter = l7policy_adapter.L7PolicyServiceAdapter(fake_conf) pol = adapter.translate(POL_CONFIGS['redirect_to_pool_not_file_type']) assert pol == { 'name': 'wrapper_policy', 'partition': u'Project_test', 'legacy': True, 'requires': ['http'], 'controls': ['forwarding'], 'rules': [{ 'actions': [{ 'forward': True, 'name': 0, 'request': True, 'pool': u'/Project_test/Project_test_pool' }], 'conditions': [{ 'startsWith': True, 'extension': True, 'httpUri': True, 'request': True, 'values': [u'txt'], "name": '0', 'not': True }], 'name': u'redirect_to_pool_1', 'ordinal': 1 }], 'strategy': 'first-match' } bigip.tm.ltm.policys.policy.create(**pol)
def test_adapter_reject_not_beginswith(bigip, fake_conf, policy_setup): adapter = l7policy_adapter.L7PolicyServiceAdapter(fake_conf) pol = adapter.translate(POL_CONFIGS['reject_not_path']) assert pol == { 'legacy': True, 'requires': ['http'], 'controls': ['forwarding'], 'rules': [{ 'ordinal': 1, 'conditions': [{ 'values': [u'/api'], 'httpUri': True, 'name': '0', 'startsWith': True, 'request': True, 'path': True, 'not': True }], 'name': u'reject_1', 'actions': [{ 'request': True, 'name': '0', 'reset': True, 'request': True, 'forward': True }] }], 'partition': u'Project_test', 'name': 'wrapper_policy', 'strategy': 'first-match' } bigip.tm.ltm.policys.policy.create(**pol)
def test_adapter_redirect_to_pool_hostname_not_equal_to( bigip, fake_conf, policy_setup): adapter = l7policy_adapter.L7PolicyServiceAdapter(fake_conf) pol = adapter.translate(POL_CONFIGS['redirect_to_pool_hostname_invert']) assert pol == { 'name': 'wrapper_policy', 'partition': u'Project_test', 'legacy': True, 'requires': ['http'], 'controls': ['forwarding'], 'rules': [{ 'actions': [{ 'request': True, 'name': '0', 'forward': True, 'pool': '/Project_test/Project_test_pool' }], 'conditions': [{ 'equals': True, 'request': True, 'httpHost': True, 'values': [u'10.10.10.10'], 'name': '0', 'host': True, 'not': True }], 'name': u'redirect_to_pool_1', 'ordinal': 1 }], 'strategy': 'first-match' } bigip.tm.ltm.policys.policy.create(**pol)
def test_adapter_many_policies_rules(bigip, fake_conf, policy_setup): adapter = l7policy_adapter.L7PolicyServiceAdapter(fake_conf) pol = adapter.translate(POL_CONFIGS['many_policies_and_rules']) from pprint import pprint pprint(pol) assert pol == \ { "controls": ["forwarding"], "legacy": True, "name": "wrapper_policy", "partition": "Project_test", "requires": ["http"], "rules": [{ "actions": [{ "forward": True, "name": "0", "pool": "/Project_test/Project_test_pool", "request": True }], "conditions": [{ "equals": True, "httpHeader": True, "name": "0", "request": True, "tmName": "X-HEADER", "values": ["test_header"] }, { "contains": True, "httpCookie": True, "name": "1", "request": True, "tmName": "cookie", "values": ["test_cookie"] }], "name": "redirect_to_pool_1", "ordinal": 1 }, { "actions": [{ "forward": True, "name": "0", "request": True, "reset": True }], "conditions": [{ "httpUri": True, "name": "0", "path": True, "request": True, "startsWith": True, "values": ["/api/cool/site"] }], "name": "reject_2", "ordinal": 2 }, { "actions": [{ "forward": True, "name": "0", "request": True, "reset": True }], "conditions": [], "name": "reject_3", "ordinal": 3 }, { "actions": [{ "httpReply": True, "location": "http://www.example.com", "name": "0", "request": True, "redirect": True }], "conditions": [], "name": "redirect_to_url_4", "ordinal": 4 }], "strategy": "first-match" } bigip.tm.ltm.policys.policy.create(**pol)