Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_create_message(self):
message = ContextElement()
message['context_id'] = 4
syntax1 = SyntaxIdElement()
syntax1['uuid'] = uuid.UUID(bytes=b"\xff" * 16)
syntax2 = SyntaxIdElement()
syntax2['uuid'] = uuid.UUID(bytes=b"\xee" * 16)
syntax3 = SyntaxIdElement()
syntax3['uuid'] = uuid.UUID(bytes=b"\xdd" * 16)
message['abstract_syntax'] = syntax1
message['transfer_syntaxes'] = [syntax2, syntax3]
expected = b"\x04\x00" \
b"\x02" \
b"\x00" \
b"\xff\xff\xff\xff\xff\xff\xff\xff" \
b"\xff\xff\xff\xff\xff\xff\xff\xff" \
b"\x00\x00\x00\x00" \
b"\xee\xee\xee\xee\xee\xee\xee\xee" \
b"\xee\xee\xee\xee\xee\xee\xee\xee" \
b"\x00\x00\x00\x00" \
b"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd" \
b"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd" \
def test_create_message(self):
message = SyntaxIdElement()
message['uuid'] = uuid.UUID(bytes=b"\xff" * 16)
message['version'] = 2
expected = b"\xff\xff\xff\xff\xff\xff\xff\xff" \
b"\xff\xff\xff\xff\xff\xff\xff\xff" \
b"\x02\x00\x00\x00"
actual = message.pack()
assert len(message) == 20
assert actual == expected
def test_create_message(self):
message = ContextElement()
message['context_id'] = 4
syntax1 = SyntaxIdElement()
syntax1['uuid'] = uuid.UUID(bytes=b"\xff" * 16)
syntax2 = SyntaxIdElement()
syntax2['uuid'] = uuid.UUID(bytes=b"\xee" * 16)
syntax3 = SyntaxIdElement()
syntax3['uuid'] = uuid.UUID(bytes=b"\xdd" * 16)
message['abstract_syntax'] = syntax1
message['transfer_syntaxes'] = [syntax2, syntax3]
expected = b"\x04\x00" \
b"\x02" \
b"\x00" \
b"\xff\xff\xff\xff\xff\xff\xff\xff" \
b"\xff\xff\xff\xff\xff\xff\xff\xff" \
b"\x00\x00\x00\x00" \
b"\xee\xee\xee\xee\xee\xee\xee\xee" \
b"\xee\xee\xee\xee\xee\xee\xee\xee" \
b"\x00\x00\x00\x00" \
b"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd" \
b"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd" \
b"\x00\x00\x00\x00"
actual = message.pack()
def test_parse_message(self):
actual = SyntaxIdElement()
data = b"\xff\xff\xff\xff\xff\xff\xff\xff" \
b"\xff\xff\xff\xff\xff\xff\xff\xff" \
b"\x02\x00\x00\x00"
data = actual.unpack(data)
assert len(actual) == 20
assert data == b""
assert actual['uuid'].get_value() == uuid.UUID(bytes=b"\xff" * 16)
assert actual['version'].get_value() == 2
def test_create_message(self):
message = ContextElement()
message['context_id'] = 4
syntax1 = SyntaxIdElement()
syntax1['uuid'] = uuid.UUID(bytes=b"\xff" * 16)
syntax2 = SyntaxIdElement()
syntax2['uuid'] = uuid.UUID(bytes=b"\xee" * 16)
syntax3 = SyntaxIdElement()
syntax3['uuid'] = uuid.UUID(bytes=b"\xdd" * 16)
message['abstract_syntax'] = syntax1
message['transfer_syntaxes'] = [syntax2, syntax3]
expected = b"\x04\x00" \
b"\x02" \
b"\x00" \
b"\xff\xff\xff\xff\xff\xff\xff\xff" \
b"\xff\xff\xff\xff\xff\xff\xff\xff" \
b"\x00\x00\x00\x00" \
b"\xee\xee\xee\xee\xee\xee\xee\xee" \
b"\xee\xee\xee\xee\xee\xee\xee\xee" \
b"\x00\x00\x00\x00" \
def __init__(self):
self.fields = OrderedDict([
('result', EnumField(
size=2,
enum_type=ContextResult
)),
('reason', EnumField(
size=2,
enum_type=ResultReason
)),
('transfer_syntax', StructureField(
size=20,
structure_type=SyntaxIdElement
)),
])
super(Result, self).__init__()
context_ndr['abstract_syntax'] = SyntaxIdElement()
context_ndr['abstract_syntax']['uuid'] = \
uuid.UUID("367ABB81-9844-35F1-AD32-98F038001003")
context_ndr['abstract_syntax']['version'] = 2
# https://msdn.microsoft.com/en-us/library/cc243843.aspx
ndr_syntax = SyntaxIdElement()
ndr_syntax['uuid'] = uuid.UUID("8a885d04-1ceb-11c9-9fe8-08002b104860")
ndr_syntax['version'] = 2
context_ndr['transfer_syntaxes'] = [
ndr_syntax
]
context_bind = ContextElement()
context_bind['context_id'] = 1
context_bind['abstract_syntax'] = SyntaxIdElement()
context_bind['abstract_syntax']['uuid'] = \
uuid.UUID("367ABB81-9844-35F1-AD32-98F038001003")
context_bind['abstract_syntax']['version'] = 2
# https://msdn.microsoft.com/en-us/library/cc243715.aspx
# uuid prefix = 6CB71C2C-9812-4540
# uuid prefix bytes = b'\x2c\x1c\xb7\x6c\x12\x98\x40\x45'
# BindTimeFeatureNegotiateBitmask
# https://msdn.microsoft.com/en-us/library/cc243884.aspx
# SecurityContextMultiplexingSupported = 0x01
# KeepConnectionOnOrphanSupported = 0x02
# version number is 1
bind_syntax = SyntaxIdElement()
bind_syntax['uuid'] = b'\x2c\x1c\xb7\x6c\x12\x98\x40\x45' \
b'\x03\x00\x00\x00\x00\x00\x00\x00'
bind_syntax['version'] = 1
context_bind = ContextElement()
context_bind['context_id'] = 1
context_bind['abstract_syntax'] = SyntaxIdElement()
context_bind['abstract_syntax']['uuid'] = \
uuid.UUID("367ABB81-9844-35F1-AD32-98F038001003")
context_bind['abstract_syntax']['version'] = 2
# https://msdn.microsoft.com/en-us/library/cc243715.aspx
# uuid prefix = 6CB71C2C-9812-4540
# uuid prefix bytes = b'\x2c\x1c\xb7\x6c\x12\x98\x40\x45'
# BindTimeFeatureNegotiateBitmask
# https://msdn.microsoft.com/en-us/library/cc243884.aspx
# SecurityContextMultiplexingSupported = 0x01
# KeepConnectionOnOrphanSupported = 0x02
# version number is 1
bind_syntax = SyntaxIdElement()
bind_syntax['uuid'] = b'\x2c\x1c\xb7\x6c\x12\x98\x40\x45' \
b'\x03\x00\x00\x00\x00\x00\x00\x00'
bind_syntax['version'] = 1
context_bind['transfer_syntaxes'] = [
bind_syntax
]
bind['context_elems'] = [
context_ndr,
context_bind
]
bind_data = bind.pack()
log.info("Sending bind request to svcctl")
log.debug(str(bind))
self.handle.write(bind_data)
bind = BindPDU()
bind['pfx_flags'].set_flag(PFlags.PFC_FIRST_FRAG)
bind['pfx_flags'].set_flag(PFlags.PFC_LAST_FRAG)
bind['packed_drep'] = DataRepresentationFormat()
bind['call_id'] = self.call_id
self.call_id += 1
context_ndr = ContextElement()
context_ndr['context_id'] = 0
context_ndr['abstract_syntax'] = SyntaxIdElement()
context_ndr['abstract_syntax']['uuid'] = \
uuid.UUID("367ABB81-9844-35F1-AD32-98F038001003")
context_ndr['abstract_syntax']['version'] = 2
# https://msdn.microsoft.com/en-us/library/cc243843.aspx
ndr_syntax = SyntaxIdElement()
ndr_syntax['uuid'] = uuid.UUID("8a885d04-1ceb-11c9-9fe8-08002b104860")
ndr_syntax['version'] = 2
context_ndr['transfer_syntaxes'] = [
ndr_syntax
]
context_bind = ContextElement()
context_bind['context_id'] = 1
context_bind['abstract_syntax'] = SyntaxIdElement()
context_bind['abstract_syntax']['uuid'] = \
uuid.UUID("367ABB81-9844-35F1-AD32-98F038001003")
context_bind['abstract_syntax']['version'] = 2
# https://msdn.microsoft.com/en-us/library/cc243715.aspx
# uuid prefix = 6CB71C2C-9812-4540
# uuid prefix bytes = b'\x2c\x1c\xb7\x6c\x12\x98\x40\x45'
def __init__(self):
self.fields = OrderedDict([
('uuid', UuidField(little_endian=False)),
('version', IntField(size=4))
])
super(SyntaxIdElement, self).__init__()