implement first ACL version (lack dict support)
This commit is contained in:
@@ -33,6 +33,7 @@ from src.pyrestresource import (
|
||||
ResourcePlugin_field_default,
|
||||
ResourcePlugin_RestResourceBase_default,
|
||||
)
|
||||
from src.pyrestresource import ACL_target_user, ACL_target_group, ACL_target_group_Any, ACL_record, ACL_rule
|
||||
from pprint import pprint
|
||||
|
||||
testdir_path = Path(__file__).parent.resolve()
|
||||
@@ -76,16 +77,19 @@ def init_classes():
|
||||
return resource
|
||||
|
||||
class Login(RestResourceBase):
|
||||
username: Optional[str] = Field(None, exclude=True)
|
||||
# username: Optional[str] = Field(None)
|
||||
secret: Optional[str] = Field(None, exclude=True)
|
||||
username: Optional[str] = Field(None)
|
||||
secret: Optional[str] = Field(
|
||||
None,
|
||||
exclude=True,
|
||||
ACL=[
|
||||
ACL_record(verbs=[rsrc_verb.PUT], target=ACL_target_group_Any(), rule=ACL_rule.ALLOW),
|
||||
ACL_record(verbs=[rsrc_verb.GET, rsrc_verb.DELETE, rsrc_verb.POST], target=ACL_target_group_Any(), rule=ACL_rule.DENY),
|
||||
],
|
||||
)
|
||||
|
||||
@register_rest_rootpoint
|
||||
class RootApp(RestResourceBase):
|
||||
login: Login = Field(
|
||||
default=Login(),
|
||||
plugin=ResourcePlugin_Login,
|
||||
)
|
||||
login: Login = Field(default=Login(), plugin=ResourcePlugin_Login)
|
||||
|
||||
# this add the classes to globals to allow using them later on
|
||||
# => this is only for uinit-testing purpose and is not needed in real use
|
||||
@@ -115,14 +119,37 @@ class Test_RestAPI_LOGIN(unittest.TestCase):
|
||||
self.testapp = RootApp()
|
||||
|
||||
def test_login(self):
|
||||
"""
|
||||
result = self.testapp.process_request("/login", rsrc_verb.GET)
|
||||
print(result)
|
||||
print("*****************")
|
||||
print(result.get_result())
|
||||
|
||||
result = self.testapp.process_request("/login/username", rsrc_verb.GET)
|
||||
print("*****************")
|
||||
print(result.get_result())
|
||||
|
||||
# result = self.testapp.process_request("/login/secret", rsrc_verb.GET)
|
||||
# print("*****************")
|
||||
# print(result.get_result())
|
||||
"""
|
||||
|
||||
result = self.testapp.process_request("/login", rsrc_verb.PUT, '{"username":"chacha","secret":"123456"}')
|
||||
print(result)
|
||||
print("*****************")
|
||||
print(result.get_result())
|
||||
|
||||
"""
|
||||
result = self.testapp.process_request("/login", rsrc_verb.GET)
|
||||
print(result)
|
||||
print("*****************")
|
||||
print(result.get_result())
|
||||
|
||||
result = self.testapp.process_request("/login/username", rsrc_verb.GET)
|
||||
print("*****************")
|
||||
print(result.get_result())
|
||||
|
||||
# result = self.testapp.process_request("/login/secret", rsrc_verb.GET)
|
||||
# print("*****************")
|
||||
# print(result.get_result())
|
||||
"""
|
||||
|
||||
|
||||
class Test_RestAPI_LOGIN_Web(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user