def test_empty(self): """ Verify that the regCred object is not empty. """ try: rc1 = rc.parseRegCred(None) self.fail("parsed nil string") except RuntimeError: pass
def test_constructor(self): """ Test the object constructor.""" now = time.time() rng = xr.SimpleRNG(now) name = 'foo' id_ = self._build_id(rng) ck_priv = RSA.generate(1024, os.urandom) ck_pub = ck_priv.publickey() ck_ = ck_pub.exportKey(format='OpenSSH') sk_priv = RSA.generate(1024, os.urandom) sk_pub = sk_priv.publickey() sk_ = sk_pub.exportKey(format='OpenSSH') ep_count = 1 + rng.nextInt16(3) # so from 1 to 3 end_points = [] for ndx in range(ep_count): port = 1000 + rng.nextInt16(64000) # values don't much matter ep_ = "TcpEndPoint: 127.0.0.1:%d" % port end_points.append(ep_) dv1 = DecimalVersion(rng.nextByte(), rng.nextByte(), rng.nextByte(), rng.nextByte()) # name, id_, ck_, sk_, end_points, version rc1 = rc.RegCred(name, id_, ck_, sk_, end_points, dv1) self.assertEqual(rc1.getName(), name) self.assertEqual(rc1.getID(), id_) self.assertEqual(rc1.getCommsPubKey(), ck_) self.assertEqual(rc1.getSigPubKey(), sk_) eps1 = rc1.getEndPoints() self.assertEqual(len(end_points), len(eps1)) for ndx, ep_ in enumerate(eps1): self.assertEqual(ep_, eps1[ndx]) # ye olde round-trip str1 = rc1.__str__() rc2 = rc.parseRegCred(str1) str2 = rc2.__str__() self.assertEqual(str2, str1)