

def test_valid_submission(context, injected_submission=None):
    "Test submitting the valid case (or the first of a list of valid cases)\n    as a HTTP POST. The server has to respond with something sane. This ensures\n    the endpoint actually exists so testing has any effect. This function is\n    called once in the beginning of a test run, and if valid case\n    instrumentation is set, after every injection to check if everything's\n    still working. Unlike injection problems, a failure of a valid case will\n    terminate the whole test run (if valid cases don't work, the validity of\n    the test run would be questionable).\n\n    :param context: The Behave context\n    :param injected_submission: Request body to be sent\n    "
    proxydict = {
        
    }
    if (injected_submission is None):
        injected_submission = '(None)'
    logging.getLogger('requests').setLevel(logging.WARNING)
    if hasattr(context, 'proxy_address'):
        if context.proxy_address:
            proxydict = {
                'http': ('http://' + context.proxy_address),
                'https': ('https://' + context.proxy_address),
            }
    else:
        context.proxy = None
        proxydict = None
    if (context.type == 'json'):
        data = json.dumps(context.submission[0])
    if (context.type == 'urlencode'):
        data = serialise_to_url(context.submission[0], encode=True)
        if (context.submission_method == 'GET'):
            data = ('?' + data)
    if (context.type == 'url-parameters'):
        data = dict_to_urlparams(context.submission[0])
    retry = 0
    while True:
        if (retry == 1):
            auth = authenticate(context, context.authentication_id, acquire_new_authenticator=True)
        else:
            auth = authenticate(context, context.authentication_id)
        retry += 1
        try:
            req = create_http_request(context.submission_method, context.targeturi, context.content_type, data, auth, valid_case=True)
            session = requests.Session()
            resp = session.send(req, timeout=context.timeout, verify=False, proxies=proxydict)
        except requests.exceptions.Timeout:
            assert False, ('Valid case %s request to URI %s timed out after an injection %s' % (context.submission_method, context.targeturi, injected_submission))
        except requests.exceptions.ConnectionError as error:
            assert False, ('Valid case %s request to URI %s after an injected submission %s failed: %s' % (context.submission_method, context.targeturi, injected_submission, error))
        if (resp.status_code in [401, 403, 405, 407, 419, 440]):
            if (retry > 1):
                assert False, ('Valid case %s request to URI %s failed authorisation twice in a row after injected submission %s: Response status code %s' % (context.submission_method, context.targeturi, injected_submission, resp.status_code))
            else:
                continue
        if hasattr(context, 'valid_cases'):
            if (resp.status_code not in context.valid_cases):
                assert False, ('Valid case %s request to URI %s after injected submission %s did not work: Response status code %s' % (context.submission_method, context.targeturi, injected_submission, resp.status_code))
        break

dataset/ETHPy150Open F-Secure/mittn/mittn/httpfuzzer/injector.py test_valid_submission/original