Skip to content

Commit

Permalink
[Notebook port 4835] Add UNIX socket support to notebook server (#525)
Browse files Browse the repository at this point in the history
* [Notebook port 4835] Add UNIX socket support to notebook server

* Address some codeQL issues

Co-authored-by: Kevin Bates <kbates4@gmail.com>
  • Loading branch information
jtpio and kevin-bates authored May 24, 2021
1 parent 3343101 commit 40c477b
Show file tree
Hide file tree
Showing 12 changed files with 841 additions and 86 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Jupyter Server Integration Tests [Linux]
on:
push:
branches: 'master'
pull_request:
branches: '*'
jobs:
build:
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu]
python-version: [ '3.6', '3.7', '3.8', '3.9', 'pypy3' ]
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
- name: Upgrade packaging dependencies
run: |
pip install --upgrade pip setuptools wheel --user
- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: Cache pip
uses: actions/cache@v1
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Install the Python dependencies
run: |
pip install -e ".[test]"
- name: List installed packages
run: |
pip freeze
pip check
- name: Run the tests
run: |
pytest -vv --integration_tests jupyter_server
2 changes: 2 additions & 0 deletions jupyter_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
os.path.join(os.path.dirname(__file__), 'templates'),
]

DEFAULT_JUPYTER_SERVER_PORT = 8888

del os

from ._version import version_info, __version__
Expand Down
19 changes: 12 additions & 7 deletions jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import jupyter_server
from jupyter_server._tz import utcnow
from jupyter_server.i18n import combine_translations
from jupyter_server.utils import ensure_async, url_path_join, url_is_absolute, url_escape
from jupyter_server.utils import ensure_async, url_path_join, url_is_absolute, url_escape, urldecode_unix_socket_path
from jupyter_server.services.security import csp_report_uri

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -462,13 +462,18 @@ def check_host(self):
if host.startswith('[') and host.endswith(']'):
host = host[1:-1]

try:
addr = ipaddress.ip_address(host)
except ValueError:
# Not an IP address: check against hostnames
allow = host in self.settings.get('local_hostnames', ['localhost'])
# UNIX socket handling
check_host = urldecode_unix_socket_path(host)
if check_host.startswith('/') and os.path.exists(check_host):
allow = True
else:
allow = addr.is_loopback
try:
addr = ipaddress.ip_address(host)
except ValueError:
# Not an IP address: check against hostnames
allow = host in self.settings.get('local_hostnames', ['localhost'])
else:
allow = addr.is_loopback

if not allow:
self.log.warning(
Expand Down
Loading

0 comments on commit 40c477b

Please sign in to comment.