def test_response_encode(self):
     _msg = {
         'id': 'test1',
         'id_ref': 'cmd1',
         'status': 200,
         'status_text': 'passed',
         'results': 'foo'
     }
     x = OpenC2Response('test1', 'cmd1', 200, 'passed', 'foo')
     msg = OpenC2MessageEncoder().encode(x)
     self.assertEqual(msg, OpenC2MessageEncoder().encode(_msg))
Пример #2
0
 def test_response_encode(self):
     _msg = {
         'response': {
             'source': {
                 'type': 'openc2:network-firewall'
             }
         },
         'status': '200',
         'results': 'passed',
         'cmdref': '1',
         'status_text': 'foo'
     }
     x = OpenC2Response(openc2.NETWORK_FIREWALL, '200', 'passed', '1',
                        'foo')
     msg = OpenC2MessageEncoder().encode(x)
     self.assertEqual(msg, OpenC2MessageEncoder().encode(_msg))
    def test_message_encode(self):
        _msg = {
            'header': {
                'version': '0.1.0',
                'content_type': 'application/json'
            },
            'command': {
                'action': 'deny',
                'target': {
                    'ip_addr': '1.2.3.4'
                },
                'args': {
                    'foo': 'bar'
                }
            }
        }
        hdr = OpenC2Header()
        body = OpenC2Command(action=openc2.DENY,
                             target=OpenC2Target(openc2.IP_ADDR, '1.2.3.4'),
                             args={'foo': 'bar'})
        msg = OpenC2Message(hdr, body)
        self.assertEqual(OpenC2MessageEncoder().encode(msg),
                         OpenC2MessageEncoder().encode(_msg))

        _msg = {
            'header': {
                'version': '0.1.0',
                'id': 'resp1',
                'created': 'now',
                'sender': 'firewall',
                'content_type': 'application/json'
            },
            'response': {
                'id': 'resp1',
                'id_ref': 'cmd1',
                'status': 200
            }
        }
        hdr = OpenC2Header(id='resp1', created='now', sender='firewall')
        body = OpenC2Response('resp1', 'cmd1', 200)
        msg = OpenC2Message(hdr, body)
        self.assertEqual(OpenC2MessageEncoder().encode(msg),
                         OpenC2MessageEncoder().encode(_msg))
    def test_command_encode(self):
        _msg = {
            'action': 'locate',
            'target': {
                'ip_addr': '1.2.3.4'
            },
            'actuator': {
                'network_firewall': {
                    'where': 'perimeter'
                }
            },
            'args': {
                'foo': 'bar'
            }
        }
        cmd = OpenC2Command(action=openc2.LOCATE,
                            target=OpenC2Target(openc2.IP_ADDR, '1.2.3.4'),
                            actuator=OpenC2Actuator(openc2.NETWORK_FIREWALL))
        cmd.actuator.where = 'perimeter'
        cmd.args.foo = 'bar'
        msg = OpenC2MessageEncoder().encode(cmd)
        self.assertEqual(msg, OpenC2MessageEncoder().encode(_msg))

        _msg = {
            'action': 'locate',
            'target': {
                'file': {
                    'name': 'passwd',
                    'hashes': '0x129823'
                }
            },
            'args': {
                'foo': 'bar'
            }
        }
        cmd = OpenC2Command(action=openc2.LOCATE,
                            target=OpenC2Target(openc2.FILE, name="passwd"),
                            args={'foo': 'bar'})
        cmd.target.hashes = '0x129823'
        msg = OpenC2MessageEncoder().encode(cmd)
        self.assertEqual(msg, OpenC2MessageEncoder().encode(_msg))
Пример #5
0
 def test_command_encode(self):
     _msg = {
         'action': 'locate',
         'target': {
             'type': 'openc2:ipv4-addr',
             'value': '1.2.3.4'
         },
         'actuator': {
             'type': 'openc2:network-firewall',
             'where': 'perimeter',
         },
         'modifiers': {
             'foo': 'bar'
         }
     }
     cmd = OpenC2Command(action=openc2.LOCATE,
                         target=openc2.IPV4_ADDR,
                         actuator=openc2.NETWORK_FIREWALL)
     cmd.target.value = '1.2.3.4'
     cmd.actuator.where = 'perimeter'
     cmd.modifiers.foo = 'bar'
     msg = OpenC2MessageEncoder().encode(cmd)
     self.assertEqual(msg, OpenC2MessageEncoder().encode(_msg))
Пример #6
0
 def test_encode(self):
     _msg = {'foo': 'bar'}
     msg = OpenC2MessageEncoder().encode(_msg)
     self.assertEqual(msg, json.dumps(_msg))
 def test_message_encode_invalid(self):
     msg = OpenC2Message(OpenC2Header())
     cmd = OpenC2MessageEncoder()
     self.assertRaises(ValueError, cmd.encode, msg)