-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: Enable CORS (#40) * feat: Register endpoint (#39) * feat: enpoint registration coverage 57% Implementation of the registration endpoint, 57% coverage is achieved * style: Fix formatter and linter warnings * test: Use random data in register tests * refactor: Update register endpoint according to the `.net` spec * test: Fix broken test --------- Co-authored-by: Antonio Donis <[email protected]> Co-authored-by: Pedro Andrés Chaparro Quintero <[email protected]> Co-authored-by: Pedro Andrés Chaparro Quintero <[email protected]> Co-authored-by: Andrea Velasquez <[email protected]> Co-authored-by: Andvelavi <[email protected]>
- Loading branch information
1 parent
0532440
commit 8417cac
Showing
13 changed files
with
121 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# CLI | ||
|
||
This document describes how to use the service as a CLI tool. | ||
|
||
## Environment variables | ||
|
||
| Variable | Description | Example | | ||
| ----------------- | ------------------------------------------------------ | ------------------------------------------ | | ||
| `GATEWAY_BASEURL` | Base URL of the gateway | `https://gateway:8080` | | ||
| `ALLOWED_ORIGINS` | An string with the allowed origins separated by commas | `https://example.com,https://example2.com` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import flask | ||
from flask_cors import CORS | ||
from src.views import views | ||
from src.config.environment import variables | ||
|
||
app = flask.Flask(__name__) | ||
app.register_blueprint(views) | ||
|
||
allowed_origins_list = variables["ALLOWED_ORIGINS"].split(",") | ||
|
||
CORS(app, resources={r"/*": {"origins": allowed_origins_list}}) | ||
|
||
if __name__ == "__main__": | ||
app.run(debug=True) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
"git-semver-tags": "^4.1.1", | ||
"standard-version": "^9.5.0" | ||
}, | ||
"version": "0.0.8" | ||
"version": "0.0.9" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,4 @@ urllib3==2.0.4 | |
Werkzeug==2.3.7 | ||
wrapt==1.15.0 | ||
zeep==4.2.1 | ||
flask-cors==4.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from flask import request | ||
from src.config.soap_client import soap_client | ||
|
||
|
||
def register_handler(): | ||
try: | ||
# Get JSON data from the request | ||
data = request.json | ||
|
||
if not data: | ||
return {"msg": "No JSON data provided in the request"}, 400 | ||
|
||
username = data.get("username") | ||
password = data.get("password") | ||
|
||
if not username or not password: | ||
return {"msg": "Required fields are missing in JSON data"}, 400 | ||
|
||
result = soap_client.service.account_register( | ||
{"username": username, "password": password} | ||
) | ||
|
||
if result.auth is not None: | ||
jwt = result.auth.token | ||
return {"msg": "Register succeeded", "token": jwt}, 200 | ||
|
||
return {"msg": "Username already registered"}, 409 | ||
|
||
except Exception as e: | ||
print("[Exception] register_handler ->", str(e)) | ||
return {"msg": "Internal error", "error": str(e)}, 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import flask | ||
from ._authentication_views import views as authentication_views | ||
from ._account_views import views as account_views | ||
|
||
|
||
# NOTE: Register all views / routes using the following blueprint | ||
views = flask.Blueprint("views", __name__) | ||
|
||
|
||
views.register_blueprint(authentication_views) | ||
views.register_blueprint(account_views) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import flask | ||
from src.controllers import _account_controllers | ||
|
||
views = flask.Blueprint("account", __name__) | ||
|
||
|
||
@views.route("/account/register", methods=["POST"]) | ||
def account_register(): | ||
return _account_controllers.register_handler() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import json | ||
from main import app | ||
from src.lib.faker import fake_username, fake_password | ||
|
||
register_test_data = {"username": fake_username(), "password": fake_password()} | ||
|
||
|
||
def test_account_register_successful() -> None: | ||
register_data = { | ||
"username": register_test_data["username"], | ||
"password": register_test_data["password"], | ||
} | ||
response = app.test_client().post("/account/register", json=register_data) | ||
json_response = json.loads(response.data) | ||
|
||
assert response.status_code == 200 | ||
assert json.loads(response.data)["msg"] == "Register succeeded" | ||
assert json_response["token"] != "" | ||
|
||
|
||
def test_account_register_missing_fields() -> None: | ||
# Empty json | ||
data = {} | ||
response = app.test_client().post("/account/register", json=data) | ||
|
||
assert response.status_code == 400 | ||
assert json.loads(response.data)["msg"] == "No JSON data provided in the request" | ||
|
||
# Missing password | ||
data = {"username": register_test_data["username"]} | ||
response = app.test_client().post("/account/register", json=data) | ||
|
||
assert response.status_code == 400 | ||
assert ( | ||
json.loads(response.data)["msg"] == "Required fields are missing in JSON data" | ||
) | ||
|
||
|
||
def test_account_register_Username_already_registered() -> None: | ||
data = { | ||
"username": register_test_data["username"], | ||
"password": register_test_data["password"], | ||
} | ||
response = app.test_client().post("/account/register", json=data) | ||
json_response = json.loads(response.data) | ||
|
||
assert response.status_code == 409 | ||
assert json_response["msg"] == "Username already registered" |