comparison NewTests/Authorization/test_authorization.py @ 621:9f867dc595e2

fix concurrency tests
author Alain Mazy <am@osimis.io>
date Tue, 06 Feb 2024 16:20:40 +0100
parents c28bd957cb93
children 78314ab6fc67
comparison
equal deleted inserted replaced
619:79812e0df162 621:9f867dc595e2
119 cls.no_label_study_dicom_id = o.studies.get_tags(cls.no_label_study_id)["StudyInstanceUID"] 119 cls.no_label_study_dicom_id = o.studies.get_tags(cls.no_label_study_id)["StudyInstanceUID"]
120 cls.no_label_series_dicom_id = o.series.get_tags(cls.no_label_series_id)["SeriesInstanceUID"] 120 cls.no_label_series_dicom_id = o.series.get_tags(cls.no_label_series_id)["SeriesInstanceUID"]
121 cls.no_label_instance_dicom_id = o.instances.get_tags(cls.no_label_instance_id)["SOPInstanceUID"] 121 cls.no_label_instance_dicom_id = o.instances.get_tags(cls.no_label_instance_id)["SOPInstanceUID"]
122 122
123 123
124 def is_orthanc_version_at_least_1_12_2(self, orthanc_client: OrthancApiClient):
125 return orthanc_client.get_system()["ApiVersion"] >= 22
126
127 def assert_is_forbidden(self, api_call): 124 def assert_is_forbidden(self, api_call):
128 with self.assertRaises(orthanc_exceptions.HttpError) as ctx: 125 with self.assertRaises(orthanc_exceptions.HttpError) as ctx:
129 api_call() 126 api_call()
130 self.assertEqual(403, ctx.exception.http_status_code) 127 self.assertEqual(403, ctx.exception.http_status_code)
131 128
276 o.get_system() 273 o.get_system()
277 o.lookup("1.2.3") # this route is still explicitely authorized because it is used by Stone 274 o.lookup("1.2.3") # this route is still explicitely authorized because it is used by Stone
278 275
279 # other studies are forbidden 276 # other studies are forbidden
280 self.assert_is_forbidden(lambda: o.studies.get_series_ids(self.label_b_study_id)) 277 self.assert_is_forbidden(lambda: o.studies.get_series_ids(self.label_b_study_id))
281 if self.is_orthanc_version_at_least_1_12_2(o): 278 if self.o.is_orthanc_version_at_least(1, 12, 2):
282 self.assert_is_forbidden(lambda: o.get_binary(f"tools/create-archive?resources={self.label_b_study_id}")) 279 self.assert_is_forbidden(lambda: o.get_binary(f"tools/create-archive?resources={self.label_b_study_id}"))
283 self.assert_is_forbidden(lambda: o.get_binary(f"tools/create-archive?resources={self.label_b_series_id}")) 280 self.assert_is_forbidden(lambda: o.get_binary(f"tools/create-archive?resources={self.label_b_series_id}"))
284 # if one of the studies is forbidden, the resource is forbidden 281 # if one of the studies is forbidden, the resource is forbidden
285 self.assert_is_forbidden(lambda: o.get_binary(f"tools/create-archive?resources={self.label_b_study_id},{self.label_a_study_id}")) 282 self.assert_is_forbidden(lambda: o.get_binary(f"tools/create-archive?resources={self.label_b_study_id},{self.label_a_study_id}"))
286 283
298 o.get_json(f"dicom-web/studies?StudyInstanceUID={self.label_a_study_dicom_id}") 295 o.get_json(f"dicom-web/studies?StudyInstanceUID={self.label_a_study_dicom_id}")
299 o.get_json(f"dicom-web/studies?0020000D={self.label_a_study_dicom_id}") 296 o.get_json(f"dicom-web/studies?0020000D={self.label_a_study_dicom_id}")
300 o.get_json(f"dicom-web/series?0020000D={self.label_a_study_dicom_id}") 297 o.get_json(f"dicom-web/series?0020000D={self.label_a_study_dicom_id}")
301 o.get_json(f"dicom-web/instances?0020000D={self.label_a_study_dicom_id}") 298 o.get_json(f"dicom-web/instances?0020000D={self.label_a_study_dicom_id}")
302 299
303 if self.is_orthanc_version_at_least_1_12_2(o): 300 if self.o.is_orthanc_version_at_least(1, 12, 2):
304 o.get_binary(f"tools/create-archive?resources={self.label_a_study_id}") 301 o.get_binary(f"tools/create-archive?resources={self.label_a_study_id}")
305 o.get_binary(f"tools/create-archive?resources={self.label_a_series_id}") 302 o.get_binary(f"tools/create-archive?resources={self.label_a_series_id}")
306 303
307 304
308 # now test with token-both 305 # now test with token-both