Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
94 lines
2.3 KiB
Python
94 lines
2.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from qwenpaw.utils.http import (
|
|
is_loopback_host,
|
|
is_loopback_url,
|
|
probe_host_for_bind_host,
|
|
trust_env_for_url,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"host",
|
|
[
|
|
"localhost",
|
|
"localhost.",
|
|
"127.0.0.1",
|
|
"127.1.2.3",
|
|
"::1",
|
|
"[::1]",
|
|
],
|
|
)
|
|
def test_is_loopback_host_recognizes_loopback_targets(host: str) -> None:
|
|
assert is_loopback_host(host) is True
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"host",
|
|
[
|
|
"",
|
|
"0.0.0.0",
|
|
"::",
|
|
"192.168.1.10",
|
|
"10.0.0.1",
|
|
"example.com",
|
|
],
|
|
)
|
|
def test_is_loopback_host_keeps_non_loopback_targets(host: str) -> None:
|
|
assert is_loopback_host(host) is False
|
|
|
|
|
|
# Local API calls should bypass env proxies for localhost/loopback targets.
|
|
@pytest.mark.parametrize(
|
|
"url",
|
|
[
|
|
"http://localhost:8088/api",
|
|
"http://localhost.:8088/api",
|
|
"http://127.0.0.1:8088/api",
|
|
"http://127.1.2.3:8088/api",
|
|
"http://[::1]:8088/api",
|
|
],
|
|
)
|
|
def test_is_loopback_url_recognizes_loopback_targets(url: str) -> None:
|
|
assert is_loopback_url(url) is True
|
|
assert trust_env_for_url(url) is False
|
|
|
|
|
|
# Non-loopback URLs keep httpx's normal env proxy behavior.
|
|
@pytest.mark.parametrize(
|
|
"url",
|
|
[
|
|
"http://192.168.1.10:8088/api",
|
|
"https://example.com/api",
|
|
"http://10.0.0.1:8088/api",
|
|
],
|
|
)
|
|
def test_is_loopback_url_keeps_non_loopback_targets(url: str) -> None:
|
|
assert is_loopback_url(url) is False
|
|
assert trust_env_for_url(url) is True
|
|
|
|
|
|
# A wildcard bind address must be probed through the loopback address of
|
|
# its own family: Winsock rejects a wildcard connect target with
|
|
# WSAEADDRNOTAVAIL, and a socket bound to :: is unreachable over IPv4.
|
|
@pytest.mark.parametrize(
|
|
"bind_host, expected",
|
|
[
|
|
("0.0.0.0", "127.0.0.1"),
|
|
("::", "::1"),
|
|
("[::]", "::1"),
|
|
(" :: ", "::1"),
|
|
("", "127.0.0.1"),
|
|
(" ", "127.0.0.1"),
|
|
("127.0.0.1", "127.0.0.1"),
|
|
("[::1]", "::1"),
|
|
("192.168.1.10", "192.168.1.10"),
|
|
("localhost", "localhost"),
|
|
],
|
|
)
|
|
def test_probe_host_for_bind_host(bind_host: str, expected: str) -> None:
|
|
assert probe_host_for_bind_host(bind_host) == expected
|