Add new test for non-sharing, fix non-sharing use case
This commit is contained in:
@@ -30,21 +30,43 @@ from typing import Any, Generator, Optional
|
||||
from playwright.sync_api import BrowserContext, Page
|
||||
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class AuthType(Enum):
|
||||
HTPASSWD = "htpasswd"
|
||||
XREMOTE = "http_x_remote_user"
|
||||
|
||||
|
||||
class SharingType(Enum):
|
||||
SHARING = "sharing"
|
||||
NOSHARING = "nosharing"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Config:
|
||||
name: str
|
||||
auth_type: str
|
||||
auth_type: AuthType
|
||||
sharing_type: SharingType
|
||||
extra_config: str = ""
|
||||
|
||||
|
||||
SHARING_HTPASSWD = Config(
|
||||
name="sharing_htpasswd",
|
||||
auth_type="htpasswd",
|
||||
auth_type=AuthType.HTPASSWD,
|
||||
sharing_type=SharingType.SHARING,
|
||||
)
|
||||
|
||||
SHARING_XREMOTE = Config(
|
||||
name="sharing_xremote",
|
||||
auth_type="http_x_remote_user",
|
||||
auth_type=AuthType.XREMOTE,
|
||||
sharing_type=SharingType.SHARING,
|
||||
)
|
||||
|
||||
NOSHARE_HTPASSWD = Config(
|
||||
name="noshare_htpasswd",
|
||||
auth_type=AuthType.HTPASSWD,
|
||||
sharing_type=SharingType.NOSHARING,
|
||||
)
|
||||
|
||||
|
||||
@@ -71,10 +93,10 @@ hosts = 127.0.0.1:{port}
|
||||
[storage]
|
||||
filesystem_folder = {storage_path}
|
||||
[auth]
|
||||
type = {config.auth_type}
|
||||
type = {config.auth_type.value}
|
||||
"""
|
||||
)
|
||||
if config.auth_type == "htpasswd":
|
||||
if config.auth_type == AuthType.HTPASSWD:
|
||||
f.write(f"htpasswd_filename = {user_path}\n")
|
||||
f.write("htpasswd_encryption = plain\n")
|
||||
|
||||
@@ -83,7 +105,11 @@ type = {config.auth_type}
|
||||
type = internal
|
||||
[headers]
|
||||
Content-Security-Policy = default-src 'self'; object-src 'none'
|
||||
[sharing]
|
||||
"""
|
||||
)
|
||||
if config.sharing_type == SharingType.SHARING:
|
||||
f.write(
|
||||
f"""[sharing]
|
||||
type = csv
|
||||
collection_by_map = true
|
||||
collection_by_token = true
|
||||
@@ -93,12 +119,12 @@ permit_properties_overlay = true
|
||||
collection_by_bday = true
|
||||
permit_create_bday = true
|
||||
database_path = {sharing_path}
|
||||
|
||||
{config.extra_config}
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
if config.auth_type == "htpasswd":
|
||||
f.write(f"\n{config.extra_config}\n")
|
||||
|
||||
if config.auth_type == AuthType.HTPASSWD:
|
||||
with open(user_path, "w") as f:
|
||||
f.write(
|
||||
"""admin:adminpassword
|
||||
@@ -155,14 +181,14 @@ def login(
|
||||
config: Config = SHARING_HTPASSWD,
|
||||
context: Optional[BrowserContext] = None,
|
||||
) -> None:
|
||||
if config.auth_type == "http_x_remote_user":
|
||||
if config.auth_type == AuthType.XREMOTE:
|
||||
if context is None:
|
||||
raise ValueError("context is required for http_x_remote_user login")
|
||||
context.set_extra_http_headers({"X-Remote-User": "admin"})
|
||||
|
||||
page.goto(radicale_server)
|
||||
|
||||
if config.auth_type == "htpasswd":
|
||||
if config.auth_type == AuthType.HTPASSWD:
|
||||
page.fill('#loginscene input[data-name="user"]', "admin")
|
||||
page.fill('#loginscene input[data-name="password"]', "adminpassword")
|
||||
page.click('button:has-text("Next")')
|
||||
|
||||
Reference in New Issue
Block a user