Archived
38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
from karldns.web.components import _code_copy_line, _code_copy_value, _copy_row, _CopyRowParts
|
|||
|
|
|
||
|
|
|
||
|
|
def test_copy_row_parts_derive_secret_state_and_badge() -> None:
|
||
|
|
parts = _CopyRowParts.from_values("Update-URL:", "https://example.test/update", "Secret", mask_secret=True)
|
||
|
|
|
||
|
|
assert parts.is_secret is True
|
||
|
|
assert parts.should_mask is True
|
||
|
|
assert parts.row_class == "copy-field copy-field-secret"
|
||
|
|
assert "ui-badge-secret" in parts.sensitivity_badge
|
||
|
|
|
||
|
|
|
||
|
|
def test_copy_row_masks_secret_values_by_default() -> None:
|
||
|
|
html = _copy_row("Update-URL:", "https://example.test/update", "Secret")
|
||
|
|
|
||
|
|
assert 'class="copy-field copy-field-secret"' in html
|
||
|
|
assert 'type="password"' in html
|
||
|
|
assert "data-secret-toggle" in html
|
||
|
|
assert 'data-copy="https://example.test/update"' in html
|
||
|
|
|
||
|
|
|
||
|
|
def test_copy_row_can_render_unmasked_secret_values() -> None:
|
||
|
|
html = _copy_row("Update-URL:", "https://example.test/update", "Secret", mask_secret=False)
|
||
|
|
|
||
|
|
assert 'class="copy-field copy-field-secret"' in html
|
||
|
|
assert 'type="password"' not in html
|
||
|
|
assert '<code class="copy-pill-value copy-value">https://example.test/update</code>' in html
|
||
|
|
|
||
|
|
|
||
|
|
def test_code_copy_value_prefers_prompt_lines_when_present() -> None:
|
||
|
|
commands = "intro\n$ first command\noutput\n$ second command"
|
||
|
|
|
||
|
|
assert _code_copy_value(commands) == "first command\nsecond command"
|
||
|
|
|
||
|
|
|
||
|
|
def test_code_copy_line_strips_shell_prompt() -> None:
|
||
|
|
assert _code_copy_line("$ curl example") == "curl example"
|
||
|
|
assert _code_copy_line("plain output") == "plain output"
|