# HG changeset patch # User Alain Mazy # Date 1790068670 -7200 # Node ID 901f681fd4c28ff0bcc54f3e127fb33a7f984086 # Parent 284b77a46aa312ff58334015646562ab4ad6dc5e updated tests wrt AllowedHosts diff -r 284b77a46aa3 -r 901f681fd4c2 GenerateConfigurationForTests.py --- a/GenerateConfigurationForTests.py Tue Sep 22 10:52:35 2026 +0200 +++ b/GenerateConfigurationForTests.py Tue Sep 22 11:17:50 2026 +0200 @@ -210,7 +210,8 @@ 'alice', 'orthanctest' ] - } + }, + 'AllowedHosts': ['my-allowed-domain.com', 'my2.allowed.*', 'my3.*.com', '*.white-listed.com'] } config['Worklists'] = { diff -r 284b77a46aa3 -r 901f681fd4c2 NewTests/Concurrency/docker-compose-transfers-concurrency.yml --- a/NewTests/Concurrency/docker-compose-transfers-concurrency.yml Tue Sep 22 10:52:35 2026 +0200 +++ b/NewTests/Concurrency/docker-compose-transfers-concurrency.yml Tue Sep 22 11:17:50 2026 +0200 @@ -27,7 +27,8 @@ "Servers": { "a": [ "http://orthanc-pg-a:8042/dicom-web/"], "b": [ "http://orthanc-pg-b:8042/dicom-web/"] - } + }, + "AllowedHosts": ["orthanc-pg-a"], } ORTHANC__POSTGRESQL: | { @@ -74,7 +75,8 @@ "Servers": { "a": [ "http://orthanc-pg-a:8042/dicom-web/"], "b": [ "http://orthanc-pg-b:8042/dicom-web/"] - } + }, + "AllowedHosts": ["orthanc-pg-b"], } ORTHANC__POSTGRESQL: | { diff -r 284b77a46aa3 -r 901f681fd4c2 NewTests/PostgresUpgrades/orthanc-for-integ-tests.json --- a/NewTests/PostgresUpgrades/orthanc-for-integ-tests.json Tue Sep 22 10:52:35 2026 +0200 +++ b/NewTests/PostgresUpgrades/orthanc-for-integ-tests.json Tue Sep 22 11:17:50 2026 +0200 @@ -58,7 +58,8 @@ "http://localhost:8042/dicom-web/", "alice", "orthanctest" - ] + ], + "AllowedHosts": ["my-allowed-domain.com", "my2.allowed.*", "my3.*.com", "*.white-listed.com"] } }, "Dictionary": { diff -r 284b77a46aa3 -r 901f681fd4c2 Plugins/DicomWeb/Run.py --- a/Plugins/DicomWeb/Run.py Tue Sep 22 10:52:35 2026 +0200 +++ b/Plugins/DicomWeb/Run.py Tue Sep 22 11:17:50 2026 +0200 @@ -1794,6 +1794,7 @@ def test_forwarded_headers(self): + # config reminder: 'AllowedHosts': ['my-allowed-domain.com', 'my2.allowed.*', 'my3.*.com', '*.white-listed.com'] study = UploadInstance(ORTHANC, 'ColorTestImageJ.dcm')['ParentStudy'] studyId = DoGet(ORTHANC, '/studies/%s' % study)['MainDicomTags']['StudyInstanceUID'] @@ -1801,21 +1802,40 @@ self.assertIn(ORTHANC['Url'], m[0][u'7FE00010']['BulkDataURI']) m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyId, headers= { - 'host': 'my-domain' + 'host': 'my-allowed-domain.com' }) - self.assertIn("http://my-domain/dicom-web", m[0][u'7FE00010']['BulkDataURI']) + self.assertIn("http://my-allowed-domain.com/dicom-web", m[0][u'7FE00010']['BulkDataURI']) m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyId, headers= { - 'forwarded': 'host=my-domain;proto=https' + 'forwarded': 'host=my2.allowed.toto;proto=https' }) - self.assertIn("https://my-domain/dicom-web", m[0][u'7FE00010']['BulkDataURI']) + self.assertIn("https://my2.allowed.toto/dicom-web", m[0][u'7FE00010']['BulkDataURI']) + + m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyId, headers= { + 'forwarded': 'host=localhost.white-listed.com;proto=https' + }) + self.assertIn("https://localhost.white-listed.com/dicom-web", m[0][u'7FE00010']['BulkDataURI']) if IsPluginVersionAtLeast(ORTHANC, "dicom-web", 1, 13, 1): m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyId, headers= { - 'X-Forwarded-Host': 'my-domain', + 'X-Forwarded-Host': 'my3.toto.com', 'X-Forwarded-Proto': 'https' }) - self.assertIn("https://my-domain/dicom-web", m[0][u'7FE00010']['BulkDataURI']) + self.assertIn("https://my3.toto.com/dicom-web", m[0][u'7FE00010']['BulkDataURI']) + + if IsPluginVersionAtLeast(ORTHANC, "dicom-web", 1, 25, 0): + self.assertRaises(Exception, lambda: DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyId, headers= { + 'host': 'my-forbidden-domain.com' + })) + + self.assertRaises(Exception, lambda: DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyId, headers= { + 'host': 'localhost.my-allowed-domain.com' + })) + + self.assertRaises(Exception, lambda: DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyId, headers= { + 'host': '127.0.0.1.my-allowed-domain.com' + })) + def test_full_mode_cache(self):