Skip to content

Commit 9251d8a

Browse files
committed
debug
1 parent f3f82d5 commit 9251d8a

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

nbviewer/providers/github/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ...utils import response_text
1717
from ...utils import url_path_join
1818

19+
1920
# -----------------------------------------------------------------------------
2021
# Async GitHub Client
2122
# -----------------------------------------------------------------------------
@@ -43,6 +44,7 @@ def authenticate(self):
4344

4445
def fetch(self, url, params=None, **kwargs):
4546
"""Add GitHub auth to self.client.fetch"""
47+
assert False
4648
if not url.startswith(self.github_api_url):
4749
raise ValueError("Only fetch GitHub urls with GitHub auth (%s)" % url)
4850
params = {} if params is None else params

nbviewer/providers/github/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ async def get(self, user, repo, ref, path):
236236

237237
if not example_file_url.startswith(self.github_url):
238238
raise ValueError(
239-
"Url will never match it does not start with same domain {self.github_url}, {example_file_url}."
239+
f"Url will never match it does not start with same domain {self.github_url}, {example_file_url}."
240240
)
241241
ghu = (
242242
self.github_url if self.github_url.endswith("/") else self.github_url + "/"

nbviewer/tests/test_security.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,32 @@
1515
from .base import NBViewerTestCase
1616
from .base import skip_unless_github_auth
1717

18+
from unittest.mock import patch
19+
1820

1921
class XSSTestCase(NBViewerTestCase):
2022
def _xss(self, path, pattern="<script>alert"):
2123
r = requests.get(self.url() + path)
22-
self.assertEqual(r.status_code, 200)
23-
self.assertNotIn(pattern, r.content)
24+
# self.assertEqual(r.status_code, 200)
25+
# self.assertNotIn(pattern, r.content)
2426

2527
@skip_unless_github_auth
2628
def test_github_dirnames(self):
2729
self._xss("/github/bburky/xss/tree/%3Cscript%3Ealert(1)%3C%2fscript%3E/")
2830

2931
@skip_unless_github_auth
3032
def test_gist_filenames(self):
31-
self._xss("/gist/bburky/c020825874798a6544a7")
33+
34+
from nbviewer.providers.github.client import AsyncGitHubClient
35+
36+
AsyncGitHubClient.fetch = lambda x: "123"
37+
38+
with patch(
39+
"nbviewer.providers.github.client.AsyncGitHubClient.fetch"
40+
) as mock_fetch:
41+
mock_fetch.return_value = "123"
42+
self._xss("/gist/bburky/c020825874798a6544a7")
43+
mock_fetch.assert_called_with("123")
3244

3345

3446
class LocalDirectoryTraversalTestCase(LFRPTC):

0 commit comments

Comments
 (0)