Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for now whitelist citations to only the DRKZ server #474

Merged
merged 3 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions backend/metagrid/api_proxy/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ def test_citation(self):

response = self.client.post(url, jo, format="json")
assert response.status_code == status.HTTP_200_OK

jo = {
"citurl": "https://aims4.llnl.gov/WDCC/meta/CMIP6/CMIP6.CMIP.IPSL.IPSL-CM6A-LR.abrupt-4xCO2.r12i1p1f1.Amon.n2oglobal.gr.v20191003.json"
}

response = self.client.post(url, jo, format="json")
assert response.status_code != status.HTTP_200_OK
7 changes: 7 additions & 0 deletions backend/metagrid/api_proxy/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from urllib.parse import urlparse

import requests
from django.http import HttpResponse, HttpResponseBadRequest
Expand Down Expand Up @@ -27,6 +28,12 @@ def do_citation(request):
return HttpResponseBadRequest()

url = jo["citurl"]

parsed_url = urlparse(url)

if not parsed_url.hostname == "cera-www.dkrz.de":
return HttpResponseBadRequest()

try:
resp = requests.get(url)
except Exception: # pragma: no cover
Expand Down