def test_sshCopyId(self): with TemporaryDirectory() as tmp: secKey = os.path.join(tmp, 'key') pubKey = secKey + '.pub' authKeys = os.path.expanduser('~/.ssh/authorized_keys') authKeysSic = os.path.join(tmp, 'sic') if os.path.exists(authKeys): shutil.copyfile(authKeys, authKeysSic) os.remove(authKeys) # create new key sshtools.sshKeyGen(secKey) self.assertTrue(os.path.isfile(pubKey)) with open(pubKey, 'rt') as f: pubKeyValue = f.read() try: # test copy pubKey self.assertTrue(sshtools.sshCopyId(pubKey, self.cfg.user(), 'localhost', askPass = '******')) self.assertTrue(os.path.exists(authKeys)) with open(authKeys, 'rt') as f: self.assertIn(pubKeyValue, f.readlines()) finally: # restore original ~/.ssh/authorized_keys file without test pubKey if os.path.exists(authKeysSic): shutil.copyfile(authKeysSic, authKeys)
def test_sshCopyId(self): with TemporaryDirectory() as tmp: secKey = os.path.join(tmp, 'key') pubKey = secKey + '.pub' authKeys = os.path.expanduser('~/.ssh/authorized_keys') authKeysSic = os.path.join(tmp, 'sic') if os.path.exists(authKeys): shutil.copyfile(authKeys, authKeysSic) os.remove(authKeys) # create new key sshtools.sshKeyGen(secKey) self.assertIsFile(pubKey) with open(pubKey, 'rt') as f: pubKeyValue = f.read() try: # test copy pubKey self.assertTrue(sshtools.sshCopyId(pubKey, self.cfg.user(), 'localhost', askPass = '******')) self.assertExists(authKeys) with open(authKeys, 'rt') as f: self.assertIn(pubKeyValue, f.readlines()) finally: # restore original ~/.ssh/authorized_keys file without test pubKey if os.path.exists(authKeysSic): shutil.copyfile(authKeysSic, authKeys)
def test_sshKeyGen(self): with TemporaryDirectory() as tmp: secKey = os.path.join(tmp, 'key') pubKey = secKey + '.pub' # create new key self.assertTrue(sshtools.sshKeyGen(secKey)) self.assertTrue(os.path.isfile(secKey)) self.assertTrue(os.path.isfile(pubKey)) # do not overwrite existing keys self.assertFalse(sshtools.sshKeyGen(secKey))
def test_sshKeyGen(self): with TemporaryDirectory() as tmp: secKey = os.path.join(tmp, 'key') pubKey = secKey + '.pub' # create new key self.assertTrue(sshtools.sshKeyGen(secKey)) self.assertIsFile(secKey) self.assertIsFile(pubKey) # do not overwrite existing keys self.assertFalse(sshtools.sshKeyGen(secKey))