Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: endpoint challenge #33

Merged
merged 6 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified requirements.txt
Binary file not shown.
25 changes: 25 additions & 0 deletions src/controllers/_authentication_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,28 @@ def login_handler():
except Exception as e:
print("SOAP Error:", str(e))
return {"msg": "Internal error", "error": str(e)}, 500


def challenge():
try:
data = request.json

if not data:
return {"msg": "No JSON data provided in the request"}, 400

token = data.get("jwt")

if not token:
return {"msg": "Token is missing in JSON data"}, 400

# SOAP
response = soap_client.service.auth_refresh({"token": token})

return {
"msg": "JWT refreshed successfully",
"jwt": response.auth.token,
}, response.code

except Exception as e:
print("Error:", str(e))
return {"msg": "Internal error", "error": str(e)}, 500
5 changes: 5 additions & 0 deletions src/views/_authentication_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
@views.route("/auth_login", methods=["POST"])
def auth_login():
return _authentication_controllers.login_handler()


@views.route("/auth_refresh", methods=["POST"])
def auth_refresh():
return _authentication_controllers.challenge()
13 changes: 12 additions & 1 deletion src/views/_authentication_views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ def test_auth_login_missing_fields() -> None:

assert (
json.loads(response.data)["msg"] == "Required fields are missing in JSON data"
) # noqa: E501
)


def test_auth_refresh_missing_token() -> None:
# Simulate a request without a token
data = {"jwt": ""}

response = app.test_client().post("/auth_refresh", json=data)

assert response.status_code == 400

assert json.loads(response.data)["msg"] == "Token is missing in JSON data"