Fix web-download bad URL test for sync URI validation

Glance can now return HTTP 400 when the web-download URI fails checks
up front. The test used to expect 202 and a later failed import.
Accept 400 when the error mentions the bad host or filtering, and
keep the old wait-for-failed-import path when Glance still returns 202.

Related-Bug: #2138602
Change-Id: I1ec58edd6029fbc8e667e008f5017c71d70cc09f
Signed-off-by: Abhishek Kekane <akekane@redhat.com>
This commit is contained in:
Abhishek Kekane
2026-03-19 17:06:30 +00:00
parent 904ad69fa2
commit e443d6addd

View File

@@ -218,12 +218,27 @@ class ImportImagesNegativeTest(base.BaseV2ImageTest):
self.assertEqual(image['id'], body['id'])
self.assertEqual('queued', body['status'])
stores = self.get_available_stores()
# import image from web to backend
image_uri = 'http://does-not.exist/no/possible/way'
self.client.image_import(image['id'], method='web-download',
import_params={'uri': image_uri},
stores=[stores[0]['id']])
try:
self.client.image_import(
image['id'], method='web-download',
import_params={'uri': image_uri},
stores=[stores[0]['id']])
except lib_exc.BadRequest as e:
# Glance may reject the URI during synchronous validation
# (HTTP 400), e.g. import filtering / SSRF protections, instead of
# accepting the import and failing asynchronously.
err = str(e)
self.assertTrue(
'does-not.exist' in err or
'does not pass filtering' in err.lower(),
'Unexpected 400 body for bad web-download URI: %s' % e)
return
# Only reached when Glance accepts the import (202) and defers failure
# to the async web-download task (e.g. older servers without sync URI
# filtering). Stricter Glance returns 400 above and never hits this
# loop.
start_time = int(time.time())
while int(time.time()) - start_time < self.client.build_timeout:
body = self.client.show_image(image['id'])