summaryrefslogtreecommitdiff
path: root/tests/fakessh/ssh
blob: d3259e4a2523ffe30ca37a41466e7166faf05221 (plain)
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
#!/usr/bin/env python
from __future__ import print_function

import getpass
import sys
PY3 = (sys.version_info[0] >= 3)
if not PY3:
    input = raw_input

server = sys.argv[-1]
if server == 'noserver':
    print('No route to host')
    sys.exit(1)

print("Mock SSH client for tests. Do not enter real security info.")

pw = getpass.getpass('password:')
if pw != 's3cret':
    print('Permission denied!')
    sys.exit(1)

prompt = "$"
while True:
    cmd = input(prompt)
    if cmd.startswith('PS1='):
        prompt = eval(cmd[4:]).replace('\$', '$')
    elif cmd == 'ping':
        print('pong')
    elif cmd.startswith('ls'):
        print('file1.py', 'file2.html', sep='\t')
    elif cmd == 'echo $?':
        print(0)
    elif cmd in ('exit', 'logout'):
        break