diff --git a/tests/test_universal_constructed.py b/tests/test_universal_constructed.py index 92678c5..7140ec7 100644 --- a/tests/test_universal_constructed.py +++ b/tests/test_universal_constructed.py @@ -22,7 +22,7 @@ class SequenceTest(univ.Sequence): SequenceTest.componentType = namedtype.NamedTypes( namedtype.NamedType('first', char.PrintableString()), namedtype.OptionalNamedType('optional', char.UTF8String()), - namedtype.DefaultedNamedType('default', useful.UTCTime()), + namedtype.DefaultedNamedType('default', useful.UTCTime().subtype(value='251231235959Z')), namedtype.NamedType('last', char.PrintableString()), ) @@ -87,3 +87,40 @@ def test_setof_two_elements(): def test_setof_two_elements_out_order(): with pytest.raises(PyAsn1Error): decoded, _ = _wrapper(b'3106130142130141', SetOfTest()) + + +def test_sequence_no_default_or_optional(): + decoded, _ = _wrapper(b'3006130141130142', SequenceTest()) + + assert str(decoded['first']) == 'A' + assert str(decoded['default']) == '251231235959Z' + assert not decoded['optional'].isValue + assert str(decoded['last']) == 'B' + + +def test_sequence_with_default_no_optional(): + decoded, _ = _wrapper(b'3015130141170D3234303130313030303030305A130142', SequenceTest()) + + assert str(decoded['first']) == 'A' + assert str(decoded['default']) == '240101000000Z' + assert not decoded['optional'].isValue + assert str(decoded['last']) == 'B' + + +def test_sequence_with_default_and_optional(): + decoded, _ = _wrapper(b'30181301410C0161170D3234303130313030303030305A130142', SequenceTest()) + + assert str(decoded['first']) == 'A' + assert str(decoded['optional']) == 'a' + assert str(decoded['default']) == '240101000000Z' + assert str(decoded['last']) == 'B' + + +def test_sequence_missing_element(): + with pytest.raises(PyAsn1Error): + decoded, _ = _wrapper(b'30151301410C0161170D3234303130313030303030305A', SequenceTest()) + + +def test_encoded_default_value(): + with pytest.raises(PyAsn1Error): + decoded, _ = _wrapper(b'30181301410C0161170D3235313233313233353935395A130142', SequenceTest())