MCPcopy Index your code
hub / github.com/python/cpython / test_asn1object

Method test_asn1object

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

Source from the content-addressed store, hash-verified

832
833
834 def test_asn1object(self):
835 expected = (129, 'serverAuth', 'TLS Web Server Authentication',
836 '1.3.6.1.5.5.7.3.1')
837
838 val = ssl._ASN1Object('1.3.6.1.5.5.7.3.1')
839 self.assertEqual(val, expected)
840 self.assertEqual(val.nid, 129)
841 self.assertEqual(val.shortname, 'serverAuth')
842 self.assertEqual(val.longname, 'TLS Web Server Authentication')
843 self.assertEqual(val.oid, '1.3.6.1.5.5.7.3.1')
844 self.assertIsInstance(val, ssl._ASN1Object)
845 self.assertRaises(ValueError, ssl._ASN1Object, 'serverAuth')
846
847 val = ssl._ASN1Object.fromnid(129)
848 self.assertEqual(val, expected)
849 self.assertIsInstance(val, ssl._ASN1Object)
850 self.assertRaises(ValueError, ssl._ASN1Object.fromnid, -1)
851 with self.assertRaisesRegex(ValueError, "unknown NID 100000"):
852 ssl._ASN1Object.fromnid(100000)
853 for i in range(1000):
854 try:
855 obj = ssl._ASN1Object.fromnid(i)
856 except ValueError:
857 pass
858 else:
859 self.assertIsInstance(obj.nid, int)
860 self.assertIsInstance(obj.shortname, str)
861 self.assertIsInstance(obj.longname, str)
862 self.assertIsInstance(obj.oid, (str, type(None)))
863
864 val = ssl._ASN1Object.fromname('TLS Web Server Authentication')
865 self.assertEqual(val, expected)
866 self.assertIsInstance(val, ssl._ASN1Object)
867 self.assertEqual(ssl._ASN1Object.fromname('serverAuth'), expected)
868 self.assertEqual(ssl._ASN1Object.fromname('1.3.6.1.5.5.7.3.1'),
869 expected)
870 with self.assertRaisesRegex(ValueError, "unknown object 'serverauth'"):
871 ssl._ASN1Object.fromname('serverauth')
872
873 def test_purpose_enum(self):
874 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