Projet

Général

Profil

0001-misc-accept-only-http-and-https-as-URL-scheme-20523.patch

Thomas Noël, 08 décembre 2017 16:19

Télécharger (3,19 ko)

Voir les différences:

Subject: [PATCH] misc: accept only http and https as URL scheme (#20523)

 tests/test_datasource.py | 33 +++++++++++++++++++++++++++++++++
 wcs/qommon/misc.py       |  4 +++-
 2 files changed, 36 insertions(+), 1 deletion(-)
tests/test_datasource.py
24 24
    global pub, req
25 25

  
26 26
    pub = create_temporary_pub()
27
    pub.cfg['debug'] = {'logger': True}
28
    pub.write_cfg()
29
    pub.set_config()
27 30

  
28 31
    req = HTTPRequest(None, {'SERVER_NAME': 'example.net', 'SCRIPT_NAME': ''})
29 32
    pub._set_request(req)
......
228 231
    assert data_sources.get_items(datasource) == []
229 232
    assert data_sources.get_structured_items(datasource) == []
230 233

  
234
def test_json_datasource_bad_url(http_requests, caplog):
235
    datasource = {'type': 'json', 'value': 'http://remote.example.net/404'}
236
    assert data_sources.get_items(datasource) == []
237
    assert 'Error loading JSON data source' in caplog.records[-1].message
238
    assert 'status: 404' in caplog.records[-1].message
239

  
240
    datasource = {'type': 'json', 'value': 'http://remote.example.net/xml'}
241
    assert data_sources.get_items(datasource) == []
242
    assert 'Error reading JSON data source output' in caplog.records[-1].message
243
    assert 'No JSON object could be decoded' in caplog.records[-1].message
244

  
245
    datasource = {'type': 'json', 'value': 'http://remote.example.net/connection-error'}
246
    assert data_sources.get_items(datasource) == []
247
    assert 'Error loading JSON data source' in caplog.records[-1].message
248
    assert 'error' in caplog.records[-1].message
249

  
250
def test_json_datasource_bad_url_scheme(caplog):
251
    datasource = {'type': 'json', 'value': ''}
252
    assert data_sources.get_items(datasource) == []
253
    assert caplog.records[-1].message == 'Empty URL in JSON data source'
254

  
255
    datasource = {'type': 'json', 'value': 'foo://bar'}
256
    assert data_sources.get_items(datasource) == []
257
    assert 'Error loading JSON data source' in caplog.records[-1].message
258
    assert 'invalid scheme in URL' in caplog.records[-1].message
259

  
260
    datasource = {'type': 'json', 'value': '/bla/blo'}
261
    assert data_sources.get_items(datasource) == []
262
    assert 'Error loading JSON data source' in caplog.records[-1].message
263
    assert 'invalid scheme in URL' in caplog.records[-1].message
231 264

  
232 265
def test_item_field_named_python_datasource():
233 266
    NamedDataSource.wipe()
wcs/qommon/misc.py
277 277

  
278 278
    if url.startswith('http://'):
279 279
        hostname, query = urllib.splithost(url[5:])
280
    else:
280
    elif url.startswith('https://'):
281 281
        hostname, query = urllib.splithost(url[6:])
282
    else:
283
        raise ConnectionError('invalid scheme in URL %s' % url)
282 284

  
283 285
    auth = None
284 286
    if '@' in hostname:
285
-