Debian Codegraph @

test/integration/targets/secret_masking_ask_pass/ask_pass.py

raw
1 #!/usr/bin/env python
2 # Copyright: Contributors to the Ansible project
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import annotations
6
7 import sys
8
9 import pexpect
10
11 CONN_PASSWORD = "ConnectionPasswordSecret"
12 BECOME_PASSWORD = "BecomePasswordSecret"
13
14 out = pexpect.run(
15 "ansible-playbook ask_pass.yml -i localhost, -c ssh -k -K",
16 events={
17 "SSH password:": f"{CONN_PASSWORD}\n",
18 "BECOME password\\[defaults to SSH password\\]:": f"{BECOME_PASSWORD}\n",
19 },
20 timeout=10,
21 )
22
23 sys.stdout.buffer.write(out)
24
25 if CONN_PASSWORD.encode() in out:
26 sys.exit("FAIL: prompted --ask-pass value leaked in plaintext output")
27
28 if b"ask_pass: $REDACTED$" not in out:
29 sys.exit("FAIL: prompted --ask-pass value was not masked in debug output")
30
31 if BECOME_PASSWORD.encode() in out:
32 sys.exit("FAIL: prompted --ask-become-pass value leaked in plaintext output")
33
34 if b"ask_become_pass: $REDACTED$" not in out:
35 sys.exit("FAIL: prompted --ask-become-pass value was not masked in debug output")
36
37 print("ask-pass masking scenario passed")