From: Anders Heimer <anders.heimer@est.tech>
To: bitbake-devel@lists.openembedded.org
Cc: Anders Heimer <anders.heimer@est.tech>
Subject: [PATCH 2/2] tests/fetch: cover checkstatus redirect auth handling
Date: Wed, 10 Jun 2026 09:40:13 +0200 [thread overview]
Message-ID: <20260610074013.558709-3-anders.heimer@est.tech> (raw)
In-Reply-To: <20260610074013.558709-1-anders.heimer@est.tech>
Add local HTTP server tests for Wget.checkstatus() redirects. They check
that Authorization is kept for same-origin redirects and dropped when the
target has a different origin.
Signed-off-by: Anders Heimer <anders.heimer@est.tech>
---
lib/bb/tests/fetch.py | 62 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
index 95cf6c414..d021ad786 100644
--- a/lib/bb/tests/fetch.py
+++ b/lib/bb/tests/fetch.py
@@ -7,6 +7,7 @@
#
import contextlib
+import http.server
import shutil
import unittest
import unittest.mock
@@ -18,6 +19,7 @@ import os
import signal
import subprocess
import tarfile
+import threading
from bb.fetch2 import URI
import bb
import bb.utils
@@ -1716,6 +1718,41 @@ class FetchCheckStatusTest(FetcherTest):
"ftp://sourceware.org/pub/libffi/libffi-1.20.tar.gz",
]
+ def _start_checkstatus_server(self):
+ class CheckStatusHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
+ def do_HEAD(self):
+ self.server.requests.append((self.path, dict(self.headers)))
+ if self.path == "/a" and self.server.redirect_url:
+ self.send_response(302)
+ self.send_header("Location", self.server.redirect_url)
+ self.end_headers()
+ return
+ self.send_response(200)
+ self.end_headers()
+
+ def log_message(self, format_str, *args):
+ pass
+
+ server = http.server.HTTPServer(("127.0.0.1", 0), CheckStatusHTTPRequestHandler)
+ server.redirect_url = None
+ server.requests = []
+ thread = threading.Thread(target=server.serve_forever, kwargs={"poll_interval": 0.05})
+ thread.daemon = True
+ thread.start()
+
+ def stop_server():
+ server.shutdown()
+ thread.join()
+ server.server_close()
+
+ self.addCleanup(stop_server)
+ return server
+
+ def _checkstatus(self, url):
+ fetch = bb.fetch2.Fetch([url], self.d)
+ ud = fetch.ud[url]
+ return ud.method.checkstatus(fetch, ud, self.d)
+
@skipIfNoNetwork()
def test_wget_checkstatus(self):
fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d)
@@ -1743,6 +1780,31 @@ class FetchCheckStatusTest(FetcherTest):
connection_cache.close_connections()
+ def test_wget_checkstatus_same_origin_redirect_keeps_auth(self):
+ server = self._start_checkstatus_server()
+ server.redirect_url = "http://127.0.0.1:%s/b" % server.server_port
+
+ url = "http://127.0.0.1:%s/a;user=user;pswd=pass" % server.server_port
+ self.assertTrue(self._checkstatus(url))
+
+ self.assertEqual(len(server.requests), 2)
+ redirected_headers = {k.lower(): v for k, v in server.requests[1][1].items()}
+ self.assertIn("authorization", redirected_headers)
+
+ def test_wget_checkstatus_different_origin_redirect_drops_auth(self):
+ origin = self._start_checkstatus_server()
+ target = self._start_checkstatus_server()
+ # Same host but different port is a different origin.
+ origin.redirect_url = "http://127.0.0.1:%s/b" % target.server_port
+
+ url = "http://127.0.0.1:%s/a;user=user;pswd=pass" % origin.server_port
+ self.assertTrue(self._checkstatus(url))
+
+ self.assertEqual(len(origin.requests), 1)
+ self.assertEqual(len(target.requests), 1)
+ redirected_headers = {k.lower(): v for k, v in target.requests[0][1].items()}
+ self.assertNotIn("authorization", redirected_headers)
+
class GitMakeShallowTest(FetcherTest):
def setUp(self):
next prev parent reply other threads:[~2026-06-10 7:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-10 7:40 [PATCH 0/2] fetch2/wget: limit auth headers on checkstatus redirects Anders Heimer
2026-06-10 7:40 ` [PATCH 1/2] fetch2/wget: limit auth " Anders Heimer
2026-06-10 7:40 ` Anders Heimer [this message]
2026-06-10 7:54 ` [bitbake-devel] [PATCH 0/2] fetch2/wget: limit auth headers " Alexander Kanavin
2026-06-10 14:11 ` Richard Purdie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260610074013.558709-3-anders.heimer@est.tech \
--to=anders.heimer@est.tech \
--cc=bitbake-devel@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox