32c7336bf6
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
"""Tests para parse_metabase_secret."""
|
|
|
|
import sys
|
|
import os
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
from metabase.parse_metabase_secret import parse_metabase_secret
|
|
|
|
|
|
def test_api_key_explicit():
|
|
res = parse_metabase_secret("mb_abc123def", mode="api_key")
|
|
assert res == {"status": "ok", "mode": "api_key", "api_key": "mb_abc123def"}
|
|
|
|
|
|
def test_session_multiline_email_prefix():
|
|
secret = "hunter2\nemail: admin@captacion.local\nurl: http://localhost:3030"
|
|
res = parse_metabase_secret(secret, mode="session")
|
|
assert res == {
|
|
"status": "ok",
|
|
"mode": "session",
|
|
"email": "admin@captacion.local",
|
|
"password": "hunter2",
|
|
}
|
|
|
|
|
|
def test_auto_detects_session_when_email_present():
|
|
secret = "secretpass\nlogin: bob@example.com"
|
|
res = parse_metabase_secret(secret, mode="auto")
|
|
assert res["mode"] == "session"
|
|
assert res["email"] == "bob@example.com"
|
|
assert res["password"] == "secretpass"
|
|
|
|
|
|
def test_auto_detects_api_key_single_line():
|
|
res = parse_metabase_secret("mb_singleLineKey", mode="auto")
|
|
assert res["mode"] == "api_key"
|
|
assert res["api_key"] == "mb_singleLineKey"
|
|
|
|
|
|
def test_session_without_email_line_errors():
|
|
res = parse_metabase_secret("onlypassword\nurl: http://x", mode="session")
|
|
assert res["status"] == "error"
|
|
assert "email" in res["error"]
|
|
|
|
|
|
def test_empty_secret_errors():
|
|
res = parse_metabase_secret("", mode="auto")
|
|
assert res["status"] == "error"
|
|
assert res["error"] == "empty secret"
|
|
|
|
|
|
def test_invalid_mode_errors():
|
|
res = parse_metabase_secret("mb_x", mode="bogus")
|
|
assert res["status"] == "error"
|
|
assert "invalid mode" in res["error"]
|
|
|
|
|
|
def test_user_prefix_variant():
|
|
secret = "pw\nuser: someone@host.io"
|
|
res = parse_metabase_secret(secret, mode="auto")
|
|
assert res["email"] == "someone@host.io"
|
|
|
|
|
|
def test_email_value_preserves_case():
|
|
secret = "pw\nEMAIL: MixedCase@Host.COM"
|
|
res = parse_metabase_secret(secret, mode="session")
|
|
assert res["email"] == "MixedCase@Host.COM"
|