Skip to content

Commit

Permalink
WIP Replace request with falcon 4
Browse files Browse the repository at this point in the history
  • Loading branch information
MoessnerFabian(Group) committed Nov 14, 2024
1 parent 26622bc commit d317413
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 38 deletions.
20 changes: 0 additions & 20 deletions tests/unit/connector/fal_tmp.py

This file was deleted.

22 changes: 4 additions & 18 deletions tests/unit/connector/test_http_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,40 +263,34 @@ def test_get_metadata(self):
connector.pipeline_index = 1
connector.setup()
target = connector.target
# Todo: gibt es hier eine Lösung?
resp = requests.post(url=f"{target}/json", json=message, timeout=0.5) # nosemgrep
#resp = self.falconClient.simulate_post('/json', json=message)
resp = requests.post(url=f"{target}/json", json=message, timeout=0.5)
assert resp.status_code == 200
message = connector.messages.get(timeout=0.5)
assert message["custom"]["url"] == target + "/json"
assert re.search(r"\d+\.\d+\.\d+\.\d+", message["custom"]["remote_addr"])
assert isinstance(message["custom"]["user_agent"], str)

def test_server_multiple_config_changes(self):
# Todo: abklären hier request zu lassen -> comments entfernen
message = {"message": "my message"}
connector_config = deepcopy(self.CONFIG)
connector_config["uvicorn_config"]["port"] = 9001
connector = Factory.create({"test connector": connector_config})
connector.pipeline_index = 1
connector.setup()
target = connector.target
#resp = self.client.simulate_post('/json', json=message)
resp = requests.post(url=f"{target}/json", json=message, timeout=0.5) # nosemgrep
resp = requests.post(url=f"{target}/json", json=message, timeout=0.5)
assert resp.status_code == 200
target = target.replace(":9001", ":9000")
try:
#resp = self.client.simulate_post('/json', json=message)
resp = requests.post(url=f"{target}/json", json=message, timeout=0.5) # nosemgrep
resp = requests.post(url=f"{target}/json", json=message, timeout=0.5)
except requests.exceptions.ConnectionError as e:
assert e.response is None
connector_config = deepcopy(self.CONFIG)
connector = Factory.create({"test connector": connector_config})
connector.pipeline_index = 1
connector.setup()
target = connector.target
resp = requests.post(url=f"{target}/json", json=message, timeout=0.5) # nosemgrep
# resp = self.client.simulate_post('/json', json=message)
resp = requests.post(url=f"{target}/json", json=message, timeout=0.5)
assert resp.status_code == 200

def test_get_next_with_hmac_of_raw_message(self):
Expand All @@ -316,8 +310,6 @@ def test_get_next_with_hmac_of_raw_message(self):
connector.pipeline_index = 1
connector.setup()
test_event = "the content"
# Todo: comment entfernen
# requests.post(url=f"{self.target}/plaintext", data=test_event, timeout=0.5) # nosemgrep
self.client.simulate_post('/plaintext', body=test_event)

expected_event = {
Expand All @@ -340,12 +332,9 @@ def test_endpoint_returns_401_if_authorization_not_provided(self, credentials_fi
resp = requests.post(
url=f"{self.target}/auth-json-file", timeout=0.5, data=json.dumps(data)
)
# Todo: gibt es eine Lösung?
#resp = self.falconClient.simulate_post('/auth-json-file', body=json.dumps(data))
assert resp.status_code == 401

def test_endpoint_returns_401_on_wrong_authorization(self, credentials_file_path):
# Todo: was machen mit auth?
mock_env = {ENV_NAME_LOGPREP_CREDENTIALS_FILE: credentials_file_path}
data = {"message": "my log message"}
with mock.patch.dict("os.environ", mock_env):
Expand All @@ -363,7 +352,6 @@ def test_endpoint_returns_200_on_correct_authorization_with_password_from_file(
):
mock_env = {ENV_NAME_LOGPREP_CREDENTIALS_FILE: credentials_file_path}
data = {"message": "my log message"}
# Todo: was machen mit auth?
with mock.patch.dict("os.environ", mock_env):
new_connector = Factory.create({"test connector": self.CONFIG})
new_connector.pipeline_index = 1
Expand All @@ -378,7 +366,6 @@ def test_endpoint_returns_200_on_correct_authorization_with_password_within_cred
self, credentials_file_path
):
mock_env = {ENV_NAME_LOGPREP_CREDENTIALS_FILE: credentials_file_path}
# Todo: was machen mit auth?
data = {"message": "my log message"}
with mock.patch.dict("os.environ", mock_env):
new_connector = Factory.create({"test connector": self.CONFIG})
Expand All @@ -393,7 +380,6 @@ def test_endpoint_returns_200_on_correct_authorization_with_password_within_cred
def test_endpoint_returns_200_on_correct_authorization_for_subpath(self, credentials_file_path):
mock_env = {ENV_NAME_LOGPREP_CREDENTIALS_FILE: credentials_file_path}
data = {"message": "my log message"}
# Todo: was machen mit auth?
with mock.patch.dict("os.environ", mock_env):
new_connector = Factory.create({"test connector": self.CONFIG})
new_connector.pipeline_index = 1
Expand Down

0 comments on commit d317413

Please sign in to comment.