-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
2,324 additions
and
1 deletion.
There are no files selected for viewing
205 changes: 205 additions & 0 deletions
205
tests/__snapshots__/test_askpass/test_askpass_visual[test0].svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
209 changes: 209 additions & 0 deletions
209
tests/__snapshots__/test_askpass/test_askpass_visual[test10].svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
205 changes: 205 additions & 0 deletions
205
tests/__snapshots__/test_askpass/test_askpass_visual[test1].svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
205 changes: 205 additions & 0 deletions
205
tests/__snapshots__/test_askpass/test_askpass_visual[test2].svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
205 changes: 205 additions & 0 deletions
205
tests/__snapshots__/test_askpass/test_askpass_visual[test3].svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
205 changes: 205 additions & 0 deletions
205
tests/__snapshots__/test_askpass/test_askpass_visual[test4].svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
205 changes: 205 additions & 0 deletions
205
tests/__snapshots__/test_askpass/test_askpass_visual[test5].svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
205 changes: 205 additions & 0 deletions
205
tests/__snapshots__/test_askpass/test_askpass_visual[test6].svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
205 changes: 205 additions & 0 deletions
205
tests/__snapshots__/test_askpass/test_askpass_visual[test7].svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
206 changes: 206 additions & 0 deletions
206
tests/__snapshots__/test_askpass/test_askpass_visual[test8].svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
209 changes: 209 additions & 0 deletions
209
tests/__snapshots__/test_askpass/test_askpass_visual[test9].svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from _pytest.fixtures import FixtureRequest | ||
from os import getpid, environ | ||
from asyncio import create_subprocess_exec as async_exec | ||
from asyncio.subprocess import PIPE | ||
import pytest | ||
from moulti.app import Moulti | ||
from .common import moulti_test | ||
assert moulti_test | ||
|
||
PASSWORD = 'The secret!' | ||
INPUT_SECRET = ['ctrl+y', *PASSWORD] | ||
INPUT_YES = ['ctrl+y', *'yes'] | ||
HIT_1ST_BUTTON = ['ctrl+y'] | ||
HIT_2ND_BUTTON = ['ctrl+y', 'tab'] | ||
FINGERPRINT_PROMPT = """The authenticity of host '[example.org]:22 ([12.34.56.78]:22)' can't be established. | ||
ED25519 key fingerprint is SHA256:s2DYbBHs784Xe7/LvXCybJe6ncu+x2Dn9mxLwXQ+TfM. | ||
Are you sure you want to continue connecting (yes/no/[fingerprint])?""" | ||
|
||
TESTS = [ | ||
{'cmd': ['moulti-askpass']}, | ||
{'cmd': ['moulti-askpass'], 'env': {'MOULTI_ASKPASS_DEFAULT_PROMPT': 'Env-based custom prompt?'}}, | ||
{'cmd': ['moulti-askpass-become-password']}, | ||
{'cmd': ['moulti-askpass-connection-password']}, | ||
{'cmd': ['moulti-askpass-vault-client']}, | ||
{'cmd': ['moulti-askpass', 'Command-line custom prompt?']}, | ||
{'cmd': ['moulti-askpass', '--vault-id', 'SHINY_VAULT']}, | ||
{'cmd': ['moulti-askpass', FINGERPRINT_PROMPT], 'input': INPUT_YES, 'output': 'yes'}, | ||
{'cmd': ['moulti-askpass'], 'env': {'SSH_ASKPASS_PROMPT': 'none'}, 'input': HIT_1ST_BUTTON, 'output': ''}, | ||
{'cmd': ['moulti-askpass'], 'env': {'SSH_ASKPASS_PROMPT': 'confirm'}, 'input': HIT_1ST_BUTTON, 'output': ''}, | ||
{'cmd': ['moulti-askpass'], 'env': {'SSH_ASKPASS_PROMPT': 'confirm'}, 'input': HIT_2ND_BUTTON, 'output': '', 'rc': 1}, | ||
] | ||
for index, test in enumerate(TESTS): | ||
test['index'] = index | ||
|
||
@pytest.mark.parametrize('test', TESTS) | ||
def test_askpass_visual(test, moulti_test, monkeypatch): | ||
"""Visual tests: ensure the askpass step looks like expected.""" | ||
for name, value in test.get('env', {}).items(): | ||
monkeypatch.setenv(name, value) | ||
async def run_before(pilot): | ||
await pilot.pause(.5) | ||
await pilot.press(*test.get('input', INPUT_SECRET)) | ||
assert moulti_test(command=test['cmd'], run_before=run_before) | ||
|
||
@pytest.mark.parametrize('test', TESTS) | ||
async def test_askpass_password(test, moulti_test, monkeypatch, request: FixtureRequest): | ||
"""Functional tests: ensure moulti-askpass returns the right secret and return code.""" | ||
instance_name = f'{getpid()}-askpass-{test["index"]}' | ||
env = environ | test.get('env', {}) | {'MOULTI_INSTANCE': instance_name} | ||
moulti_app = Moulti(instance_name=instance_name) | ||
async with moulti_app.run_test() as pilot: | ||
proc = await async_exec(*test['cmd'], env=env, stdout=PIPE) | ||
await pilot.pause(.5) | ||
await pilot.press(*test.get('input', INPUT_SECRET), 'enter') | ||
password = await proc.stdout.readline() | ||
await proc.wait() | ||
assert proc.returncode == test.get('rc', 0) | ||
assert password.decode('utf-8').rstrip() == test.get('output', PASSWORD) | ||
await pilot.press('q') |