sweatstack-cli 0.13.0__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.13.0 → sweatstack_cli-0.14.0}/CHANGELOG.md +20 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/PKG-INFO +1 -1
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/pyproject.toml +1 -1
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/api/client.py +11 -1
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/auth/__init__.py +3 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/commands/auth.py +30 -20
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/exceptions.py +21 -0
- {sweatstack_cli-0.13.0 → 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.14.0/tests/test_commands/test_auth.py +93 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/uv.lock +1 -1
- sweatstack_cli-0.13.0/tests/test_commands/test_auth.py +0 -49
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/.claude/settings.local.json +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/.claude/skills/sweatstack/SKILL.md +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/.claude/skills/sweatstack/api.md +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/.claude/skills/sweatstack/auth.md +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/.claude/skills/sweatstack/cli.md +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/.claude/skills/sweatstack/pyscript.md +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/.claude/skills/sweatstack/webapp.md +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/.gitignore +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/.python-version +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/CREATE_PRIVATE_APP.md +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/DEVELOPMENT.md +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/Makefile +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/PLAN.md +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/README.md +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/plans/001-page-init-command.md +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/__init__.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/api/__init__.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/auth/callback_server.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/auth/jwt.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/auth/pkce.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/auth/tokens.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/commands/__init__.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/commands/app.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/commands/page.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/config.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/console.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/go_live.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/main.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/project.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/py.typed +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/services/__init__.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/services/applications.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/templates/page/index.html +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/src/sweatstack_cli/version_check.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/sweatstack.toml +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/__init__.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/conftest.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_api/__init__.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_auth/__init__.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_auth/test_callback_server.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_auth/test_jwt.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_auth/test_pkce.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_auth/test_tokens.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_commands/__init__.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_commands/test_app.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_commands/test_cli.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_commands/test_page_deploy.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_commands/test_page_init.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_project.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_services/__init__.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_services/test_applications.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_version.py +0 -0
- {sweatstack_cli-0.13.0 → sweatstack_cli-0.14.0}/tests/test_version_check.py +0 -0
|
@@ -4,6 +4,26 @@ 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
|
+
|
|
7
27
|
## [0.13.0] - 2026-10-15
|
|
8
28
|
|
|
9
29
|
### Changed
|
|
@@ -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
|
|
|
@@ -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()
|
|
@@ -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
|
|
|
@@ -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"]
|
|
@@ -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
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sweatstack_cli-0.13.0 → 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
|
|
File without changes
|
|
File without changes
|