diff options
Diffstat (limited to 'tests/x509/test_x509_ext.py')
| -rw-r--r-- | tests/x509/test_x509_ext.py | 63 | 
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/x509/test_x509_ext.py b/tests/x509/test_x509_ext.py index fc8651c8..5b9fb347 100644 --- a/tests/x509/test_x509_ext.py +++ b/tests/x509/test_x509_ext.py @@ -92,6 +92,69 @@ class TestExtension(object):          assert ext1 != object() +class TestTLSFeature(object): +    def test_not_enum_type(self): +        with pytest.raises(TypeError): +            x509.TLSFeature([3]) + +    def test_empty_list(self): +        with pytest.raises(TypeError): +            x509.TLSFeature([]) + +    def test_repr(self): +        ext1 = x509.TLSFeature([x509.TLSFeatureType.status_request]) +        assert repr(ext1) == ( +            "<TLSFeature(features=[<TLSFeatureType.status_request: 5>])>" +        ) + +    def test_eq(self): +        ext1 = x509.TLSFeature([x509.TLSFeatureType.status_request]) +        ext2 = x509.TLSFeature([x509.TLSFeatureType.status_request]) +        assert ext1 == ext2 + +    def test_ne(self): +        ext1 = x509.TLSFeature([x509.TLSFeatureType.status_request]) +        ext2 = x509.TLSFeature([x509.TLSFeatureType.status_request_v2]) +        ext3 = x509.TLSFeature([ +            x509.TLSFeatureType.status_request, +            x509.TLSFeatureType.status_request_v2 +        ]) +        assert ext1 != ext2 +        assert ext1 != ext3 +        assert ext1 != object() + +    def test_hash(self): +        ext1 = x509.TLSFeature([x509.TLSFeatureType.status_request]) +        ext2 = x509.TLSFeature([x509.TLSFeatureType.status_request]) +        ext3 = x509.TLSFeature([ +            x509.TLSFeatureType.status_request, +            x509.TLSFeatureType.status_request_v2 +        ]) +        assert hash(ext1) == hash(ext2) +        assert hash(ext1) != hash(ext3) + +    def test_iter(self): +        ext1_features = [x509.TLSFeatureType.status_request] +        ext1 = x509.TLSFeature(ext1_features) +        assert len(ext1) == 1 +        assert list(ext1) == ext1_features +        ext2_features = [ +            x509.TLSFeatureType.status_request, +            x509.TLSFeatureType.status_request_v2, +        ] +        ext2 = x509.TLSFeature(ext2_features) +        assert len(ext2) == 2 +        assert list(ext2) == ext2_features + +    def test_indexing(self): +        ext = x509.TLSFeature([ +            x509.TLSFeatureType.status_request, +            x509.TLSFeatureType.status_request_v2, +        ]) +        assert ext[-1] == ext[1] +        assert ext[0] == x509.TLSFeatureType.status_request + +  class TestUnrecognizedExtension(object):      def test_invalid_oid(self):          with pytest.raises(TypeError):  | 
