|
2 | 2 | import json
|
3 | 3 |
|
4 | 4 | def make_request(method, path, headers=None, data=None):
|
5 |
| - headerstr = "-h {}" if headers is None else f" -h \"{headers}\"" |
6 |
| - datastr = "" if data is None else f" -d \"{data}\"" |
7 |
| - response_string = os.popen(fr'sh run.sh -m {method} -u http://localhost:8080{path} {headerstr} {datastr}').read() |
| 5 | + headerstr = "-h {}" if headers is None else f" -h {headers}" |
| 6 | + datastr = "" if data is None else f" -d {data}" |
| 7 | + response_string = os.popen(f"sh run.sh -m {method} -u http://localhost:8080{path} {headerstr} {datastr}").read() |
8 | 8 | return json.loads(response_string) # JSON con campos status, body y headers
|
9 | 9 |
|
10 | 10 | # Almacena los resultados de las pruebas
|
@@ -52,7 +52,7 @@ def evaluate_response(case, expected_status, actual_status, expected_body=None,
|
52 | 52 | evaluate_response("GET secure with valid Authorization", 200, response['status'], "You accessed a protected resource", response['body'])
|
53 | 53 |
|
54 | 54 | print_case("GET secure with invalid Authorization", "Testing GET request to '/secure' with invalid authorization")
|
55 |
| -response = make_request("GET", "/secure", headers='{\\"Authorization\\":\\"Bearer\\ invalid_token\\"}') |
| 55 | +response = make_request("GET", "/secure", headers='{\\"Authorization\\":\\ \\"Bearer\\ invalid_token\\"}') |
56 | 56 | evaluate_response("GET secure with invalid Authorization", 401, response['status'], "Invalid or missing authorization token", response['body'])
|
57 | 57 |
|
58 | 58 | # Ajuste en PUT request
|
@@ -82,7 +82,7 @@ def evaluate_response(case, expected_status, actual_status, expected_body=None,
|
82 | 82 | response = make_request(
|
83 | 83 | "POST",
|
84 | 84 | "/secure",
|
85 |
| - headers='{\\"Authorization\\": \\"Bearer\\ 12345\\",\\ \\"Content-Type\\":\\ \\"application/json\\"}', |
| 85 | + headers='{\\"Authorization\\":\\ \\"Bearer\\ 12345\\",\\ \\"Content-Type\\":\\ \\"application/json\\"}', |
86 | 86 | data='{"key":}'
|
87 | 87 | )
|
88 | 88 | evaluate_response(
|
|
0 commit comments