forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_auth_api_key.py
More file actions
63 lines (42 loc) · 1.99 KB
/
Copy pathtest_auth_api_key.py
File metadata and controls
63 lines (42 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Tests for the API-key auth flow."""
from __future__ import annotations
import pytest
from omi_cli import config as cfg
from omi_cli.auth import api_key as api_key_auth
from omi_cli.auth.store import clear_credentials, store_api_key
from omi_cli.errors import UsageError
def test_validate_rejects_empty_key() -> None:
with pytest.raises(UsageError):
api_key_auth.validate_api_key_format("")
def test_validate_rejects_whitespace_only() -> None:
with pytest.raises(UsageError):
api_key_auth.validate_api_key_format(" ")
def test_validate_rejects_non_dev_prefix() -> None:
with pytest.raises(UsageError) as info:
api_key_auth.validate_api_key_format("omi_mcp_" + "x" * 32)
assert "developer key" in str(info.value).lower()
def test_validate_rejects_truncated_dev_key() -> None:
with pytest.raises(UsageError):
api_key_auth.validate_api_key_format("omi_dev_short")
def test_validate_strips_whitespace() -> None:
key = "omi_dev_" + "x" * 32
result = api_key_auth.validate_api_key_format(f" {key}\n")
assert result == key
def test_login_persists_to_disk(config_path) -> None:
key = "omi_dev_" + "y" * 40
profile = api_key_auth.login_with_api_key("default", key, api_base="https://api.staging.omi.me")
assert profile.api_key == key
assert profile.api_base == "https://api.staging.omi.me"
# Re-load from disk to confirm persistence.
reloaded = cfg.load().get_profile("default")
assert reloaded.api_key == key
def test_store_and_clear_round_trip(config_path) -> None:
key = "omi_dev_" + "z" * 40
store_api_key("default", key)
assert cfg.load().get_profile("default").api_key == key
cleared = clear_credentials("default")
assert cleared is True
assert cfg.load().get_profile("default").api_key is None
assert cfg.load().get_profile("default").auth_method is None
def test_clear_credentials_returns_false_for_unconfigured_profile(config_path) -> None:
assert clear_credentials("nonexistent") is False