8
8
configuration to access an HTTP Basic protected endpoint.
9
9
10
10
11
- From build dir, run: ctest -R PyQgsAuthManagerEndpointTest -V
11
+ From build dir, run: ctest -R PyQgsAuthManagerPasswordOWSTest -V
12
12
13
13
.. note:: This program is free software; you can redistribute it and/or modify
14
14
it under the terms of the GNU General Public License as published by
30
30
# This will get replaced with a git SHA1 when you do a git archive
31
31
__revision__ = '$Format:%H$'
32
32
33
- from urllib .parse import quote
34
33
from shutil import rmtree
35
34
36
35
from utilities import unitTestDataPath , waitServer
45
44
unittest ,
46
45
)
47
46
48
-
49
47
try :
50
48
QGIS_SERVER_ENDPOINT_PORT = os .environ ['QGIS_SERVER_ENDPOINT_PORT' ]
51
49
except :
52
- QGIS_SERVER_ENDPOINT_PORT = '0' # Auto
50
+ QGIS_SERVER_ENDPOINT_PORT = '0' # Auto
53
51
54
52
55
53
QGIS_AUTH_DB_DIR_PATH = tempfile .mkdtemp ()
@@ -74,7 +72,7 @@ def setUpClass(cls):
74
72
except KeyError :
75
73
pass
76
74
cls .testdata_path = unitTestDataPath ('qgis_server' ) + '/'
77
- cls .project_path = quote ( cls .testdata_path + "test_project.qgs" )
75
+ cls .project_path = cls .testdata_path + "test_project.qgs"
78
76
# Enable auth
79
77
#os.environ['QGIS_AUTH_PASSWORD_FILE'] = QGIS_AUTH_PASSWORD_FILE
80
78
authm = QgsAuthManager .instance ()
@@ -86,26 +84,30 @@ def setUpClass(cls):
86
84
cls .auth_config .setConfig ('username' , cls .username )
87
85
cls .auth_config .setConfig ('password' , cls .password )
88
86
assert (authm .storeAuthenticationConfig (cls .auth_config )[0 ])
87
+ cls .hostname = '127.0.0.1'
88
+ cls .protocol = 'http'
89
89
90
90
os .environ ['QGIS_SERVER_HTTP_BASIC_AUTH' ] = '1'
91
91
os .environ ['QGIS_SERVER_USERNAME' ] = cls .username
92
92
os .environ ['QGIS_SERVER_PASSWORD' ] = cls .password
93
93
os .environ ['QGIS_SERVER_PORT' ] = str (cls .port )
94
+ os .environ ['QGIS_SERVER_HOST' ] = cls .hostname
95
+
94
96
server_path = os .path .dirname (os .path .realpath (__file__ )) + \
95
97
'/qgis_wrapped_server.py'
96
98
cls .server = subprocess .Popen ([sys .executable , server_path ],
97
99
env = os .environ , stdout = subprocess .PIPE )
100
+
98
101
line = cls .server .stdout .readline ()
99
102
cls .port = int (re .findall (b':(\d+)' , line )[0 ])
100
103
assert cls .port != 0
101
104
# Wait for the server process to start
102
- assert waitServer ('http ://127.0.0.1 :%s' % cls .port ), "Server is not responding!"
105
+ assert waitServer ('%s ://%s :%s' % ( cls .protocol , cls . hostname , cls . port )) , "Server is not responding! %s://%s:%s" % ( cls . protocol , cls . hostname , cls . port )
103
106
104
107
@classmethod
105
108
def tearDownClass (cls ):
106
109
"""Run after all tests"""
107
110
cls .server .terminate ()
108
- cls .server .wait ()
109
111
rmtree (QGIS_AUTH_DB_DIR_PATH )
110
112
del cls .server
111
113
@@ -127,7 +129,7 @@ def _getWFSLayer(cls, type_name, layer_name=None, authcfg=None):
127
129
parms = {
128
130
'srsname' : 'EPSG:4326' ,
129
131
'typename' : type_name ,
130
- 'url' : 'http ://127.0.0.1 :%s/?map=%s' % (cls .port , cls .project_path ),
132
+ 'url' : '%s ://%s :%s/?map=%s' % (cls . protocol , cls . hostname , cls .port , cls .project_path ),
131
133
'version' : 'auto' ,
132
134
'table' : '' ,
133
135
}
@@ -146,12 +148,12 @@ def _getWMSLayer(cls, layers, layer_name=None, authcfg=None):
146
148
layer_name = 'wms_' + layers .replace (',' , '' )
147
149
parms = {
148
150
'crs' : 'EPSG:4326' ,
149
- 'url' : 'http://127.0.0.1:%s/?map=%s' % (cls .port , cls .project_path ),
150
- 'format' : 'image/png' ,
151
+ 'url' : '%s://%s:%s/?map=%s' % (cls .protocol , cls .hostname , cls .port , cls .project_path ),
151
152
# This is needed because of a really weird implementation in QGIS Server, that
152
153
# replaces _ in the the real layer name with spaces
153
- 'layers' : urllib .parse .quote (layers ) .replace ('_' , ' ' ),
154
+ 'layers' : urllib .parse .quote (layers .replace ('_' , ' ' ) ),
154
155
'styles' : '' ,
156
+ 'version' : 'auto' ,
155
157
#'sql': '',
156
158
}
157
159
if authcfg is not None :
@@ -173,7 +175,7 @@ def testInvalidAuthAccess(self):
173
175
"""
174
176
Access the HTTP Basic protected layer with no credentials
175
177
"""
176
- wfs_layer = self ._getWFSLayer ('testlayer_èé ' )
178
+ wfs_layer = self ._getWFSLayer ('testlayer èé ' )
177
179
self .assertFalse (wfs_layer .isValid ())
178
180
wms_layer = self ._getWMSLayer ('testlayer_èé' )
179
181
self .assertFalse (wms_layer .isValid ())
0 commit comments