Mercurial > hg > orthanc-tests
comparison 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 |
comparison
equal
deleted
inserted
replaced
575:28fef24147fa | 576:80ba6f1d521c |
---|---|
1 from fastapi import FastAPI | |
2 import logging | |
3 from models import * | |
4 import pprint | |
5 | |
6 # Sample Authorization service that is started when the test starts. | |
7 # It does not check token validity and simply implements a set of basic users | |
8 | |
9 app = FastAPI() | |
10 | |
11 | |
12 | |
13 @app.post("/user/get-profile") | |
14 def get_user_profile(user_profile_request: UserProfileRequest): | |
15 logging.info("get user profile: " + user_profile_request.json()) | |
16 | |
17 if user_profile_request.token_key == "user-token-key": | |
18 if user_profile_request.token_value == "token-uploader": | |
19 p = UserProfileResponse( | |
20 name="uploader", | |
21 permissions=["upload", "edit-labels", "delete", "view"], | |
22 authorized_labels=["*"], | |
23 validity=60 | |
24 ) | |
25 return p | |
26 elif user_profile_request.token_value == "token-admin": | |
27 p = UserProfileResponse( | |
28 name="admin", | |
29 permissions=["all"], | |
30 authorized_labels=["*"], | |
31 validity=60 | |
32 ) | |
33 return p | |
34 elif user_profile_request.token_value == "token-user-a": | |
35 p = UserProfileResponse( | |
36 name="user-a", | |
37 permissions=["view"], | |
38 authorized_labels=["label_a"], | |
39 validity=60 | |
40 ) | |
41 return p | |
42 | |
43 |