Skip to content

Commit 40c477b

Browse files
jtpiokevin-bates
andauthored
[Notebook port 4835] Add UNIX socket support to notebook server (#525)
* [Notebook port 4835] Add UNIX socket support to notebook server * Address some codeQL issues Co-authored-by: Kevin Bates <[email protected]>
1 parent 3343101 commit 40c477b

File tree

12 files changed

+841
-86
lines changed

12 files changed

+841
-86
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Jupyter Server Integration Tests [Linux]
2+
on:
3+
push:
4+
branches: 'master'
5+
pull_request:
6+
branches: '*'
7+
jobs:
8+
build:
9+
runs-on: ${{ matrix.os }}-latest
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
os: [ubuntu]
14+
python-version: [ '3.6', '3.7', '3.8', '3.9', 'pypy3' ]
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v1
18+
- name: Install Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v1
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
architecture: 'x64'
23+
- name: Upgrade packaging dependencies
24+
run: |
25+
pip install --upgrade pip setuptools wheel --user
26+
- name: Get pip cache dir
27+
id: pip-cache
28+
run: |
29+
echo "::set-output name=dir::$(pip cache dir)"
30+
- name: Cache pip
31+
uses: actions/cache@v1
32+
with:
33+
path: ${{ steps.pip-cache.outputs.dir }}
34+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
35+
restore-keys: |
36+
${{ runner.os }}-pip-${{ matrix.python-version }}-
37+
${{ runner.os }}-pip-
38+
- name: Install the Python dependencies
39+
run: |
40+
pip install -e ".[test]"
41+
- name: List installed packages
42+
run: |
43+
pip freeze
44+
pip check
45+
- name: Run the tests
46+
run: |
47+
pytest -vv --integration_tests jupyter_server

jupyter_server/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
os.path.join(os.path.dirname(__file__), 'templates'),
1111
]
1212

13+
DEFAULT_JUPYTER_SERVER_PORT = 8888
14+
1315
del os
1416

1517
from ._version import version_info, __version__

jupyter_server/base/handlers.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import jupyter_server
3232
from jupyter_server._tz import utcnow
3333
from jupyter_server.i18n import combine_translations
34-
from jupyter_server.utils import ensure_async, url_path_join, url_is_absolute, url_escape
34+
from jupyter_server.utils import ensure_async, url_path_join, url_is_absolute, url_escape, urldecode_unix_socket_path
3535
from jupyter_server.services.security import csp_report_uri
3636

3737
#-----------------------------------------------------------------------------
@@ -462,13 +462,18 @@ def check_host(self):
462462
if host.startswith('[') and host.endswith(']'):
463463
host = host[1:-1]
464464

465-
try:
466-
addr = ipaddress.ip_address(host)
467-
except ValueError:
468-
# Not an IP address: check against hostnames
469-
allow = host in self.settings.get('local_hostnames', ['localhost'])
465+
# UNIX socket handling
466+
check_host = urldecode_unix_socket_path(host)
467+
if check_host.startswith('/') and os.path.exists(check_host):
468+
allow = True
470469
else:
471-
allow = addr.is_loopback
470+
try:
471+
addr = ipaddress.ip_address(host)
472+
except ValueError:
473+
# Not an IP address: check against hostnames
474+
allow = host in self.settings.get('local_hostnames', ['localhost'])
475+
else:
476+
allow = addr.is_loopback
472477

473478
if not allow:
474479
self.log.warning(

0 commit comments

Comments
 (0)