Function to verify that a transaction looks complete. Args: transaction (json object) fabricate_proxy_requests (bool) Whether the post-processor should fabricate proxy requests if they don't exist because the proxy served the response locally. Raises:
(transaction, fabricate_proxy_requests=False)
| 110 | |
| 111 | |
| 112 | def verify_transaction(transaction, fabricate_proxy_requests=False): |
| 113 | """ Function to verify that a transaction looks complete. |
| 114 | |
| 115 | Args: |
| 116 | transaction (json object) |
| 117 | fabricate_proxy_requests (bool) Whether the post-processor should |
| 118 | fabricate proxy requests if they don't exist because the proxy served |
| 119 | the response locally. |
| 120 | |
| 121 | Raises: |
| 122 | VerifySessionError if there is no transaction. |
| 123 | VerifyRequestError if there is a problem with a request. |
| 124 | VerifyResponseError if there is a problem with a response. |
| 125 | """ |
| 126 | if not transaction: |
| 127 | raise VerifySessionError('No transaction found in the session.') |
| 128 | |
| 129 | if "client-request" not in transaction: |
| 130 | raise VerifyRequestError('client-request not found in transaction') |
| 131 | else: |
| 132 | verify_request(transaction["client-request"]) |
| 133 | |
| 134 | if "proxy-request" not in transaction and fabricate_proxy_requests: |
| 135 | if "proxy-response" not in transaction: |
| 136 | raise VerifyRequestError('proxy-response not found in transaction with a client-request') |
| 137 | transaction["proxy-request"] = transaction["client-request"] |
| 138 | if "server-response" not in transaction: |
| 139 | transaction["server-response"] = transaction["proxy-response"] |
| 140 | |
| 141 | # proxy-response nodes can be empty. |
| 142 | if "proxy-response" not in transaction: |
| 143 | raise VerifyResponseError('proxy-response not found in transaction') |
| 144 | |
| 145 | if "proxy-request" in transaction or "server-response" in transaction: |
| 146 | # proxy-request nodes can be empty, so no need to verify_response. |
| 147 | if "proxy-request" not in transaction: |
| 148 | raise VerifyRequestError('proxy-request not found in transaction') |
| 149 | |
| 150 | if "server-response" not in transaction: |
| 151 | raise VerifyResponseError('server-response not found in transaction') |
| 152 | else: |
| 153 | verify_response(transaction["server-response"]) |
| 154 | |
| 155 | |
| 156 | def verify_session(session, fabricate_proxy_requests=False): |
no test coverage detected