Skip to content

Commit

Permalink
fixing unit tests to test what they are actually meant to test
Browse files Browse the repository at this point in the history
  • Loading branch information
ori-gold-px committed Nov 18, 2023
1 parent 22785e3 commit 6e5362b
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions test/test_px_request_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def test_bypass_monitor_header_on_valid_request(self):
def test_specific_enforced_routes_with_enforced_route(self):
config = PxConfig({'px_app_id': 'PXfake_app_id',
'px_auth_token': '',
'px_module_mode': px_constants.MODULE_MODE_BLOCKING,
'px_enforced_routesspecific_routes': ['/profile'],
'px_module_mode': px_constants.MODULE_MODE_MONITORING,
'px_enforced_routes': ['/profile'],
})
headers = {'X-FORWARDED-FOR': '127.0.0.1',
'remote-addr': '127.0.0.1',
Expand All @@ -191,7 +191,7 @@ def test_specific_enforced_routes_with_enforced_route(self):
def test_specific_enforced_routes_with_enforced_route_regex(self):
config = PxConfig({'px_app_id': 'PXfake_app_id',
'px_auth_token': '',
'px_module_mode': px_constants.MODULE_MODE_BLOCKING,
'px_module_mode': px_constants.MODULE_MODE_MONITORING,
'px_enforced_routes_regex': [r'^/profile$'],
})
headers = {'X-FORWARDED-FOR': '127.0.0.1',
Expand All @@ -209,7 +209,7 @@ def test_specific_enforced_routes_with_enforced_route_regex(self):
def test_specific_enforced_routes_with_unenforced_route(self):
config = PxConfig({'px_app_id': 'PXfake_app_id',
'px_auth_token': '',
'px_module_mode': px_constants.MODULE_MODE_BLOCKING,
'px_module_mode': px_constants.MODULE_MODE_MONITORING,
'px_enforced_routes': ['/profile'],
})
headers = {'X-FORWARDED-FOR': '127.0.0.1',
Expand All @@ -220,7 +220,7 @@ def test_specific_enforced_routes_with_unenforced_route(self):
env = builder.get_environ()
request = Request(env)
context = PxContext(request, request_handler.config)
response = create_risk_response(score=0)
response = create_risk_response(score=100)
with mock.patch('perimeterx.px_api.send_risk_request', return_value=response):
response = request_handler.verify_request(context, request)
self.assertEqual(response, True)
Expand Down Expand Up @@ -258,7 +258,7 @@ def test_monitor_specific_routes_in_blocking_mode(self):
env = builder.get_environ()
request = Request(env)
context = PxContext(request, request_handler.config)
response = create_risk_response(score=0)
response = create_risk_response(score=100)
with mock.patch('perimeterx.px_api.send_risk_request', return_value=response):
response = request_handler.verify_request(context, request)
self.assertEqual(context.monitored_route, True)
Expand All @@ -278,10 +278,11 @@ def test_monitor_specific_routes_in_blocking_mode_regex(self):
env = builder.get_environ()
request = Request(env)
context = PxContext(request, request_handler.config)
response = create_risk_response(score=0)
response = create_risk_response(score=100)
with mock.patch('perimeterx.px_api.send_risk_request', return_value=response):
response = request_handler.verify_request(context, request)
self.assertEqual(context.monitored_route, True)
self.assertEqual(response, True)

def test_monitor_specific_routes_in_blocking_mode_should_block_other_routes(self):
config = PxConfig({'px_app_id': 'PXfake_app_id',
Expand Down Expand Up @@ -372,17 +373,18 @@ def test_monitor_specific_routes_with_enforced_specific_routes(self):
env = builder.get_environ()
request = Request(env)
context = PxContext(request, request_handler.config)
response = create_risk_response(score=0)
response = create_risk_response(score=100)
with mock.patch('perimeterx.px_api.send_risk_request', return_value=response):
response = request_handler.verify_request(context, request)
self.assertEqual(context.monitored_route, True)
self.assertEqual(response, True)

def test_monitor_specific_routes_with_enforced_specific_routes_regex(self):
config = PxConfig({'px_app_id': 'PXfake_app_id',
'px_auth_token': '',
'px_module_mode': px_constants.MODULE_MODE_BLOCKING,
'px_monitored_routes_regex': [r'^/profile$'],
'px_enforced_specific_routes_regex': [r'^/login$'],
'px_enforced_routes_regex': [r'^/login$'],
});
headers = {'X-FORWARDED-FOR': '127.0.0.1',
'remote-addr': '127.0.0.1',
Expand All @@ -392,7 +394,8 @@ def test_monitor_specific_routes_with_enforced_specific_routes_regex(self):
env = builder.get_environ()
request = Request(env)
context = PxContext(request, request_handler.config)
response = create_risk_response(score=0)
response = create_risk_response(score=100)
with mock.patch('perimeterx.px_api.send_risk_request', return_value=response):
response = request_handler.verify_request(context, request)
self.assertEqual(context.monitored_route, True)
self.assertEqual(response, True)

0 comments on commit 6e5362b

Please sign in to comment.