MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_asn1object

Method test_asn1object

Lib/test/test_ssl.py:753–790  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

751
752
753 def test_asn1object(self):
754 expected = (129, 'serverAuth', 'TLS Web Server Authentication',
755 '1.3.6.1.5.5.7.3.1')
756
757 val = ssl._ASN1Object('1.3.6.1.5.5.7.3.1')
758 self.assertEqual(val, expected)
759 self.assertEqual(val.nid, 129)
760 self.assertEqual(val.shortname, 'serverAuth')
761 self.assertEqual(val.longname, 'TLS Web Server Authentication')
762 self.assertEqual(val.oid, '1.3.6.1.5.5.7.3.1')
763 self.assertIsInstance(val, ssl._ASN1Object)
764 self.assertRaises(ValueError, ssl._ASN1Object, 'serverAuth')
765
766 val = ssl._ASN1Object.fromnid(129)
767 self.assertEqual(val, expected)
768 self.assertIsInstance(val, ssl._ASN1Object)
769 self.assertRaises(ValueError, ssl._ASN1Object.fromnid, -1)
770 with self.assertRaisesRegex(ValueError, "unknown NID 100000"):
771 ssl._ASN1Object.fromnid(100000)
772 for i in range(1000):
773 try:
774 obj = ssl._ASN1Object.fromnid(i)
775 except ValueError:
776 pass
777 else:
778 self.assertIsInstance(obj.nid, int)
779 self.assertIsInstance(obj.shortname, str)
780 self.assertIsInstance(obj.longname, str)
781 self.assertIsInstance(obj.oid, (str, type(None)))
782
783 val = ssl._ASN1Object.fromname('TLS Web Server Authentication')
784 self.assertEqual(val, expected)
785 self.assertIsInstance(val, ssl._ASN1Object)
786 self.assertEqual(ssl._ASN1Object.fromname('serverAuth'), expected)
787 self.assertEqual(ssl._ASN1Object.fromname('1.3.6.1.5.5.7.3.1'),
788 expected)
789 with self.assertRaisesRegex(ValueError, "unknown object 'serverauth'"):
790 ssl._ASN1Object.fromname('serverauth')
791
792 def test_purpose_enum(self):
793 val = ssl._ASN1Object('1.3.6.1.5.5.7.3.1')

Callers

nothing calls this directly

Calls 6

assertIsInstanceMethod · 0.80
fromnidMethod · 0.80
assertRaisesRegexMethod · 0.80
assertEqualMethod · 0.45
assertRaisesMethod · 0.45
fromnameMethod · 0.45

Tested by

no test coverage detected