Add UI for share by token

This commit is contained in:
Max Berger
2026-02-22 22:52:28 +01:00
parent f5e42cdeff
commit b7bc0538d2
17 changed files with 574 additions and 93 deletions

0
integ_tests/__init__.py Normal file
View File

99
integ_tests/common.py Normal file
View File

@@ -0,0 +1,99 @@
import os
import pathlib
import socket
import subprocess
import sys
import time
from typing import Any, Generator
from playwright.sync_api import Page
def get_free_port():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("127.0.0.1", 0))
return s.getsockname()[1]
def start_radicale_server(tmp_path: pathlib.Path) -> Generator[str, Any, None]:
port = get_free_port()
config_path = tmp_path / "config"
user_path = tmp_path / "users"
storage_path = tmp_path / "collections"
# Create a local config file
with open(config_path, "w") as f:
f.write(
f"""[server]
hosts = 127.0.0.1:{port}
[storage]
filesystem_folder = {storage_path}
[auth]
type = htpasswd
htpasswd_filename = {user_path}
[web]
type = internal
[sharing]
type = csv
collection_by_map = true
collection_by_token = true
permit_create_token = true
permit_create_map = true
"""
)
with open(user_path, "w") as f:
f.write(
"""admin:adminpassword
"""
)
env = os.environ.copy()
# Ensure the radicale package is in PYTHONPATH
# Assuming this test file is in <repo>/integ_tests/
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
env["PYTHONPATH"] = repo_root + os.pathsep + env.get("PYTHONPATH", "")
# Run the server
process = subprocess.Popen(
[sys.executable, "-m", "radicale", "--config", str(config_path)],
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
# Wait for the server to start listening
start_time = time.time()
while time.time() - start_time < 10:
try:
with socket.create_connection(("127.0.0.1", port), timeout=0.1):
break
except (OSError, ConnectionRefusedError):
if process.poll() is not None:
_stdout, stderr = process.communicate()
raise RuntimeError(
f"Radicale failed to start (code {process.returncode}):\n{stderr.decode()}"
)
time.sleep(0.1)
else:
process.terminate()
process.wait()
raise RuntimeError("Timeout waiting for Radicale to start")
yield f"http://127.0.0.1:{port}"
# Cleanup
process.terminate()
process.wait()
def login(page: Page, radicale_server: str) -> None:
page.goto(radicale_server)
page.fill('#loginscene input[data-name="user"]', "admin")
page.fill('#loginscene input[data-name="password"]', "adminpassword")
page.click('button:has-text("Next")')
def create_collection(page: Page, radicale_server: str) -> None:
page.click('.fabcontainer a[data-name="new"]')
page.click('#createcollectionscene button[data-name="submit"]')

View File

@@ -1,88 +1,20 @@
import os
import socket
import subprocess
import sys
import time
import pathlib
from typing import Any, Generator
import pytest
from playwright.sync_api import Page, expect
def get_free_port():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("127.0.0.1", 0))
return s.getsockname()[1]
from integ_tests.common import login, start_radicale_server
@pytest.fixture
def radicale_server(tmp_path):
port = get_free_port()
config_path = tmp_path / "config"
user_path = tmp_path / "users"
storage_path = tmp_path / "collections"
# Create a local config file
with open(config_path, "w") as f:
f.write(
f"""[server]
hosts = 127.0.0.1:{port}
[storage]
filesystem_folder = {storage_path}
[auth]
type = htpasswd
htpasswd_filename = {user_path}
[web]
type = internal
"""
)
with open(user_path, "w") as f:
f.write(
"""admin:adminpassword
"""
)
env = os.environ.copy()
# Ensure the radicale package is in PYTHONPATH
# Assuming this test file is in <repo>/integ_tests/
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
env["PYTHONPATH"] = repo_root + os.pathsep + env.get("PYTHONPATH", "")
# Run the server
process = subprocess.Popen(
[sys.executable, "-m", "radicale", "--config", str(config_path)],
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
# Wait for the server to start listening
start_time = time.time()
while time.time() - start_time < 10:
try:
with socket.create_connection(("127.0.0.1", port), timeout=0.1):
break
except (OSError, ConnectionRefusedError):
if process.poll() is not None:
stdout, stderr = process.communicate()
raise RuntimeError(
f"Radicale failed to start (code {process.returncode}):\n{stderr.decode()}"
)
time.sleep(0.1)
else:
process.terminate()
process.wait()
raise RuntimeError("Timeout waiting for Radicale to start")
yield f"http://127.0.0.1:{port}"
# Cleanup
process.terminate()
process.wait()
def radicale_server(tmp_path: pathlib.Path) -> Generator[str, Any, None]:
yield from start_radicale_server(tmp_path)
def test_index_html_loads(page: Page, radicale_server):
def test_index_html_loads(page: Page, radicale_server: str) -> None:
"""Test that the index.html loads from the server."""
console_msgs = []
console_msgs: list[str] = []
page.on("console", lambda msg: console_msgs.append(msg.text))
page.goto(radicale_server)
expect(page).to_have_title("Radicale Web Interface")
@@ -90,13 +22,9 @@ def test_index_html_loads(page: Page, radicale_server):
assert len(console_msgs) == 0
def test_user_login_works(page: Page, radicale_server):
def test_user_login_works(page: Page, radicale_server: str) -> None:
"""Test that the login form works."""
page.goto(radicale_server)
# Fill in the login form
page.fill('#loginscene input[data-name="user"]', "admin")
page.fill('#loginscene input[data-name="password"]', "adminpassword")
page.click('button:has-text("Next")')
login(page, radicale_server)
# After login, we should see the collections list (which is empty)
expect(

View File

@@ -0,0 +1,46 @@
import pathlib
from typing import Any, Generator
import pytest
from playwright.sync_api import Page, expect
from integ_tests.common import create_collection, login, start_radicale_server
@pytest.fixture
def radicale_server(tmp_path: pathlib.Path) -> Generator[str, Any, None]:
yield from start_radicale_server(tmp_path)
def test_create_and_delete_share_by_key(page: Page, radicale_server: str) -> None:
login(page, radicale_server)
create_collection(page, radicale_server)
page.hover("article:not(.hidden)")
page.click('article:not(.hidden) a[data-name="share"]', force=True, strict=True)
expect(
page.locator("tr[data-name='sharetokenrowtemplate']:not(.hidden)")
).to_have_count(0)
page.click('button[data-name="sharebytoken_ro"]')
expect(
page.locator("tr[data-name='sharetokenrowtemplate']:not(.hidden)")
).to_have_count(1)
expect(
page.locator("tr[data-name='sharetokenrowtemplate']:not(.hidden) img[alt='RO']")
).to_be_visible()
page.click('tr:not(.hidden) button[data-name="delete"]', strict=True)
expect(
page.locator("tr[data-name='sharetokenrowtemplate']:not(.hidden)")
).to_have_count(0)
page.click('button[data-name="sharebytoken_rw"]')
expect(
page.locator("tr[data-name='sharetokenrowtemplate']:not(.hidden)")
).to_have_count(1)
expect(
page.locator("tr[data-name='sharetokenrowtemplate']:not(.hidden) img[alt='RW']")
).to_be_visible()
page.click('tr:not(.hidden) button[data-name="delete"]', strict=True)
expect(
page.locator("tr[data-name='sharetokenrowtemplate']:not(.hidden)")
).to_have_count(0)