From 887094f2d3588e6ba7466c14e5da4ee20b8e456b Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 26 Sep 2024 20:34:45 -0700 Subject: [PATCH] Added tests Signed-off-by: Abhijeet Kasurde --- .../targets/uri/files/testserver.py | 24 +++++++++++++++++-- test/integration/targets/uri/tasks/main.yml | 13 ++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/test/integration/targets/uri/files/testserver.py b/test/integration/targets/uri/files/testserver.py index 3a83724ce87..52fe9285a93 100644 --- a/test/integration/targets/uri/files/testserver.py +++ b/test/integration/targets/uri/files/testserver.py @@ -6,10 +6,30 @@ import sys if __name__ == '__main__': PORT = int(sys.argv[1]) + content_type_json = "application/json" class Handler(http.server.SimpleHTTPRequestHandler): - pass + def do_GET(self): + if self.path == '/chunked': + self.request.sendall( + b'HTTP/1.1 200 OK\r\n' + b'Transfer-Encoding: chunked\r\n' + b'\r\n' + b'a\r\n' # size of the chunk (0xa = 10) + b'123456' + ) + elif self.path.endswith('json'): + try: + with open(self.path[1:]) as f: + self.send_response(200) + self.send_header("Content-type", content_type_json) + self.end_headers() + self.wfile.write(bytes(f.read(), "utf-8")) + except IOError: + self.send_error(404) + else: + self.send_error(404) - Handler.extensions_map['.json'] = 'application/json' + Handler.extensions_map['.json'] = content_type_json httpd = socketserver.TCPServer(("", PORT), Handler) httpd.serve_forever() diff --git a/test/integration/targets/uri/tasks/main.yml b/test/integration/targets/uri/tasks/main.yml index b156f82cb99..d1638f28468 100644 --- a/test/integration/targets/uri/tasks/main.yml +++ b/test/integration/targets/uri/tasks/main.yml @@ -100,6 +100,19 @@ - "{{fail_checksum.results}}" - "{{fail.results}}" +- name: Request IncompleteRead from localhost + uri: + return_content: yes + url: http://localhost:{{ http_port }}/chunked + register: r + ignore_erros: true + +- name: Check if IncompleteRead raises error + assert: + that: + - r.failed + - "'HTTP Error while fetching' in r.msg" + - name: test https fetch to a site with mismatched hostname and certificate uri: url: "https://{{ badssl_host }}/"