Changeset 3764e3b in trunk
- Timestamp:
- 2021-01-07T18:59:57Z (5 years ago)
- Branches:
- master
- Children:
- 7a15f7e
- Parents:
- b887991
- Location:
- integration
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified integration/conftest.py ¶
rb887991 r3764e3b 9 9 from functools import partial 10 10 from json import loads 11 from subprocess import check_call12 11 13 12 from foolscap.furl import ( … … 42 41 cli, 43 42 _run_node, 43 generate_ssh_key 44 44 ) 45 45 … … 344 344 345 345 346 def generate_ssh_key(path):347 """Create a new SSH private/public key pair."""348 check_call(["ckeygen", "--type", "rsa", "--no-passphrase", "--bits", "512",349 "--file", path])350 351 352 346 @pytest.fixture(scope='session') 353 347 @log_call(action_type=u"integration:alice", include_args=[], include_result=False) … … 367 361 368 362 # 2. Enable SFTP on the node: 369 ssh_key_path = join(process.node_dir, "private", "ssh_host_rsa_key")363 host_ssh_key_path = join(process.node_dir, "private", "ssh_host_rsa_key") 370 364 accounts_path = join(process.node_dir, "private", "accounts") 371 365 with open(join(process.node_dir, "tahoe.cfg"), "a") as f: … … 377 371 host_privkey_file = {ssh_key_path} 378 372 accounts.file = {accounts_path} 379 """.format(ssh_key_path=ssh_key_path, accounts_path=accounts_path)) 380 generate_ssh_key(ssh_key_path) 381 382 # 3. Add a SFTP access file with username, password, and rwcap. 373 """.format(ssh_key_path=host_ssh_key_path, accounts_path=accounts_path)) 374 generate_ssh_key(host_ssh_key_path) 375 376 # 3. Add a SFTP access file with username/password and SSH key auth. 377 378 # The client SSH key path is typically going to be somewhere else (~/.ssh, 379 # typically), but for convenience sake for testing we'll put it inside node. 380 client_ssh_key_path = join(process.node_dir, "private", "ssh_client_rsa_key") 381 generate_ssh_key(client_ssh_key_path) 382 # Pub key format is "ssh-rsa <thekey> <username>". We want the key. 383 ssh_public_key = open(client_ssh_key_path + ".pub").read().strip().split()[1] 383 384 with open(accounts_path, "w") as f: 384 385 f.write("""\ 385 alice password {} 386 """.format(rwcap)) 387 # TODO add sftp access with public key 386 alice password {rwcap} 387 388 alice2 ssh-rsa {ssh_public_key} {rwcap} 389 """.format(rwcap=rwcap, ssh_public_key=ssh_public_key)) 388 390 389 391 # 4. Restart the node with new SFTP config. -
TabularUnified integration/test_sftp.py ¶
rb887991 r3764e3b 24 24 25 25 26 def connect_sftp( alice, username="alice", password="password"):26 def connect_sftp(connect_args={"username": "alice", "password": "password"}): 27 27 """Create an SFTP client.""" 28 28 client = SSHClient() 29 29 client.set_missing_host_key_policy(AutoAddPolicy) 30 client.connect( 31 "localhost", username=username, password=password, port=8022, 32 look_for_keys=False 33 ) 30 client.connect("localhost", port=8022, look_for_keys=False, **connect_args) 34 31 sftp = SFTPClient.from_transport(client.get_transport()) 35 32 … … 50 47 51 48 52 def test_bad_account_password(alice): 53 """Can't login with unknown username or wrong password.""" 49 def test_bad_account_password_ssh_key(alice): 50 """ 51 Can't login with unknown username, wrong password, or wrong SSH pub key. 52 """ 54 53 for u, p in [("alice", "wrong"), ("someuser", "password")]: 55 54 with pytest.raises(AuthenticationException): 56 connect_sftp(alice, u, p) 55 connect_sftp(connect_args={ 56 "username": u, "password": p, 57 }) 58 # TODO bad pubkey 59 60 61 def test_ssh_key_auth(alice): 62 """It's possible to login authenticating with SSH public key.""" 63 key_filename = join(alice.node_dir, "private", "ssh_client_rsa_key") 64 sftp = connect_sftp(connect_args={ 65 "username": "alice2", "key_filename": key_filename 66 }) 67 assert sftp.listdir() == [] 57 68 58 69 59 70 def test_read_write_files(alice): 60 71 """It's possible to upload and download files.""" 61 sftp = connect_sftp( alice)72 sftp = connect_sftp() 62 73 f = sftp.file("myfile", "wb") 63 74 f.write(b"abc") … … 76 87 them. 77 88 """ 78 sftp = connect_sftp( alice)89 sftp = connect_sftp() 79 90 assert sftp.listdir() == [] 80 91 … … 102 113 sftp.rmdir("childdir") 103 114 assert sftp.listdir() == [] 115 116 117 def test_rename(alice): 118 """Directories and files can be renamed.""" 119 sftp = connect_sftp() 120 sftp.mkdir("dir") 121 122 filepath = join("dir", "file") 123 with sftp.file(filepath, "wb") as f: 124 f.write(b"abc") 125 126 sftp.rename(filepath, join("dir", "file2")) 127 sftp.rename("dir", "dir2") 128 129 with sftp.file(join("dir2", "file2"), "rb") as f: 130 assert f.read() == b"abc" -
TabularUnified integration/util.py ¶
rb887991 r3764e3b 6 6 from six.moves import StringIO 7 7 from functools import partial 8 from subprocess import check_output 8 from subprocess import check_output, check_call 9 9 10 10 from twisted.python.filepath import ( … … 507 507 ) 508 508 ) 509 510 511 def generate_ssh_key(path): 512 """Create a new SSH private/public key pair.""" 513 check_call(["ckeygen", "--type", "rsa", "--no-passphrase", "--bits", "512", 514 "--file", path])
Note: See TracChangeset
for help on using the changeset viewer.