(self)
| 27 | self.wfile.write(response) |
| 28 | |
| 29 | def do_POST(self): |
| 30 | if self.path == '/auth': |
| 31 | if not 'Content-Length' in self.headers: |
| 32 | self.send_error(403, "Missing form data") |
| 33 | return |
| 34 | |
| 35 | content_length = int(self.headers['Content-Length']) |
| 36 | post_data_str = self.rfile.read(content_length).decode("utf-8") |
| 37 | post_data = {} |
| 38 | for item in post_data_str.split('&'): |
| 39 | k,v = item.split('=') |
| 40 | post_data[k] = v |
| 41 | |
| 42 | username = post_data.get("username") |
| 43 | password = post_data.get("password") |
| 44 | |
| 45 | print("Login request for " + username) |
| 46 | |
| 47 | if username == "extuser1" and password == "test1234": |
| 48 | print("Granted") |
| 49 | self.send_json(200, { |
| 50 | 'user_id': 100, |
| 51 | 'username': 'extuser1', |
| 52 | 'maxQuota': 500, |
| 53 | 'node': { |
| 54 | 'hostname': 'localhost', |
| 55 | 'port': 4444, |
| 56 | 'token': 'test' |
| 57 | } |
| 58 | }) |
| 59 | else: |
| 60 | print("Unauthorized") |
| 61 | return self.send_error(401, "unauthorized") |
| 62 | else: |
| 63 | self.send_error(404, "not found") |
| 64 | |
| 65 | class WebServer(threading.Thread): |
| 66 | def __init__(self): |
nothing calls this directly
no test coverage detected