示例#1
0
 def test_1_load(self):
     hostdict = ssh.HostKeys('hostfile.temp')
     self.assertEquals(2, len(hostdict))
     self.assertEquals(1, len(hostdict.values()[0]))
     self.assertEquals(1, len(hostdict.values()[1]))
     fp = hexlify(hostdict['secure.example.com']
                  ['ssh-rsa'].get_fingerprint()).upper()
     self.assertEquals('E6684DB30E109B67B70FF1DC5C7F1363', fp)
示例#2
0
 def test_2_add(self):
     hostdict = ssh.HostKeys('hostfile.temp')
     hh = '|1|BMsIC6cUIP2zBuXR3t2LRcJYjzM=|hpkJMysjTk/+zzUUzxQEa2ieq6c='
     key = ssh.RSAKey(data=base64.decodestring(keyblob))
     hostdict.add(hh, 'ssh-rsa', key)
     self.assertEquals(3, len(hostdict))
     x = hostdict['foo.example.com']
     fp = hexlify(x['ssh-rsa'].get_fingerprint()).upper()
     self.assertEquals('7EC91BB336CB6D810B124B1353C32396', fp)
     self.assert_(hostdict.check('foo.example.com', key))
示例#3
0
 def test_3_dict(self):
     hostdict = ssh.HostKeys('hostfile.temp')
     self.assert_('secure.example.com' in hostdict)
     self.assert_('not.example.com' not in hostdict)
     self.assert_(hostdict.has_key('secure.example.com'))
     self.assert_(not hostdict.has_key('not.example.com'))
     x = hostdict.get('secure.example.com', None)
     self.assert_(x is not None)
     fp = hexlify(x['ssh-rsa'].get_fingerprint()).upper()
     self.assertEquals('E6684DB30E109B67B70FF1DC5C7F1363', fp)
     i = 0
     for key in hostdict:
         i += 1
     self.assertEquals(2, i)
示例#4
0
    def test_4_dict_set(self):
        hostdict = ssh.HostKeys('hostfile.temp')
        key = ssh.RSAKey(data=base64.decodestring(keyblob))
        key_dss = ssh.DSSKey(data=base64.decodestring(keyblob_dss))
        hostdict['secure.example.com'] = {'ssh-rsa': key, 'ssh-dss': key_dss}
        hostdict['fake.example.com'] = {}
        hostdict['fake.example.com']['ssh-rsa'] = key

        self.assertEquals(3, len(hostdict))
        self.assertEquals(2, len(hostdict.values()[0]))
        self.assertEquals(1, len(hostdict.values()[1]))
        self.assertEquals(1, len(hostdict.values()[2]))
        fp = hexlify(hostdict['secure.example.com']
                     ['ssh-rsa'].get_fingerprint()).upper()
        self.assertEquals('7EC91BB336CB6D810B124B1353C32396', fp)
        fp = hexlify(hostdict['secure.example.com']
                     ['ssh-dss'].get_fingerprint()).upper()
        self.assertEquals('4478F0B9A23CC5182009FF755BC1D26C', fp)