• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#***************************************************************************
4#                                  _   _ ____  _
5#  Project                     ___| | | |  _ \| |
6#                             / __| | | | |_) | |
7#                            | (__| |_| |  _ <| |___
8#                             \___|\___/|_| \_\_____|
9#
10# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11#
12# This software is licensed as described in the file COPYING, which
13# you should have received as part of this distribution. The terms
14# are also available at https://curl.se/docs/copyright.html.
15#
16# You may opt to use, copy, modify, merge, publish, distribute and/or sell
17# copies of the Software, and permit persons to whom the Software is
18# furnished to do so, under the terms of the COPYING file.
19#
20# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21# KIND, either express or implied.
22#
23# SPDX-License-Identifier: curl
24#
25###########################################################################
26#
27import json
28import logging
29from typing import Optional, Tuple, List, Dict
30import pytest
31
32from testenv import Env, CurlClient, ExecResult
33
34
35log = logging.getLogger(__name__)
36
37
38@pytest.mark.skipif(condition=Env.setup_incomplete(),
39                    reason=f"missing: {Env.incomplete_reason()}")
40@pytest.mark.skipif(condition=not Env.httpd_is_at_least('2.4.55'),
41                    reason=f"httpd version too old for this: {Env.httpd_version()}")
42class TestErrors:
43
44    @pytest.fixture(autouse=True, scope='class')
45    def _class_scope(self, env, httpd, nghttpx):
46        if env.have_h3():
47            nghttpx.start_if_needed()
48        httpd.clear_extra_configs()
49        httpd.reload()
50
51    # download 1 file, check that we get CURLE_PARTIAL_FILE
52    @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
53    def test_05_01_partial_1(self, env: Env, httpd, nghttpx, repeat,
54                              proto):
55        if proto == 'h3' and not env.have_h3():
56            pytest.skip("h3 not supported")
57        count = 1
58        curl = CurlClient(env=env)
59        urln = f'https://{env.authority_for(env.domain1, proto)}' \
60               f'/curltest/tweak?id=[0-{count - 1}]'\
61               '&chunks=3&chunk_size=16000&body_error=reset'
62        r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
63            '--retry', '0'
64        ])
65        assert r.exit_code != 0, f'{r}'
66        invalid_stats = []
67        for idx, s in enumerate(r.stats):
68            if 'exitcode' not in s or s['exitcode'] not in [18, 56, 92]:
69                invalid_stats.append(f'request {idx} exit with {s["exitcode"]}')
70        assert len(invalid_stats) == 0, f'failed: {invalid_stats}'
71
72    # download files, check that we get CURLE_PARTIAL_FILE for all
73    @pytest.mark.parametrize("proto", ['h2', 'h3'])
74    def test_05_02_partial_20(self, env: Env, httpd, nghttpx, repeat,
75                              proto):
76        if proto == 'h3' and not env.have_h3():
77            pytest.skip("h3 not supported")
78        if proto == 'h3' and env.curl_uses_lib('quiche'):
79            pytest.skip("quiche not reliable, sometimes reports success")
80        count = 20
81        curl = CurlClient(env=env)
82        urln = f'https://{env.authority_for(env.domain1, proto)}' \
83               f'/curltest/tweak?id=[0-{count - 1}]'\
84               '&chunks=5&chunk_size=16000&body_error=reset'
85        r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
86            '--retry', '0', '--parallel',
87        ])
88        assert r.exit_code != 0, f'{r}'
89        assert len(r.stats) == count, f'did not get all stats: {r}'
90        invalid_stats = []
91        for idx, s in enumerate(r.stats):
92            if 'exitcode' not in s or s['exitcode'] not in [18, 56, 92, 95]:
93                invalid_stats.append(f'request {idx} exit with {s["exitcode"]}\n{s}')
94        assert len(invalid_stats) == 0, f'failed: {invalid_stats}'
95