# HG changeset patch # User Alain Mazy # Date 1682325807 -7200 # Node ID f96c023ce5237068d70939ea63c3d05244069b8e # Parent 8a920ab91cf492d28d64075283ad51adba175a87 dicom-web X-Forwarded headers diff -r 8a920ab91cf4 -r f96c023ce523 Plugins/DicomWeb/Run.py --- 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) diff -r 8a920ab91cf4 -r f96c023ce523 README --- 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 diff -r 8a920ab91cf4 -r f96c023ce523 Tests/Toolbox.py --- 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