BVB Source Codes

voltron Show http_api_tests.py Source code

Return Download voltron: download http_api_tests.py Source code - Download voltron Source code - Type:.py
  1. """
  2. Tests that emulate the debugger adaptor and just test the interaction between
  3. the front end and back end API classes. HTTP edition!
  4.  
  5. Tests:
  6. Server (via HTTP)
  7. """
  8.  
  9. import logging
  10. import sys
  11. import json
  12. import time
  13. import subprocess
  14.  
  15. from nose.tools import *
  16.  
  17. import voltron
  18. from voltron.core import *
  19. from voltron.api import *
  20. from voltron.plugin import *
  21.  
  22. import platform
  23. if platform.system() == 'Darwin':
  24.     sys.path.append("/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python")
  25.  
  26. from .common import *
  27.  
  28. import requests
  29.  
  30.  
  31. log = logging.getLogger('tests')
  32.  
  33.  
  34. class APIHostNotSupportedRequest(APIRequest):
  35.     @server_side
  36.     def dispatch(self):
  37.         return APIDebuggerHostNotSupportedErrorResponse()
  38.  
  39.  
  40. class APIHostNotSupportedPlugin(APIPlugin):
  41.     request = "host_not_supported"
  42.     request_class = APIHostNotSupportedRequest
  43.     response_class = APIResponse
  44.  
  45.  
  46. def setup():
  47.     global server, client, target, pm, adaptor, methods
  48.  
  49.     log.info("setting up API tests")
  50.  
  51.     # set up voltron
  52.     voltron.setup_env()
  53.     voltron.config['server'] = {
  54.         "listen": {
  55.             "tcp":     ["127.0.0.1", 5555]
  56.         }
  57.     }
  58.     pm = PluginManager()
  59.     plugin = pm.debugger_plugin_for_host('mock')
  60.     adaptor = plugin.adaptor_class()
  61.     voltron.debugger = adaptor
  62.  
  63.     # inject mock methods
  64.     inject_mock(adaptor)
  65.  
  66.     # start up a voltron server
  67.     server = Server()
  68.     server.start()
  69.  
  70.     time.sleep(2)
  71.  
  72.  
  73. def teardown():
  74.     server.stop()
  75.     time.sleep(2)
  76.  
  77.  
  78. def test_disassemble():
  79.     data = requests.get('http://localhost:5555/api/disassemble?count=16').text
  80.     res = APIResponse(data=data)
  81.     assert res.is_success
  82.     assert res.disassembly == disassemble_response
  83.  
  84.  
  85. def test_command():
  86.     data = requests.get('http://localhost:5555/api/command?command=reg%20read').text
  87.     res = APIResponse(data=data)
  88.     assert res.is_success
  89.     assert res.output == command_response
  90.  
  91.  
  92. def test_targets():
  93.     data = requests.get('http://localhost:5555/api/targets').text
  94.     res = api_response('targets', data=data)
  95.     assert res.is_success
  96.     assert res.targets == targets_response
  97.  
  98.  
  99. def test_memory():
  100.     data = requests.get('http://localhost:5555/api/registers').text
  101.     res = api_response('registers', data=data)
  102.     url = 'http://localhost:5555/api/memory?address={}&length=64'.format(res.registers['rip'])
  103.     data = requests.get(url).text
  104.     res = api_response('memory', data=data)
  105.     assert res.is_success
  106.     assert res.memory == memory_response
  107.  
  108.  
  109. def test_registers():
  110.     data = requests.get('http://localhost:5555/api/registers').text
  111.     res = api_response('registers', data=data)
  112.     assert res.is_success
  113.     assert res.registers == registers_response
  114.  
  115.  
  116. def test_stack_length_missing():
  117.     data = requests.get('http://localhost:5555/api/stack').text
  118.     res = APIErrorResponse(data=data)
  119.     assert res.is_error
  120.     assert res.message == 'length'
  121.  
  122.  
  123. def test_stack():
  124.     data = requests.get('http://localhost:5555/api/stack?length=64').text
  125.     res = api_response('stack', data=data)
  126.     assert res.is_success
  127.     assert res.memory == stack_response
  128.  
  129.  
  130. def test_state():
  131.     data = requests.get('http://localhost:5555/api/state').text
  132.     res = api_response('state', data=data)
  133.     assert res.is_success
  134.     assert res.state == state_response
  135.  
  136.  
  137. def test_version():
  138.     data = requests.get('http://localhost:5555/api/version').text
  139.     res = api_response('version', data=data)
  140.     assert res.is_success
  141.     assert res.api_version == 1.1
  142.     assert res.host_version == 'lldb-something'
  143.  
  144.  
  145. def test_bad_json():
  146.     data = requests.post('http://localhost:5555/api/request', data='xxx').text
  147.     res = APIResponse(data=data)
  148.     assert res.is_error
  149.     assert res.code == 0x1001
  150.  
  151.  
  152. def test_bad_request():
  153.     data = requests.post('http://localhost:5555/api/request', data='{"type":"request","request":"no_such_request"}').text
  154.     res = APIResponse(data=data)
  155.     assert res.is_error
  156.     assert res.code == 0x1002
  157.  
  158.  
  159. def test_breakpoints():
  160.     data = requests.get('http://localhost:5555/api/breakpoints').text
  161.     res = api_response('breakpoints', data=data)
  162.     assert res.is_success
  163.     assert res.breakpoints == breakpoints_response
  164.  
downloadhttp_api_tests.py Source code - Download voltron Source code
Related Source Codes/Software:
IGListKit - A data-driven UICollectionView framework for build... 2017-01-11
androidmvp - MVP Android Example 2017-01-11
svelte - The magical disappearing UI framework ... 2017-01-11
kcptun - A Simple UDP Tunnel Based On KCP 2017-01-11
poisontap - Exploits locked/password protected computers over ... 2017-01-10
ecma262 - Status, process, and documents for ECMA262 ... 2017-01-11
react-native-elements - React Native Elements UI Toolkit 2017-01-11
tensorflow-zh - Google new open source ai system TensorFlow Chines... 2017-01-11
forum - Blue light (the Lantern) the official BBS 2017-01-11
socketcluster - Highly scalable realtime framework ... 2017-01-11
mobile-chrome-apps - Chrome apps on Android and iOS 2017-02-20
pycrumbs - Bits and bytes of Python from the Internet 2017-02-20
drupal - Verbatim mirror of the git.drupal.org repository f... 2017-02-20
elasticsearch-head - A web front end for an elastic search cluster 2017-02-19
launchrocket - A Mac PrefPane to manage all your Homebrew-install... 2017-02-19
jquery-boilerplate - A jump-start for jQuery plugins development ... 2017-02-19
MVVMReactiveCocoa - GitBucket iOS A 2017-02-19
ios-webkit-debug-proxy - A DevTools proxy (Chrome Remote Debugging Protocol... 2017-02-19
jump.js - A modern smooth scrolling library. ... 2017-02-19
GoSublime - A Golang plugin collection for SublimeText **3**, ... 2017-02-19

 Back to top