changeset 975:901f681fd4c2

updated tests wrt AllowedHosts
author Alain Mazy <am@orthanc.team>
date Tue, 22 Sep 2026 11:17:50 +0200
parents 284b77a46aa3
children 0c13013c7930
files GenerateConfigurationForTests.py NewTests/Concurrency/docker-compose-transfers-concurrency.yml NewTests/PostgresUpgrades/orthanc-for-integ-tests.json Plugins/DicomWeb/Run.py
diffstat 4 files changed, 34 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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'] = {
--- 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: |
         {
--- 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": {
--- 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):