diff NewTests/Authorization/auth_service.py @ 576:80ba6f1d521c

new tests for authorization plugin (native only)
author Alain Mazy <am@osimis.io>
date Wed, 06 Sep 2023 17:04:36 +0200
parents
children 0649a19df194
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NewTests/Authorization/auth_service.py	Wed Sep 06 17:04:36 2023 +0200
@@ -0,0 +1,43 @@
+from fastapi import FastAPI
+import logging
+from models import *
+import pprint
+
+# Sample Authorization service that is started when the test starts.
+# It does not check token validity and simply implements a set of basic users
+
+app = FastAPI()
+
+
+
+@app.post("/user/get-profile") 
+def get_user_profile(user_profile_request: UserProfileRequest):
+    logging.info("get user profile: " + user_profile_request.json())
+
+    if user_profile_request.token_key == "user-token-key":
+        if user_profile_request.token_value == "token-uploader":
+            p = UserProfileResponse(
+                name="uploader",
+                permissions=["upload", "edit-labels", "delete", "view"],
+                authorized_labels=["*"],
+                validity=60
+            )
+            return p
+        elif user_profile_request.token_value == "token-admin":
+            p = UserProfileResponse(
+                name="admin",
+                permissions=["all"],
+                authorized_labels=["*"],
+                validity=60
+            )
+            return p
+        elif user_profile_request.token_value == "token-user-a":
+            p = UserProfileResponse(
+                name="user-a",
+                permissions=["view"],
+                authorized_labels=["label_a"],
+                validity=60
+            )
+            return p
+            
+