annotate Tests/CheckDicomTls.py @ 574:ee71526e11ed

contributing
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 14 Aug 2023 10:19:50 +0200
parents 933fe1bbce4f
children 8aa101e126d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
375
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Orthanc - A Lightweight, RESTful DICOM Store
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Department, University Hospital of Liege, Belgium
511
933fe1bbce4f upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 449
diff changeset
6 # Copyright (C) 2017-2023 Osimis S.A., Belgium
933fe1bbce4f upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 449
diff changeset
7 # Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
375
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 #
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # This program is free software: you can redistribute it and/or
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # modify it under the terms of the GNU General Public License as
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # published by the Free Software Foundation, either version 3 of the
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 # License, or (at your option) any later version.
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 #
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # This program is distributed in the hope that it will be useful, but
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # General Public License for more details.
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 #
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # You should have received a copy of the GNU General Public License
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 import argparse
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 import os
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 import pprint
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 import re
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 import sys
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 import subprocess
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 import unittest
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 from Toolbox import *
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 ##
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 ## Parse the command-line arguments
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 ##
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 parser = argparse.ArgumentParser(description = 'Run the integration tests for DICOM TLS in Orthanc.')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 parser.add_argument('--server',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 default = 'localhost',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 help = 'Address of the Orthanc server to test')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 parser.add_argument('--aet',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 default = 'ORTHANC',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 help = 'AET of the Orthanc instance to test')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 parser.add_argument('--dicom',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 type = int,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 default = 4242,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 help = 'DICOM port of the Orthanc instance to test')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 parser.add_argument('--rest',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 type = int,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 default = 8042,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 help = 'Port to the REST API')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 parser.add_argument('--username',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 default = 'alice',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 help = 'Username to the REST API')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 parser.add_argument('--password',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 default = 'orthanctest',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 help = 'Password to the REST API')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 parser.add_argument('--force', help = 'Do not warn the user',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 action = 'store_true')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 parser.add_argument('--config', help = 'Create the configuration files for this test in the current folder',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 action = 'store_true')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 parser.add_argument('options', metavar = 'N', nargs = '*',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 help='Arguments to Python unittest')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 args = parser.parse_args()
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 ##
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 ## Configure the testing context
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 ##
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 if args.config:
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 def CreateCertificate(name):
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 subprocess.check_call([ 'openssl', 'req', '-x509', '-nodes', '-days', '365', '-newkey', 'rsa:2048',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 '-keyout', '%s.key' % name,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 '-out', '%s.crt' % name,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 '-subj', '/C=BE/CN=localhost' ])
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 print('Writing configuration to folder: %s' % args.config)
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 CreateCertificate('dicom-tls-a')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 CreateCertificate('dicom-tls-b')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 CreateCertificate('dicom-tls-c') # Not trusted by Orthanc
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 with open('dicom-tls-trusted.crt', 'w') as f:
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 for i in [ 'dicom-tls-a.crt', 'dicom-tls-b.crt' ]:
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 with open(i, 'r') as g:
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 f.write(g.read())
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 with open('dicom-tls.json', 'w') as f:
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 f.write(json.dumps({
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 'DicomTlsEnabled' : True,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 'DicomTlsCertificate' : 'dicom-tls-a.crt',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 'DicomTlsPrivateKey' : 'dicom-tls-a.key',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 'DicomTlsTrustedCertificates' : 'dicom-tls-trusted.crt',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 'ExecuteLuaEnabled' : True,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 'RemoteAccessAllowed' : True,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 'RegisteredUsers' : {
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 'alice' : 'orthanctest'
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 },
400
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
104 'DicomTlsRemoteCertificateRequired' : False, # New in Orthanc 1.9.3
375
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }))
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 exit(0)
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 if not args.force:
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 print("""
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 WARNING: This test will remove all the content of your
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 Orthanc instance running on %s!
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 Are you sure ["yes" to go on]?""" % args.server)
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 if sys.stdin.readline().strip() != 'yes':
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 print('Aborting...')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 exit(0)
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 ORTHANC = DefineOrthanc(server = args.server,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 username = args.username,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 password = args.password,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 restPort = args.rest,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 aet = args.aet,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 dicomPort = args.dicom)
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 ##
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 ## The tests
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 ##
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 FNULL = open(os.devnull, 'w') # Emulates "subprocess.DEVNULL" on Python 2.7
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 class Orthanc(unittest.TestCase):
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 def setUp(self):
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 if (sys.version_info >= (3, 0)):
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 # Remove annoying warnings about unclosed socket in Python 3
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 import warnings
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 warnings.simplefilter('ignore', ResourceWarning)
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 DropOrthanc(ORTHANC)
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 def test_incoming(self):
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 # No certificate
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 self.assertRaises(Exception, lambda: subprocess.check_call([
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 FindExecutable('echoscu'),
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 ORTHANC['Server'],
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 str(ORTHANC['DicomPort']),
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 '-aec', 'ORTHANC',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 ], stderr = FNULL))
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 subprocess.check_call([
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 FindExecutable('echoscu'),
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 ORTHANC['Server'],
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 str(ORTHANC['DicomPort']),
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 '-aec', 'ORTHANC',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 '+tls', 'dicom-tls-b.key', 'dicom-tls-b.crt',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 '+cf', 'dicom-tls-a.crt',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 ], stderr = FNULL)
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 self.assertRaises(Exception, lambda: subprocess.check_call([
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 FindExecutable('echoscu'),
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 ORTHANC['Server'],
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 str(ORTHANC['DicomPort']),
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 '-aec', 'ORTHANC',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 '+tls', 'dicom-tls-c.key', 'dicom-tls-c.crt', # Not trusted by Orthanc
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 '+cf', 'dicom-tls-a.crt',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 ], stderr = FNULL))
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 self.assertRaises(Exception, lambda: subprocess.check_call([
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 FindExecutable('echoscu'),
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 ORTHANC['Server'],
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 str(ORTHANC['DicomPort']),
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 '-aec', 'ORTHANC',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 '+tls', 'dicom-tls-b.key', 'dicom-tls-b.crt',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 '+cf', 'dicom-tls-b.crt', # Not the certificate of Orthanc
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 ], stderr = FNULL))
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 def test_outgoing_to_self(self):
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 u = UploadInstance(ORTHANC, 'DummyCT.dcm') ['ID']
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 # Error, as DICOM TLS is not enabled
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 DoPut(ORTHANC, '/modalities/self', {
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 'AET' : 'ORTHANC',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 'Host' : ORTHANC['Server'],
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 'Port' : ORTHANC['DicomPort'],
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 })
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 self.assertRaises(Exception, lambda: DoPost(ORTHANC, '/modalities/self/store', u))
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 # Retry using DICOM TLS
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 DoPut(ORTHANC, '/modalities/self', {
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 'AET' : 'ORTHANC',
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 'Host' : ORTHANC['Server'],
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 'Port' : ORTHANC['DicomPort'],
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 'UseDicomTls' : True,
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 })
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 self.assertEqual(1, DoPost(ORTHANC, '/modalities/self/store', u) ['InstancesCount'])
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
400
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
207
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
208 def test_anonymous(self):
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
209 # Fails on Orthanc <= 1.9.2
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
210 # https://book.orthanc-server.com/faq/dicom-tls.html#secure-tls-connections-without-certificate
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
211 subprocess.check_call([
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
212 FindExecutable('echoscu'),
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
213 ORTHANC['Server'],
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
214 str(ORTHANC['DicomPort']),
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
215 '-aec', 'ORTHANC',
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
216 '--anonymous-tls',
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
217 '+cf', 'dicom-tls-a.crt',
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
218 ], stderr = FNULL)
f454fe86061b dicom tls: test_anonymous
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
219
375
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 try:
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 print('\nStarting the tests...')
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 unittest.main(argv = [ sys.argv[0] ] + args.options)
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 finally:
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 print('\nDone')