def test_time_fields(self): """ Parses invalid published, valid-after, fresh-until, and valid-until fields. All are simply datetime values. """ expected = datetime.datetime(2012, 9, 2, 22, 0, 0) test_value = '2012-09-02 22:00:00' sig = DetachedSignature.create({ 'valid-after': test_value, 'fresh-until': test_value, 'valid-until': test_value, }) self.assertEqual(expected, sig.valid_after) self.assertEqual(expected, sig.fresh_until) self.assertEqual(expected, sig.valid_until) test_values = ( '', ' ', '2012-12-12', '2012-12-12 01:01:', '2012-12-12 01:a1:01', ) for test_value in test_values: content = DetachedSignature.content({'valid-after': test_value}) self.assertRaises(ValueError, DetachedSignature, content, True) sig = DetachedSignature(content, False) self.assertEqual(None, sig.valid_after)
def test_blank_lines(self): """ Includes blank lines, which should be ignored. """ sig = DetachedSignature.create({'consensus-digest': '6D3CC0EFA408F228410A4A8145E1B0BB0670E442\n\n\n'}) self.assertEqual('6D3CC0EFA408F228410A4A8145E1B0BB0670E442', sig.consensus_digest)
def test_unrecognized_line(self): """ Includes unrecognized content in the descriptor. """ sig = DetachedSignature.create({'pepperjack': 'is oh so tasty!'}) self.assertEqual(['pepperjack is oh so tasty!'], sig.get_unrecognized_lines())
def test_missing_fields(self): """ Parse a detached signature where a mandatory field is missing. """ mandatory_fields = ( 'consensus-digest', 'valid-after', 'fresh-until', 'valid-until', ) for excluded_field in mandatory_fields: content = DetachedSignature.content(exclude = (excluded_field,)) self.assertRaises(ValueError, DetachedSignature, content, True) sig = DetachedSignature(content, False) if excluded_field == 'consensus-digest': self.assertEqual(None, sig.consensus_digest) else: self.assertEqual(40, len(sig.consensus_digest))
def test_minimal(self): """ Parses a minimal detached signature. """ sig = DetachedSignature.create() self.assertEqual('6D3CC0EFA408F228410A4A8145E1B0BB0670E442', sig.consensus_digest) self.assertTrue(sig.valid_after is not None) self.assertTrue(sig.fresh_until is not None) self.assertTrue(sig.valid_until is not None) self.assertEqual([], sig.additional_digests) self.assertEqual([], sig.additional_signatures) self.assertEqual([], sig.signatures) self.assertEqual([], sig.get_unrecognized_lines())
def test_from_str(self): sig = DetachedSignature.create() self.assertEqual(sig, DetachedSignature.from_str(str(sig)))