solis: force _links to use service_url scheme (#38039)

This commit is contained in:
Thomas NOËL 2019-11-28 11:14:15 +01:00
parent 3a56b4c709
commit 2bc9d1d89a
2 changed files with 11 additions and 6 deletions

View File

@ -473,10 +473,15 @@ class Solis(BaseResource):
for sublink in link:
self.rsa_fill_with_link_content(sublink)
return
if (not isinstance(link, dict) or not link.get('href')
or not link['href'].startswith(self.service_url)):
if not isinstance(link, dict) or not link.get('href'):
return
endpoint = link['href'][len(self.service_url):]
href = link['href']
if href.startswith('http:') and self.service_url.startswith('https:'):
# fix scheme (reverse-proxy bug, https://dev.entrouvert.org/issues/38039)
href = 'https:' + href[5:]
if not href.startswith(self.service_url):
return
endpoint = href[len(self.service_url):]
try:
value = self.request(endpoint)
except APIError as e: # do not raise on linked informations

View File

@ -50,7 +50,7 @@ RSAALLOCATAIRES = '''{
"href": "https://solis.example.net/solisapi/referentiels/civi/individu/4242/"
},
"conjoint": {
"href": "https://solis.example.net/solisapi/referentiels/civi/individu/4273/"
"href": "http://solis.example.net/solisapi/referentiels/civi/individu/4273/"
}
}
}'''
@ -61,7 +61,7 @@ RSA_3LINKS = '''{
},
"refOrientStructAcc": [
{"href": "https://solis.example.net/solisapi/referentiels/civi/individu/4242/"},
{"href": "https://solis.example.net/solisapi/referentiels/civi/individu/4242/"}
{"href": "http://solis.example.net/solisapi/referentiels/civi/individu/4242/"}
]
}
}'''
@ -963,7 +963,7 @@ def test_solis_rsa_link_infos_unlink(app, solis):
assert resp.json['data']['rsa_links']['conjoint']['content']['err'] == 1
# bad links, do nothing
for content in (RSAALLOCATAIRES.replace('https:', 'http:'),
for content in (RSAALLOCATAIRES.replace('solis.example.net', 'solis.example.org'),
RSAALLOCATAIRES.replace('href', 'xxxx')):
requests_post.reset_mock()
requests_get.reset_mock()