comparison Tests/CheckHttpServerSecurity.py @ 370:7eb5b86508b1

added Tests/CheckHttpServerSecurity.py and Tests/CheckIngestTranscoding.py
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 21 Jan 2021 11:38:47 +0100
parents
children e769bcf2b94f
comparison
equal deleted inserted replaced
369:24d93b42873a 370:7eb5b86508b1
1 #!/usr/bin/env python
2
3 # Orthanc - A Lightweight, RESTful DICOM Store
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
5 # Department, University Hospital of Liege, Belgium
6 # Copyright (C) 2017-2021 Osimis S.A., Belgium
7 #
8 # This program is free software: you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21
22 import json
23 import os
24 import subprocess
25 import sys
26 import time
27 import Toolbox
28
29 if len(sys.argv) != 2:
30 print('Must provide a path to Orthanc binaries')
31 exit(-1)
32
33
34 TMP = '/tmp/OrthancTest'
35 CONFIG = os.path.join(TMP, 'Configuration.json')
36
37 if os.path.exists(TMP):
38 print('Temporary path already exists: %s' % TMP)
39 exit(-1)
40
41 os.mkdir(TMP)
42
43
44 ORTHANC = Toolbox.DefineOrthanc(username = 'orthanc',
45 password = 'orthanc')
46
47
48 def IsHttpServerSecure(config):
49 with open(CONFIG, 'w') as f:
50 f.write(json.dumps(config))
51
52 process = subprocess.Popen(
53 [ sys.argv[1], CONFIG ],
54 cwd = TMP,
55 #stdout=subprocess.PIPE,
56 stderr=subprocess.PIPE,
57 #shell=True
58 )
59
60 time.sleep(1)
61
62 while True:
63 try:
64 system = Toolbox.DoGet(ORTHANC, '/system')
65 break
66 except:
67 time.sleep(0.1)
68
69 process.terminate()
70 process.wait()
71
72 return system['IsHttpServerSecure']
73
74
75 def Assert(b):
76 if not b:
77 raise Exception('Bad result')
78
79
80 print('==== TEST 1 ====')
81 Assert(IsHttpServerSecure({
82 'RemoteAccessAllowed': False,
83 'RegisteredUsers' : { }
84 }))
85
86 print('==== TEST 2 ====')
87 Assert(IsHttpServerSecure({
88 'RemoteAccessAllowed': False,
89 'AuthenticationEnabled': False,
90 'RegisteredUsers' : { }
91 }))
92
93 print('==== TEST 3 ====')
94 Assert(IsHttpServerSecure({
95 'RemoteAccessAllowed': False,
96 'AuthenticationEnabled': True,
97 'RegisteredUsers' : { 'orthanc' : 'orthanc' }
98 }))
99
100 print('==== TEST 4 ====')
101 Assert(not IsHttpServerSecure({
102 'RemoteAccessAllowed': True
103 }))
104
105 print('==== TEST 5 (server application scenario) ====')
106 Assert(not IsHttpServerSecure({
107 'RemoteAccessAllowed': True,
108 'AuthenticationEnabled': False,
109 }))
110
111 print('==== TEST 6 ====')
112 Assert(IsHttpServerSecure({
113 'RemoteAccessAllowed': True,
114 'AuthenticationEnabled': True,
115 'RegisteredUsers' : { 'orthanc' : 'orthanc' }
116 }))
117
118 print('==== TEST 7 (Docker scenario) ====')
119 Assert(not IsHttpServerSecure({
120 'RemoteAccessAllowed': True,
121 'AuthenticationEnabled': True
122 }))
123
124 print('Success!')