• 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 logging
28import pytest
29
30from testenv import Env
31from testenv import CurlClient
32
33
34log = logging.getLogger(__name__)
35
36
37@pytest.mark.skipif(condition=Env.setup_incomplete(),
38                    reason=f"missing: {Env.incomplete_reason()}")
39class TestBasic:
40
41    @pytest.fixture(autouse=True, scope='class')
42    def _class_scope(self, env, nghttpx):
43        if env.have_h3():
44            nghttpx.start_if_needed()
45
46    # simple http: GET
47    def test_01_01_http_get(self, env: Env, httpd):
48        curl = CurlClient(env=env)
49        url = f'http://{env.domain1}:{env.http_port}/data.json'
50        r = curl.http_get(url=url)
51        assert r.exit_code == 0
52        assert r.response['status'] == 200
53        assert r.json['server'] == env.domain1
54
55    # simple https: GET, any http version
56    def test_01_02_https_get(self, env: Env, httpd):
57        curl = CurlClient(env=env)
58        url = f'https://{env.domain1}:{env.https_port}/data.json'
59        r = curl.http_get(url=url)
60        assert r.exit_code == 0
61        assert r.response['status'] == 200
62        assert r.json['server'] == env.domain1
63
64    # simple https: GET, h2 wanted and got
65    def test_01_03_h2_get(self, env: Env, httpd):
66        curl = CurlClient(env=env)
67        url = f'https://{env.domain1}:{env.https_port}/data.json'
68        r = curl.http_get(url=url, extra_args=['--http2'])
69        assert r.exit_code == 0
70        assert r.response['status'] == 200
71        assert r.response['protocol'] == 'HTTP/2'
72        assert r.json['server'] == env.domain1
73
74    # simple https: GET, h2 unsupported, fallback to h1
75    def test_01_04_h2_unsupported(self, env: Env, httpd):
76        curl = CurlClient(env=env)
77        url = f'https://{env.domain2}:{env.https_port}/data.json'
78        r = curl.http_get(url=url, extra_args=['--http2'])
79        assert r.exit_code == 0
80        assert r.response['status'] == 200
81        assert r.response['protocol'] == 'HTTP/1.1'
82        assert r.json['server'] == env.domain2
83
84    # simple h3: GET, want h3 and get it
85    @pytest.mark.skipif(condition=not Env.have_h3(), reason="h3 not supported")
86    def test_01_05_h3_get(self, env: Env, httpd, nghttpx):
87        curl = CurlClient(env=env)
88        url = f'https://{env.domain1}:{env.h3_port}/data.json'
89        r = curl.http_get(url=url, extra_args=['--http3'])
90        assert r.exit_code == 0, f'{r}'
91        assert r.response['status'] == 200
92        assert r.response['protocol'] == 'HTTP/3'
93        assert r.json['server'] == env.domain1
94