changeset 532:f96c023ce523

dicom-web X-Forwarded headers
author Alain Mazy <am@osimis.io>
date Mon, 24 Apr 2023 10:43:27 +0200
parents 8a920ab91cf4
children c5291d97ed54
files Plugins/DicomWeb/Run.py README Tests/Toolbox.py
diffstat 3 files changed, 48 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/DicomWeb/Run.py	Fri Apr 21 10:35:41 2023 +0200
+++ b/Plugins/DicomWeb/Run.py	Mon Apr 24 10:43:27 2023 +0200
@@ -1648,6 +1648,32 @@
         self.assertLessEqual(abs(GetLinear(0x30 * rs + ri, 127, 256) - im.getpixel((1, 1))), 1)
 
 
+    def test_forwarded_headers(self):
+        study = UploadInstance(ORTHANC, 'ColorTestImageJ.dcm')['ParentStudy']
+        studyId = DoGet(ORTHANC, '/studies/%s' % study)['MainDicomTags']['StudyInstanceUID']
+
+        m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyId)
+        self.assertIn("http://localhost:8042/dicom-web", m[0][u'7FE00010']['BulkDataURI'])
+
+        m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyId, headers= {
+            'host': 'my-domain'
+        })
+        self.assertIn("http://my-domain/dicom-web", m[0][u'7FE00010']['BulkDataURI'])
+
+        m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyId, headers= {
+            'forwarded': 'host=my-domain;proto=https'
+        })
+        self.assertIn("https://my-domain/dicom-web", m[0][u'7FE00010']['BulkDataURI'])
+
+        if IsPluginVersionAbove(ORTHANC, "dicom-web", 1, 13, 1):
+            m = DoGet(ORTHANC, '/dicom-web/studies/%s/metadata' % studyId, headers= {
+                'X-Forwarded-Host': 'my-domain',
+                'X-Forwarded-Proto': 'https'
+            })
+            self.assertIn("https://my-domain/dicom-web", m[0][u'7FE00010']['BulkDataURI'])
+
+
+
 try:
     print('\nStarting the tests...')
     unittest.main(argv = [ sys.argv[0] ] + args.options)
--- a/README	Fri Apr 21 10:35:41 2023 +0200
+++ b/README	Mon Apr 24 10:43:27 2023 +0200
@@ -127,6 +127,7 @@
 
 To run a plugin test (no need for Orthanc 0.8.6)
 # python2 ./Plugins/DicomWeb/Run.py
+# python2 ./Plugins/DicomWeb/Run.py Orthanc.test_forwarded_headers
 
 Use the flag "--help" to get the full list of arguments. These
 arguments will notably allow you to specify the network parameters
--- a/Tests/Toolbox.py	Fri Apr 21 10:35:41 2023 +0200
+++ b/Tests/Toolbox.py	Mon Apr 24 10:43:27 2023 +0200
@@ -354,6 +354,27 @@
                 (a == major and b > minor) or
                 (a == major and b == minor and c >= revision))
 
+def IsPluginVersionAbove(orthanc, plugin, major, minor, revision):
+    v = DoGet(orthanc, '/plugins/%s' % plugin)['Version']
+
+    if v == 'mainline':
+        return True
+    else:
+        tmp = v.split('.')
+        if len(tmp) >= 3:
+            a = int(tmp[0])
+            b = int(tmp[1])
+            c = int(tmp[2])
+            return (a > major or
+                    (a == major and b > minor) or
+                    (a == major and b == minor and c >= revision))
+        elif len(tmp) >= 2:
+            a = int(tmp[0])
+            b = int(tmp[1])
+            return (a > major or
+                    (a == major and b > minor))
+        else:
+            return False
 
 class ExternalCommandThread:
     @staticmethod