sweatstack-cli 0.12.1__tar.gz → 0.14.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/CHANGELOG.md +31 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/PKG-INFO +1 -1
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/pyproject.toml +1 -1
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/api/client.py +11 -1
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/auth/__init__.py +3 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/commands/app.py +6 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/commands/auth.py +30 -20
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/commands/page.py +3 -11
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/exceptions.py +21 -0
- sweatstack_cli-0.14.0/src/sweatstack_cli/go_live.py +45 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_api/test_client.py +60 -1
- sweatstack_cli-0.14.0/tests/test_auth/test_authorize_url.py +21 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_commands/test_app.py +17 -0
- sweatstack_cli-0.14.0/tests/test_commands/test_auth.py +93 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_commands/test_page_deploy.py +58 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/uv.lock +1 -1
- sweatstack_cli-0.12.1/tests/test_commands/test_auth.py +0 -49
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/.claude/settings.local.json +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/.claude/skills/sweatstack/SKILL.md +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/.claude/skills/sweatstack/api.md +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/.claude/skills/sweatstack/auth.md +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/.claude/skills/sweatstack/cli.md +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/.claude/skills/sweatstack/pyscript.md +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/.claude/skills/sweatstack/webapp.md +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/.gitignore +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/.python-version +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/CREATE_PRIVATE_APP.md +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/DEVELOPMENT.md +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/Makefile +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/PLAN.md +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/README.md +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/plans/001-page-init-command.md +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/__init__.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/api/__init__.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/auth/callback_server.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/auth/jwt.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/auth/pkce.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/auth/tokens.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/commands/__init__.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/config.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/console.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/main.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/project.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/py.typed +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/services/__init__.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/services/applications.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/templates/page/index.html +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/version_check.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/sweatstack.toml +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/__init__.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/conftest.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_api/__init__.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_auth/__init__.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_auth/test_callback_server.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_auth/test_jwt.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_auth/test_pkce.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_auth/test_tokens.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_commands/__init__.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_commands/test_cli.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_commands/test_page_init.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_project.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_services/__init__.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_services/test_applications.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_version.py +0 -0
- {sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/tests/test_version_check.py +0 -0
|
@@ -4,6 +4,37 @@ All notable changes to this project are documented here. The format is based on
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
|
|
5
5
|
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.14.0] - 2026-10-29
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Passkeys (SweatStack plan 084): `sweatstack login` asks the browser to confirm
|
|
12
|
+
your passkey when your account has one (`acr_values=mfa`), and the CLI's tokens
|
|
13
|
+
carry that confirmation, so creating an application and deploying a page work
|
|
14
|
+
without the CLI ever handling the passkey. `sweatstack status` shows whether the
|
|
15
|
+
login confirmed it.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- `sweatstack login` always opens the browser, also when you are logged in:
|
|
20
|
+
signing in again is how a confirmation reaches the CLI. `--force` is still
|
|
21
|
+
accepted and does nothing.
|
|
22
|
+
- A command refused for want of a recent passkey confirmation says to run
|
|
23
|
+
`sweatstack login` and the command again, and one refused because the account
|
|
24
|
+
has no passkey says where to add one; both exit 2. Such a refusal used to read
|
|
25
|
+
"Session expired".
|
|
26
|
+
|
|
27
|
+
## [0.13.0] - 2026-10-15
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- `page deploy` prints what the app still needs before anyone else can connect,
|
|
32
|
+
as the server reports it (`go_live_missing`), and links to the app's Consent
|
|
33
|
+
screen, where it goes live. It used to print a bare `/publish` link, which only
|
|
34
|
+
ever said the app was private.
|
|
35
|
+
- `app create` points to the app's overview as the next step and lists what is
|
|
36
|
+
missing before anyone else can connect.
|
|
37
|
+
|
|
7
38
|
## [0.12.1] - 2026-10-13
|
|
8
39
|
|
|
9
40
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: sweatstack-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.14.0
|
|
4
4
|
Summary: Command-line interface for SweatStack — the sports data platform for developers
|
|
5
5
|
Project-URL: Homepage, https://sweatstack.no
|
|
6
6
|
Project-URL: Documentation, https://docs.sweatstack.no
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sweatstack-cli"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.14.0"
|
|
4
4
|
description = "Command-line interface for SweatStack — the sports data platform for developers"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [{ name = "Aart Goossens", email = "aart@sweatstack.no" }]
|
|
@@ -10,7 +10,12 @@ import httpx
|
|
|
10
10
|
|
|
11
11
|
from sweatstack_cli.auth import Authenticator
|
|
12
12
|
from sweatstack_cli.config import get_settings
|
|
13
|
-
from sweatstack_cli.exceptions import
|
|
13
|
+
from sweatstack_cli.exceptions import (
|
|
14
|
+
APIError,
|
|
15
|
+
AuthenticationError,
|
|
16
|
+
SecondFactorEnrollmentRequired,
|
|
17
|
+
SecondFactorRequired,
|
|
18
|
+
)
|
|
14
19
|
|
|
15
20
|
|
|
16
21
|
class APIClient:
|
|
@@ -152,11 +157,16 @@ class APIClient:
|
|
|
152
157
|
AuthenticationError: For 401 responses.
|
|
153
158
|
APIError: For other error responses.
|
|
154
159
|
"""
|
|
160
|
+
# A step-up (RFC 9470) is a 401 too, but not an expired session: read the challenge first.
|
|
155
161
|
if response.status_code == 401:
|
|
162
|
+
if "insufficient_user_authentication" in response.headers.get("WWW-Authenticate", ""):
|
|
163
|
+
raise SecondFactorRequired()
|
|
156
164
|
raise AuthenticationError("Session expired. Run 'sweatstack login' again.")
|
|
157
165
|
|
|
158
166
|
if response.status_code >= 400:
|
|
159
167
|
detail, code = self._extract_error(response)
|
|
168
|
+
if code == "second_factor_enrollment_required":
|
|
169
|
+
raise SecondFactorEnrollmentRequired(detail)
|
|
160
170
|
raise APIError(
|
|
161
171
|
f"API error ({response.status_code}): {detail}",
|
|
162
172
|
status_code=response.status_code,
|
|
@@ -154,6 +154,9 @@ class Authenticator:
|
|
|
154
154
|
"code_challenge": pkce.challenge,
|
|
155
155
|
"code_challenge_method": "S256",
|
|
156
156
|
"state": pkce.state,
|
|
157
|
+
# SweatStack plan 084 D11: a user with a passkey confirms it in the browser here, and the
|
|
158
|
+
# CLI's tokens carry that confirmation. For anyone else it changes nothing.
|
|
159
|
+
"acr_values": "mfa",
|
|
157
160
|
}
|
|
158
161
|
return f"{self._settings.api_url}/oauth/authorize?{urlencode(params)}"
|
|
159
162
|
|
|
@@ -12,6 +12,7 @@ import typer
|
|
|
12
12
|
from sweatstack_cli.api import APIClient
|
|
13
13
|
from sweatstack_cli.console import console, stderr_console
|
|
14
14
|
from sweatstack_cli.exceptions import APIError, AuthenticationError
|
|
15
|
+
from sweatstack_cli.go_live import app_url, print_go_live
|
|
15
16
|
from sweatstack_cli.project import CONFIG_FILENAME, write_config
|
|
16
17
|
from sweatstack_cli.services.applications import create_application
|
|
17
18
|
|
|
@@ -198,6 +199,11 @@ def _print_app_created(result: dict[str, str], env_path: Path | None, config_pat
|
|
|
198
199
|
console.print()
|
|
199
200
|
console.print("[yellow]Save the secret now — it won't be shown again.[/yellow]")
|
|
200
201
|
|
|
202
|
+
console.print()
|
|
203
|
+
console.print("Next: authorize with your own account. The app's overview walks you through it:")
|
|
204
|
+
console.print(f" {app_url(result['id'])}")
|
|
205
|
+
print_go_live(result)
|
|
206
|
+
|
|
201
207
|
|
|
202
208
|
@app.command()
|
|
203
209
|
def link(
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
5
7
|
import typer
|
|
6
8
|
|
|
7
9
|
from sweatstack_cli.api import APIClient
|
|
8
10
|
from sweatstack_cli.auth import Authenticator
|
|
11
|
+
from sweatstack_cli.auth.jwt import decode_jwt_payload
|
|
9
12
|
from sweatstack_cli.console import console
|
|
10
13
|
from sweatstack_cli.exceptions import APIError, AuthenticationError
|
|
11
14
|
from sweatstack_cli.version_check import check_for_update
|
|
@@ -22,30 +25,22 @@ def _display_name(user: dict[str, object]) -> str:
|
|
|
22
25
|
|
|
23
26
|
|
|
24
27
|
def login(
|
|
28
|
+
# Kept so scripts that pass it keep working.
|
|
25
29
|
force: bool = typer.Option(
|
|
26
30
|
False,
|
|
27
31
|
"--force",
|
|
28
32
|
"-f",
|
|
29
|
-
|
|
33
|
+
hidden=True,
|
|
34
|
+
help="No longer needed: login always opens the browser.",
|
|
30
35
|
),
|
|
31
36
|
) -> None:
|
|
32
|
-
"""Authenticate with SweatStack via browser.
|
|
33
|
-
auth = Authenticator()
|
|
37
|
+
"""Authenticate with SweatStack via browser.
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
client = APIClient(authenticator=auth)
|
|
41
|
-
user = client.get("/api/v1/oauth/userinfo")
|
|
42
|
-
console.print(
|
|
43
|
-
f"Already logged in as [bold]{_display_name(user)}[/bold]. "
|
|
44
|
-
f"Use [cyan]--force[/cyan] to re-authenticate."
|
|
45
|
-
)
|
|
46
|
-
return
|
|
47
|
-
except AuthenticationError:
|
|
48
|
-
pass # Token invalid, proceed with login
|
|
39
|
+
Always opens the browser, as ``gh auth login`` does: signing in again is how a
|
|
40
|
+
passkey confirmation reaches the CLI's tokens (SweatStack plan 084). Other
|
|
41
|
+
commands never open a browser on their own.
|
|
42
|
+
"""
|
|
43
|
+
auth = Authenticator()
|
|
49
44
|
|
|
50
45
|
with console.status("[bold]Opening browser for authentication...[/bold]"):
|
|
51
46
|
try:
|
|
@@ -64,6 +59,20 @@ def login(
|
|
|
64
59
|
raise typer.Exit(2)
|
|
65
60
|
|
|
66
61
|
|
|
62
|
+
def _confirmation(access_token: str) -> str:
|
|
63
|
+
"""Whether the login that issued these tokens confirmed a passkey (SweatStack plan 084):
|
|
64
|
+
the ``amr`` and ``auth_time`` claims the browser's confirmation put on them. Which actions
|
|
65
|
+
need a confirmation, and how recent, is the server's to decide: a refusal says what to do."""
|
|
66
|
+
try:
|
|
67
|
+
claims = decode_jwt_payload(access_token)
|
|
68
|
+
except ValueError:
|
|
69
|
+
return "unknown"
|
|
70
|
+
if "mfa" in (claims.get("amr") or []) and isinstance(claims.get("auth_time"), int):
|
|
71
|
+
confirmed_at = datetime.fromtimestamp(claims["auth_time"]).astimezone()
|
|
72
|
+
return f"confirmed at login {confirmed_at:%Y-%m-%d %H:%M}"
|
|
73
|
+
return "not confirmed at login"
|
|
74
|
+
|
|
75
|
+
|
|
67
76
|
def logout() -> None:
|
|
68
77
|
"""Remove stored credentials."""
|
|
69
78
|
auth = Authenticator()
|
|
@@ -86,11 +95,12 @@ def status() -> None:
|
|
|
86
95
|
try:
|
|
87
96
|
client = APIClient(authenticator=auth)
|
|
88
97
|
user = client.get("/api/v1/oauth/userinfo")
|
|
89
|
-
console.print(f" Name:
|
|
90
|
-
console.print(f" Email:
|
|
91
|
-
console.print(f" ID:
|
|
98
|
+
console.print(f" Name: {_display_name(user)}")
|
|
99
|
+
console.print(f" Email: {user.get('email', 'unknown')}")
|
|
100
|
+
console.print(f" ID: {user.get('sub', 'unknown')}")
|
|
92
101
|
except (AuthenticationError, APIError):
|
|
93
102
|
pass # Silently skip user info on error
|
|
103
|
+
console.print(f" Passkey: {_confirmation(tokens.access_token)}")
|
|
94
104
|
|
|
95
105
|
# Check version
|
|
96
106
|
update_available, latest = check_for_update()
|
|
@@ -16,9 +16,9 @@ import typer
|
|
|
16
16
|
from rich.progress import Progress, SpinnerColumn, TextColumn
|
|
17
17
|
|
|
18
18
|
from sweatstack_cli.api import APIClient
|
|
19
|
-
from sweatstack_cli.config import get_settings
|
|
20
19
|
from sweatstack_cli.console import console
|
|
21
20
|
from sweatstack_cli.exceptions import APIError, AuthenticationError
|
|
21
|
+
from sweatstack_cli.go_live import print_go_live
|
|
22
22
|
from sweatstack_cli.project import CONFIG_FILENAME, ProjectConfig, update_config, write_config
|
|
23
23
|
from sweatstack_cli.services.applications import (
|
|
24
24
|
APPLICATION_HAS_PAGE_CODE,
|
|
@@ -196,16 +196,8 @@ def deploy(
|
|
|
196
196
|
console.print(f" Files: {file_count}")
|
|
197
197
|
console.print(f" URL: {result.get('url', 'N/A')}")
|
|
198
198
|
|
|
199
|
-
#
|
|
200
|
-
|
|
201
|
-
if application.get("is_private"):
|
|
202
|
-
app_id = application.get("id")
|
|
203
|
-
if app_id:
|
|
204
|
-
base_url = get_settings().api_url
|
|
205
|
-
console.print()
|
|
206
|
-
console.print("Your app is private. Ready to go public?")
|
|
207
|
-
publish_url = f"{base_url}/applications/{app_id}/publish"
|
|
208
|
-
console.print(f" {publish_url}")
|
|
199
|
+
# What the app still needs before anyone else can connect, as the server reports it.
|
|
200
|
+
print_go_live(result.get("application") or {}, on_pages=True)
|
|
209
201
|
|
|
210
202
|
|
|
211
203
|
def _upload(
|
|
@@ -18,6 +18,27 @@ class AuthenticationError(CLIError):
|
|
|
18
18
|
exit_code = 2
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
class SecondFactorRequired(AuthenticationError):
|
|
22
|
+
"""The action needs a recent passkey confirmation (SweatStack plan 084).
|
|
23
|
+
|
|
24
|
+
The server answers RFC 9470's step-up challenge: a ``401`` whose ``WWW-Authenticate`` says
|
|
25
|
+
``insufficient_user_authentication``. The browser confirms it at ``sweatstack login``; the CLI
|
|
26
|
+
never handles a passkey itself. Not an expired session, so it never says so."""
|
|
27
|
+
|
|
28
|
+
def __init__(self) -> None:
|
|
29
|
+
super().__init__(
|
|
30
|
+
"This needs your passkey. Run 'sweatstack login' to confirm in your browser, "
|
|
31
|
+
"then run this command again."
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class SecondFactorEnrollmentRequired(AuthenticationError):
|
|
36
|
+
"""The account has no passkey, and the action needs one (SweatStack plan 084)."""
|
|
37
|
+
|
|
38
|
+
def __init__(self, detail: str) -> None:
|
|
39
|
+
super().__init__(f"{detail} Then run 'sweatstack login' and this command again.")
|
|
40
|
+
|
|
41
|
+
|
|
21
42
|
class APIError(CLIError):
|
|
22
43
|
"""API returned an error response.
|
|
23
44
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""What an app still needs before anyone else can connect, as the CLI prints it.
|
|
2
|
+
|
|
3
|
+
The server decides: `go_live_missing` on the application in an API response is the same
|
|
4
|
+
checklist the web app's pages show (SweatStack plan 080). The CLI only prints it and links to
|
|
5
|
+
the page where each item is filled in, so a terminal, an agent and the browser agree.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from sweatstack_cli.config import get_settings
|
|
13
|
+
from sweatstack_cli.console import console
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def app_url(application_id: str, tab: str = "") -> str:
|
|
17
|
+
"""The application's page in the web app, or one of its tabs."""
|
|
18
|
+
return f"{get_settings().api_url}/applications/{application_id}{tab}"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def print_go_live(application: dict[str, Any], *, on_pages: bool = False) -> None:
|
|
22
|
+
"""Print what stands between `application` and anyone else connecting, or nothing when the
|
|
23
|
+
app is ready. A server older than the checklist sends only `is_private`; then the CLI says
|
|
24
|
+
that much and links to the same page."""
|
|
25
|
+
application_id = application.get("id")
|
|
26
|
+
if not application_id:
|
|
27
|
+
return
|
|
28
|
+
missing = [item["label"] for item in application.get("go_live_missing") or []]
|
|
29
|
+
private = bool(application.get("is_private"))
|
|
30
|
+
if not missing and not private:
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
console.print()
|
|
34
|
+
if private:
|
|
35
|
+
console.print("Your app is private: only you can connect.")
|
|
36
|
+
else:
|
|
37
|
+
console.print("Your app is public, but anyone else is turned away until you add:")
|
|
38
|
+
if missing:
|
|
39
|
+
if private:
|
|
40
|
+
console.print("Before anyone else can, add:")
|
|
41
|
+
for label in missing:
|
|
42
|
+
console.print(f" - {label}")
|
|
43
|
+
if private and on_pages:
|
|
44
|
+
console.print("Runs entirely in the browser? The Pages fast track fills in most of it.")
|
|
45
|
+
console.print(f" {app_url(application_id, '/consent')}")
|
|
@@ -10,7 +10,12 @@ import pytest
|
|
|
10
10
|
from sweatstack_cli.api.client import APIClient
|
|
11
11
|
from sweatstack_cli.auth import Authenticator
|
|
12
12
|
from sweatstack_cli.auth.tokens import TokenPair
|
|
13
|
-
from sweatstack_cli.exceptions import
|
|
13
|
+
from sweatstack_cli.exceptions import (
|
|
14
|
+
APIError,
|
|
15
|
+
AuthenticationError,
|
|
16
|
+
SecondFactorEnrollmentRequired,
|
|
17
|
+
SecondFactorRequired,
|
|
18
|
+
)
|
|
14
19
|
|
|
15
20
|
if TYPE_CHECKING:
|
|
16
21
|
from pytest_httpx import HTTPXMock
|
|
@@ -193,3 +198,57 @@ class TestAPIClient:
|
|
|
193
198
|
assert request is not None
|
|
194
199
|
assert "User-Agent" in request.headers
|
|
195
200
|
assert request.headers["User-Agent"].startswith("sweatstack-cli/")
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
class TestStepUp:
|
|
204
|
+
"""SweatStack plan 084: a step-up refusal is not an expired session."""
|
|
205
|
+
|
|
206
|
+
@pytest.fixture
|
|
207
|
+
def mock_auth(self, sample_tokens: TokenPair) -> Authenticator:
|
|
208
|
+
auth = Mock(spec=Authenticator)
|
|
209
|
+
auth.get_valid_tokens.return_value = sample_tokens
|
|
210
|
+
return auth
|
|
211
|
+
|
|
212
|
+
def test_a_step_up_401_asks_for_a_login_not_a_new_session(
|
|
213
|
+
self, httpx_mock: HTTPXMock, mock_auth: Authenticator
|
|
214
|
+
) -> None:
|
|
215
|
+
httpx_mock.add_response(
|
|
216
|
+
url="https://app.sweatstack.no/api/v1/applications",
|
|
217
|
+
status_code=401,
|
|
218
|
+
headers={
|
|
219
|
+
"WWW-Authenticate": 'Bearer error="insufficient_user_authentication", acr_values="mfa", max_age=86400'
|
|
220
|
+
},
|
|
221
|
+
json={"code": "second_factor_required", "detail": "This needs a recent confirmation."},
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
with pytest.raises(SecondFactorRequired) as raised:
|
|
225
|
+
APIClient(authenticator=mock_auth).post("/api/v1/applications", json={})
|
|
226
|
+
|
|
227
|
+
assert "Session expired" not in str(raised.value)
|
|
228
|
+
assert "sweatstack login" in str(raised.value) and raised.value.exit_code == 2
|
|
229
|
+
|
|
230
|
+
def test_a_plain_401_is_still_an_expired_session(
|
|
231
|
+
self, httpx_mock: HTTPXMock, mock_auth: Authenticator
|
|
232
|
+
) -> None:
|
|
233
|
+
httpx_mock.add_response(
|
|
234
|
+
url="https://app.sweatstack.no/api/v1/applications", status_code=401
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
with pytest.raises(AuthenticationError, match="Session expired"):
|
|
238
|
+
APIClient(authenticator=mock_auth).post("/api/v1/applications", json={})
|
|
239
|
+
|
|
240
|
+
def test_enrollment_says_where_to_add_a_passkey(
|
|
241
|
+
self, httpx_mock: HTTPXMock, mock_auth: Authenticator
|
|
242
|
+
) -> None:
|
|
243
|
+
detail = "This needs a passkey on your SweatStack account. Add one at https://app.sweatstack.no/settings/passkeys."
|
|
244
|
+
httpx_mock.add_response(
|
|
245
|
+
url="https://app.sweatstack.no/api/v1/applications",
|
|
246
|
+
status_code=403,
|
|
247
|
+
json={"code": "second_factor_enrollment_required", "detail": detail},
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
with pytest.raises(SecondFactorEnrollmentRequired) as raised:
|
|
251
|
+
APIClient(authenticator=mock_auth).post("/api/v1/applications", json={})
|
|
252
|
+
|
|
253
|
+
assert "https://app.sweatstack.no/settings/passkeys" in str(raised.value)
|
|
254
|
+
assert raised.value.exit_code == 2
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""The authorization URL `sweatstack login` opens."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from unittest.mock import Mock
|
|
6
|
+
from urllib.parse import parse_qs, urlsplit
|
|
7
|
+
|
|
8
|
+
from sweatstack_cli.auth import Authenticator
|
|
9
|
+
from sweatstack_cli.auth.pkce import generate_pkce
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_it_asks_for_a_passkey_confirmation() -> None:
|
|
13
|
+
"""SweatStack plan 084 D11: `acr_values=mfa` has a user with a passkey confirm it in the
|
|
14
|
+
browser, and the CLI's tokens carry the confirmation."""
|
|
15
|
+
url = Authenticator(storage=Mock())._build_auth_url(
|
|
16
|
+
"http://localhost:8765/callback", generate_pkce()
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
query = parse_qs(urlsplit(url).query)
|
|
20
|
+
assert query["acr_values"] == ["mfa"]
|
|
21
|
+
assert query["code_challenge_method"] == ["S256"]
|
|
@@ -44,6 +44,23 @@ class TestAppCreate:
|
|
|
44
44
|
json={"name": "Test App"},
|
|
45
45
|
)
|
|
46
46
|
|
|
47
|
+
def test_create_points_to_the_next_step(self, mock_api: MagicMock, tmp_path: Path) -> None:
|
|
48
|
+
"""The app's overview walks the developer from here (SweatStack plan 080)."""
|
|
49
|
+
mock_api.post.return_value = {
|
|
50
|
+
"name": "Test App",
|
|
51
|
+
"id": "abc123",
|
|
52
|
+
"is_private": True,
|
|
53
|
+
"go_live_missing": [{"field": "description", "label": "description"}],
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
with runner.isolated_filesystem(temp_dir=tmp_path):
|
|
57
|
+
result = runner.invoke(app, ["app", "create", "Test App"])
|
|
58
|
+
|
|
59
|
+
assert result.exit_code == 0, result.output
|
|
60
|
+
assert "Next: authorize with your own account" in result.stdout
|
|
61
|
+
assert "/applications/abc123\n" in result.stdout
|
|
62
|
+
assert " - description" in result.stdout
|
|
63
|
+
|
|
47
64
|
def test_create_with_page(self, mock_api: MagicMock, tmp_path: Path) -> None:
|
|
48
65
|
"""Should create an app with page association."""
|
|
49
66
|
mock_api.post.return_value = {
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Tests for authentication commands."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from unittest.mock import MagicMock, patch
|
|
6
|
+
|
|
7
|
+
from typer.testing import CliRunner
|
|
8
|
+
|
|
9
|
+
from sweatstack_cli.commands.auth import _display_name
|
|
10
|
+
from sweatstack_cli.main import app
|
|
11
|
+
|
|
12
|
+
runner = CliRunner()
|
|
13
|
+
|
|
14
|
+
# Shape of GET /api/v1/oauth/userinfo: OIDC claims, no `name`.
|
|
15
|
+
USERINFO = {
|
|
16
|
+
"sub": "user_123",
|
|
17
|
+
"given_name": "Ada",
|
|
18
|
+
"family_name": "Lovelace",
|
|
19
|
+
"email": "ada@example.com",
|
|
20
|
+
"registered_at": "2026-01-01T00:00:00Z",
|
|
21
|
+
"issue": None,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TestDisplayName:
|
|
26
|
+
def test_joins_given_and_family_name(self) -> None:
|
|
27
|
+
assert _display_name(USERINFO) == "Ada Lovelace"
|
|
28
|
+
|
|
29
|
+
def test_given_name_only(self) -> None:
|
|
30
|
+
assert _display_name({"sub": "u", "given_name": "Ada", "family_name": None}) == "Ada"
|
|
31
|
+
|
|
32
|
+
def test_falls_back_to_email_then_sub(self) -> None:
|
|
33
|
+
assert _display_name({"sub": "u", "email": "ada@example.com"}) == "ada@example.com"
|
|
34
|
+
assert _display_name({"sub": "u"}) == "u"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class TestLogin:
|
|
38
|
+
def test_login_always_opens_the_browser(self) -> None:
|
|
39
|
+
"""Signing in again is how a passkey confirmation reaches the CLI (plan 084), so valid
|
|
40
|
+
tokens no longer short-circuit it."""
|
|
41
|
+
with (
|
|
42
|
+
patch("sweatstack_cli.commands.auth.Authenticator") as mock_auth,
|
|
43
|
+
patch("sweatstack_cli.commands.auth.APIClient") as mock_client,
|
|
44
|
+
):
|
|
45
|
+
mock_auth.return_value.get_valid_tokens.return_value = MagicMock()
|
|
46
|
+
mock_client.return_value.get.return_value = USERINFO
|
|
47
|
+
|
|
48
|
+
result = runner.invoke(app, ["login"])
|
|
49
|
+
|
|
50
|
+
assert result.exit_code == 0, result.output
|
|
51
|
+
mock_auth.return_value.login.assert_called_once_with(force=True)
|
|
52
|
+
assert "Logged in as Ada Lovelace" in result.stdout
|
|
53
|
+
|
|
54
|
+
def test_force_is_still_accepted(self) -> None:
|
|
55
|
+
with (
|
|
56
|
+
patch("sweatstack_cli.commands.auth.Authenticator"),
|
|
57
|
+
patch("sweatstack_cli.commands.auth.APIClient") as mock_client,
|
|
58
|
+
):
|
|
59
|
+
mock_client.return_value.get.return_value = USERINFO
|
|
60
|
+
result = runner.invoke(app, ["login", "--force"])
|
|
61
|
+
|
|
62
|
+
assert result.exit_code == 0, result.output
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _jwt(claims: dict) -> str:
|
|
66
|
+
import base64
|
|
67
|
+
import json
|
|
68
|
+
|
|
69
|
+
payload = base64.urlsafe_b64encode(json.dumps(claims).encode()).rstrip(b"=").decode()
|
|
70
|
+
return f"e30.{payload}.signature"
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class TestStatusShowsTheConfirmation:
|
|
74
|
+
def _status(self, claims: dict) -> str:
|
|
75
|
+
tokens = MagicMock(access_token=_jwt(claims))
|
|
76
|
+
with (
|
|
77
|
+
patch("sweatstack_cli.commands.auth.Authenticator") as mock_auth,
|
|
78
|
+
patch("sweatstack_cli.commands.auth.APIClient") as mock_client,
|
|
79
|
+
patch("sweatstack_cli.commands.auth.check_for_update", return_value=(False, None)),
|
|
80
|
+
):
|
|
81
|
+
mock_auth.return_value.get_valid_tokens.return_value = tokens
|
|
82
|
+
mock_client.return_value.get.return_value = USERINFO
|
|
83
|
+
return runner.invoke(app, ["status"]).stdout
|
|
84
|
+
|
|
85
|
+
def test_a_confirmed_login(self) -> None:
|
|
86
|
+
assert "Passkey: confirmed at login" in self._status(
|
|
87
|
+
{"amr": ["pop", "mfa"], "auth_time": 1_800_000_000}
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
def test_an_unconfirmed_login(self) -> None:
|
|
91
|
+
"""Also what an account without a passkey sees, so it promises nothing."""
|
|
92
|
+
output = self._status({"sub": "user_123"})
|
|
93
|
+
assert "Passkey: not confirmed at login\n" in output
|
|
@@ -153,3 +153,61 @@ class TestDeployCreatesAppWhenUnlinked:
|
|
|
153
153
|
assert result.exit_code == 1
|
|
154
154
|
mock_api.post.assert_not_called()
|
|
155
155
|
assert not Path("sweatstack.toml").exists()
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class TestDeployPrintsWhatIsMissing:
|
|
159
|
+
"""After a deploy the CLI prints the server's go-live checklist (SweatStack plan 080)."""
|
|
160
|
+
|
|
161
|
+
def _deploy(self, mock_api: MagicMock, application: dict) -> str:
|
|
162
|
+
mock_api.put.return_value = {**DEPLOYED, "application": application}
|
|
163
|
+
result = runner.invoke(app, ["page", "deploy", "my-page", "--dir", "public"])
|
|
164
|
+
assert result.exit_code == 0, result.output
|
|
165
|
+
return result.output
|
|
166
|
+
|
|
167
|
+
def test_a_private_app_lists_the_fields_and_the_consent_screen(
|
|
168
|
+
self, mock_api: MagicMock, site: Path
|
|
169
|
+
) -> None:
|
|
170
|
+
output = self._deploy(
|
|
171
|
+
mock_api,
|
|
172
|
+
{
|
|
173
|
+
"id": "app_123",
|
|
174
|
+
"name": "My App",
|
|
175
|
+
"is_private": True,
|
|
176
|
+
"go_live_missing": [
|
|
177
|
+
{"field": "description", "label": "description"},
|
|
178
|
+
{"field": "purpose.activities", "label": "purpose for Activities"},
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
)
|
|
182
|
+
assert "Your app is private" in output
|
|
183
|
+
assert " - description\n - purpose for Activities" in output
|
|
184
|
+
assert "Pages fast track" in output
|
|
185
|
+
assert "/applications/app_123/consent" in output
|
|
186
|
+
assert "/publish" not in output
|
|
187
|
+
|
|
188
|
+
def test_a_public_app_missing_a_purpose_says_who_is_turned_away(
|
|
189
|
+
self, mock_api: MagicMock, site: Path
|
|
190
|
+
) -> None:
|
|
191
|
+
output = self._deploy(
|
|
192
|
+
mock_api,
|
|
193
|
+
{
|
|
194
|
+
"id": "app_123",
|
|
195
|
+
"name": "My App",
|
|
196
|
+
"is_private": False,
|
|
197
|
+
"go_live_missing": [{"field": "purpose.wellness", "label": "purpose for Wellness"}],
|
|
198
|
+
},
|
|
199
|
+
)
|
|
200
|
+
assert "turned away until you add" in output and "purpose for Wellness" in output
|
|
201
|
+
|
|
202
|
+
def test_a_ready_app_prints_nothing_extra(self, mock_api: MagicMock, site: Path) -> None:
|
|
203
|
+
output = self._deploy(
|
|
204
|
+
mock_api,
|
|
205
|
+
{"id": "app_123", "name": "My App", "is_private": False, "go_live_missing": []},
|
|
206
|
+
)
|
|
207
|
+
assert "/consent" not in output
|
|
208
|
+
|
|
209
|
+
def test_an_older_server_without_the_checklist_still_links(
|
|
210
|
+
self, mock_api: MagicMock, site: Path
|
|
211
|
+
) -> None:
|
|
212
|
+
output = self._deploy(mock_api, {"id": "app_123", "name": "My App", "is_private": True})
|
|
213
|
+
assert "Your app is private" in output and "/applications/app_123/consent" in output
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"""Tests for authentication commands."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from unittest.mock import MagicMock, patch
|
|
6
|
-
|
|
7
|
-
from typer.testing import CliRunner
|
|
8
|
-
|
|
9
|
-
from sweatstack_cli.commands.auth import _display_name
|
|
10
|
-
from sweatstack_cli.main import app
|
|
11
|
-
|
|
12
|
-
runner = CliRunner()
|
|
13
|
-
|
|
14
|
-
# Shape of GET /api/v1/oauth/userinfo: OIDC claims, no `name`.
|
|
15
|
-
USERINFO = {
|
|
16
|
-
"sub": "user_123",
|
|
17
|
-
"given_name": "Ada",
|
|
18
|
-
"family_name": "Lovelace",
|
|
19
|
-
"email": "ada@example.com",
|
|
20
|
-
"registered_at": "2026-01-01T00:00:00Z",
|
|
21
|
-
"issue": None,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class TestDisplayName:
|
|
26
|
-
def test_joins_given_and_family_name(self) -> None:
|
|
27
|
-
assert _display_name(USERINFO) == "Ada Lovelace"
|
|
28
|
-
|
|
29
|
-
def test_given_name_only(self) -> None:
|
|
30
|
-
assert _display_name({"sub": "u", "given_name": "Ada", "family_name": None}) == "Ada"
|
|
31
|
-
|
|
32
|
-
def test_falls_back_to_email_then_sub(self) -> None:
|
|
33
|
-
assert _display_name({"sub": "u", "email": "ada@example.com"}) == "ada@example.com"
|
|
34
|
-
assert _display_name({"sub": "u"}) == "u"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class TestLogin:
|
|
38
|
-
def test_already_logged_in_uses_userinfo_claims(self) -> None:
|
|
39
|
-
with (
|
|
40
|
-
patch("sweatstack_cli.commands.auth.Authenticator") as mock_auth,
|
|
41
|
-
patch("sweatstack_cli.commands.auth.APIClient") as mock_client,
|
|
42
|
-
):
|
|
43
|
-
mock_auth.return_value.get_valid_tokens.return_value = MagicMock()
|
|
44
|
-
mock_client.return_value.get.return_value = USERINFO
|
|
45
|
-
|
|
46
|
-
result = runner.invoke(app, ["login"])
|
|
47
|
-
|
|
48
|
-
assert result.exit_code == 0, result.output
|
|
49
|
-
assert "Already logged in as Ada Lovelace" in result.stdout
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sweatstack_cli-0.12.1 → sweatstack_cli-0.14.0}/src/sweatstack_cli/templates/page/index.html
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|