kytos-ng / sdntrace_cp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: `PUT /trace and /traces` don't validate payload yet

viniarck opened this issue · comments

PUT /trace and /traces don't validate their OpenAPI spec yet, so if mandatory keys aren't present or wrong type it'll crash the thread of the request in the server.

How to reproduce

  • If you send a request without switch in_port for example:
❯ echo '{ "trace": { "switch": { "dpid": "00:00:00:00:00:00:00:01"}, "eth": { "dl_vlan": 100 } } }' | http PUT http://localhost:8181/api/amlight/sdntrace_cp/trace 
HTTP/1.0 500 INTERNAL SERVER ERROR
Access-Control-Allow-Origin: *
Content-Length: 215
Content-Type: application/json
Date: Thu, 02 Feb 2023 14:44:12 GMT
Server: Werkzeug/2.0.3 Python/3.9.15

{
    "code": 500,
    "description": "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.",
    "name": "Internal Server Error"
}
kytos $> 2023-02-02 11:44:12,857 - ERROR [kytos.core.controller] (Thread-129) Exception on /api/amlight/sdntrace_cp/trace [PUT]                                                           
Traceback (most recent call last):
  File "/home/viniarck/repos/kytos/.direnv/python-3.9.15/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/viniarck/repos/kytos/.direnv/python-3.9.15/lib/python3.9/site-packages/flask/app.py", line 1519, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/viniarck/repos/kytos/.direnv/python-3.9.15/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/viniarck/repos/kytos/.direnv/python-3.9.15/lib/python3.9/site-packages/flask/app.py", line 1517, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/viniarck/repos/kytos/.direnv/python-3.9.15/lib/python3.9/site-packages/flask/app.py", line 1503, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/viniarck/repos/napps/napps/amlight/sdntrace_cp/main.py", line 64, in trace
    result = self.tracepath(entries, stored_flows)
  File "/home/viniarck/repos/napps/napps/amlight/sdntrace_cp/main.py", line 95, in tracepath
    'port': entries['in_port'],
KeyError: 'in_port'

@gretelliz can you reopen this issue? This one was partly addressed.

It's still not validating completely the types based on the spec, for instance a wrong dpid as a list would still crash.