-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Verify fetching data using ssh public key
Add a test case to verify that a new (guest) user can retrieve data (i.e. syslog data) using ssh public key Fixes #304
- Loading branch information
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
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,94 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Generate ssh key pair | ||
Verify that 'guest' user can fetch data using only the 'public' key | ||
""" | ||
|
||
import infamy | ||
import os | ||
import tempfile | ||
from infamy import ssh | ||
|
||
with infamy.Test() as test: | ||
with test.step("Connect to the target device"): | ||
env = infamy.Env() | ||
target = env.attach("target", "mgmt") | ||
|
||
private_key = """-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn | ||
NhAAAAAwEAAQAAAQEAn3zL3StVQZLsP9dnrXxK/PT4m2tjW0M+2GN6JdiIUZyKI9KKHWaf | ||
2uHNdXNUPo0JGwgyj1geOcN2TEdkPd113mO9qrS87wgSzs3gpF93MzACSy8c55dxF5g50w | ||
FnrRNZ1JgciyzryncNQjxYkvbbrIcHX4+ojn3sdx70MJbVeYv60M9IeyXksBENF5+rAYA8 | ||
VpQ+k7cGJeHIdMx6MURwo6nUIoOzTKJ4WhedwTCkWGlEixE98PsynyvB2Ih8a8uiX/nXLb | ||
PT0MsaQohFt0aFOuZ8J6taRu1wHZk/w3hikkKl5HZ5l74GZK0GGfuB1tr3kJR88MBCAITE | ||
7HEvkIjl/wAAA8hbDYq6Ww2Kug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wdawZHdsIJL | ||
JWwNnQ8TdWXPZze0lE9R5b2E4EvJilHvD13pdcIN+hyvGE0QAAAIEAyY+JAtJjDS6wW07E | ||
eTVndLHpDiTZO+tCIP+OO45uYA/8O+IMc+wvIsHCpZC7e3bskg6z2gt5B0DwSnf2Q4zXxP | ||
OFXdOBTFO8XcgWKRo9BIPV6BNH9qrx0Z0m5G45rY6SE9c5Ypv0ExjXRZ/iPWLBSarsv1fF | ||
lrH5aNT6hzZKsc8AAAAMcm9vdEBpbmZhbXkwAQIDBAUGBw== | ||
-----END OPENSSH PRIVATE KEY----- | ||
""" | ||
|
||
public_key_alg = "ssh-rsa" | ||
public_key_data = "AAAAB3NzaC1yc2EAAAADAQABAAABAQCffMvdK1VBkuw/12etfEr89Piba2NbQz7YY3ol2IhRnIoj0oodZp/a4c11c1Q+jQkbCDKPWB45w3ZMR2Q93XXeY72qtLzvCBLOzeCkX3czMAJLLxznl3EXmDnTAWetE1nUmByLLOvKdw1CPFiS9tushwdfj6iOfex3HvQwltV5i/rQz0h7JeSwEQ0Xn6sBgDxWlD6TtwYl4ch0zHoxRHCjqdQig7NMonhaF53BMKRYaUSLET3w+zKfK8HYiHxry6Jf+dcts9PQyxpCiEW3RoU65nwnq1pG7XAdmT/DeGKSQqXkdnmXvgZkrQYZ+4HW2veQlHzwwEIAhMTscS+QiOX/" | ||
|
||
with test.step("Create a guest user on the target device"): | ||
USER = "guest" | ||
|
||
target.put_config_dict("ietf-system", { | ||
"system": { | ||
"authentication": { | ||
"user": [ | ||
{ | ||
"name": USER, | ||
"authorized-key": [ | ||
{ | ||
"name":"guest-ssh-key", | ||
"algorithm":public_key_alg, | ||
"key-data":public_key_data | ||
} | ||
], | ||
"infix-system:shell":"bash" | ||
} | ||
] | ||
} | ||
} | ||
}) | ||
|
||
with test.step("Write private key to a temporary file"): | ||
with tempfile.NamedTemporaryFile(delete=False, mode='w') as key_file: | ||
key_file.write(private_key) | ||
key_file_name = key_file.name | ||
|
||
os.chmod(key_file_name, 0o600) | ||
|
||
with test.step("Verify it is possible to fetch syslog data using public key"): | ||
address = target.get_mgmt_ip() | ||
syslog_file = "./syslog_copy" | ||
|
||
ssh.fetch_file( | ||
remote_user=USER, | ||
remote_address=address, | ||
remote_file="/var/log/syslog", | ||
local_file=syslog_file, | ||
key_file=key_file_name, | ||
check=True, | ||
remove=True | ||
) | ||
|
||
test.succeed() |
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 @@ | ||
../../../infamy/topologies/1x1.dot |
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