def testRemovingExistingKeyWithSomeMoreSpaces(self): ssh.RemoveAuthorizedKey(self.tmpname, "ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a") self.assertFileContent(self.tmpname, 'command="/usr/bin/fooserver -t --verbose",from="198.51.100.4"' " ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b\n")
def testRemovingNonExistingKey(self): ssh.RemoveAuthorizedKey( self.tmpname, "ssh-dss AAAAB3Nsdfj230xxjxJjsjwjsjdjU root@test") self.assertFileContent( self.tmpname, "ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a\n" 'command="/usr/bin/fooserver -t --verbose",from="198.51.100.4"' " ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b\n")
def testOtherKeyTypes(self): key_rsa = "ssh-rsa AAAAimnottypingallofthathere0jfJs22 test@test" key_ed25519 = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOlcZ6cpQTGow0LZECRHWn9"\ "7Yvn16J5un501T/RcbfuF fast@secure" key_ecdsa = "ecdsa-sha2-nistp256 AAAAE2VjZHNtoolongk/TNhVbEg= secure@secure" def _ToFileContent(keys): return '\n'.join(keys) + '\n' ssh.AddAuthorizedKeys(self.tmpname, [key_rsa, key_ed25519, key_ecdsa]) self.assertFileContent(self.tmpname, _ToFileContent([self.KEY_A, self.KEY_B, key_rsa, key_ed25519, key_ecdsa])) ssh.RemoveAuthorizedKey(self.tmpname, key_ed25519) self.assertFileContent(self.tmpname, _ToFileContent([self.KEY_A, self.KEY_B, key_rsa, key_ecdsa])) ssh.RemoveAuthorizedKey(self.tmpname, key_rsa) ssh.RemoveAuthorizedKey(self.tmpname, key_ecdsa) self.assertFileContent(self.tmpname, _ToFileContent([self.KEY_A, self.KEY_B]))