Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jupyter-server/jupyter_server
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0b0
Choose a base ref
...
head repository: jupyter-server/jupyter_server
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 644540b4128e8295e5cedf75e7d7d1c04ba9b3ea
Choose a head ref
  • 20 commits
  • 37 files changed
  • 14 contributors

Commits on Jul 14, 2022

  1. Copy the full SHA
    19c716b View commit details

Commits on Jul 19, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    eb9bf30 View commit details

Commits on Jul 25, 2022

  1. [pre-commit.ci] pre-commit autoupdate (#928)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    pre-commit-ci[bot] authored Jul 25, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3090893 View commit details

Commits on Jul 26, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e59610b View commit details
  2. Adds anonymous users (#863)

    * Adds anonymous users
    
    * [pre-commit.ci] auto fixes from pre-commit.com hooks
    
    for more information, see https://pre-commit.ci
    
    * removes unused import
    
    * Removes random colors
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Zachary Sailer <zsailer@apple.com>
    3 people authored Jul 26, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0c22000 View commit details

Commits on Jul 29, 2022

  1. Update security.rst

    danielyahn authored and vidartf committed Jul 29, 2022
    Copy the full SHA
    e32f726 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f373286 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    426d996 View commit details

Commits on Aug 1, 2022

  1. [pre-commit.ci] pre-commit autoupdate (#938)

    updates:
    - [github.com/asottile/pyupgrade: v2.37.2 → v2.37.3](asottile/pyupgrade@v2.37.2...v2.37.3)
    - [github.com/PyCQA/doc8: 0.11.2 → v1.0.0](PyCQA/doc8@0.11.2...v1.0.0)
    - [github.com/pycqa/flake8: 4.0.1 → 5.0.2](PyCQA/flake8@4.0.1...5.0.2)
    - [github.com/pre-commit/mirrors-eslint: v8.20.0 → v8.21.0](pre-commit/mirrors-eslint@v8.20.0...v8.21.0)
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    pre-commit-ci[bot] authored Aug 1, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    54164ac View commit details

Commits on Aug 2, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a8bf3f6 View commit details

Commits on Aug 4, 2022

  1. Fix flake8 v5 compat (#941)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    blink1073 and pre-commit-ci[bot] authored Aug 4, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ba7ac85 View commit details

Commits on Aug 8, 2022

  1. [pre-commit.ci] pre-commit autoupdate (#942)

    updates:
    - [github.com/pycqa/flake8: 5.0.2 → 5.0.4](PyCQA/flake8@5.0.2...5.0.4)
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    pre-commit-ci[bot] authored Aug 8, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7623966 View commit details

Commits on Aug 15, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    260351e View commit details
  2. [pre-commit.ci] pre-commit autoupdate (#945)

    updates:
    - [github.com/pre-commit/mirrors-eslint: v8.21.0 → v8.22.0](pre-commit/mirrors-eslint@v8.21.0...v8.22.0)
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    pre-commit-ci[bot] authored Aug 15, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    323def5 View commit details

Commits on Aug 23, 2022

  1. Fix docs build (#952)

    blink1073 authored Aug 23, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6baed5e View commit details

Commits on Aug 29, 2022

  1. Check for serverapp for reraise flag (#887)

    * Check for serverapp for reraise flag
    
    The supporting serverextension apps (enable/disable/list) should probably always complete even if an exception raises an error, so in those cases, default to just warning about exceptions, but still complete.
    
    * Add regtest for ExtensionManager wo/serverapp
    
    It should not raise exceptions if there is no serverapp.
    
    * [pre-commit.ci] auto fixes from pre-commit.com hooks
    
    for more information, see https://pre-commit.ci
    
    * Fix lint
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
    3 people authored Aug 29, 2022

    Partially verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
    Copy the full SHA
    0028483 View commit details
  2. switch to jupyter_events (#862)

    * switch to jupyter_events
    
    * update to jupyter_events 0.2.0
    
    * remove unused import
    
    * fix payload in events unit tests
    
    * update to use latest jupyter_events
    
    * add unit test for extensions
    
    * get tests working
    Zsailer authored Aug 29, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    63bb2a9 View commit details
  3. [pre-commit.ci] pre-commit autoupdate (#955)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
    pre-commit-ci[bot] and blink1073 authored Aug 29, 2022

    Partially verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
    Copy the full SHA
    cc7e6c4 View commit details

Commits on Aug 31, 2022

  1. Emit events from the Contents Service (#954)

    * emit events from the contents manager
    
    * remove unused imports
    
    * return default event_logger in contents manager
    
    * remove unused actions
    Zsailer authored Aug 31, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6dc7d53 View commit details
  2. Update pytest_plugin with fixtures to test auth in core and extensions (

    #956)
    
    Co-authored-by: Akshay Chitneni <achitneni@apple.com>
    akshaychitneni and Akshay Chitneni authored Aug 31, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    644540b View commit details
Showing with 693 additions and 285 deletions.
  1. +7 −11 .pre-commit-config.yaml
  2. +1 −0 docs/doc-requirements.txt
  3. +1 −0 docs/environment.yml
  4. +1 −1 docs/source/conf.py
  5. +1 −1 docs/source/operators/security.rst
  6. +4 −0 examples/simple/simple_ext1/handlers.py
  7. +21 −3 examples/simple/tests/test_handlers.py
  8. +3 −0 jupyter_server/__init__.py
  9. +1 −1 jupyter_server/_version.py
  10. +26 −4 jupyter_server/auth/identity.py
  11. +93 −0 jupyter_server/auth/utils.py
  12. +3 −2 jupyter_server/base/handlers.py
  13. +73 −0 jupyter_server/event_schemas/contents_service/v1.yaml
  14. +3 −3 jupyter_server/extension/manager.py
  15. +86 −22 jupyter_server/gateway/gateway_client.py
  16. +2 −1 jupyter_server/gateway/managers.py
  17. +125 −2 jupyter_server/pytest_plugin.py
  18. +28 −15 jupyter_server/serverapp.py
  19. +14 −2 jupyter_server/services/contents/filemanager.py
  20. +15 −16 jupyter_server/services/contents/handlers.py
  21. +3 −0 jupyter_server/services/contents/largefilemanager.py
  22. +26 −0 jupyter_server/services/contents/manager.py
  23. +0 −15 jupyter_server/services/events/bus.py
  24. +12 −29 jupyter_server/services/events/handlers.py
  25. +23 −18 jupyter_server/services/nbconvert/handlers.py
  26. +1 −1 jupyter_server/services/sessions/sessionmanager.py
  27. +3 −3 pyproject.toml
  28. +0 −6 readthedocs.yml
  29. +15 −72 tests/auth/test_authorizer.py
  30. +26 −2 tests/extension/mockextensions/app.py
  31. +18 −0 tests/extension/test_app.py
  32. +14 −10 tests/extension/test_manager.py
  33. +4 −0 tests/services/contents/test_api.py
  34. +2 −0 tests/services/events/mock_event.yaml
  35. +4 −5 tests/services/events/mockextension/mock_extension.py
  36. +2 −0 tests/services/events/mockextension/mock_extension_event.yaml
  37. +32 −40 tests/services/events/test_api.py
18 changes: 7 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ repos:
files: \.py$

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.961
rev: v0.971
hooks:
- id: mypy
additional_dependencies: [types-requests]
@@ -41,39 +41,35 @@ repos:
- id: prettier

- repo: https://github.com/asottile/pyupgrade
rev: v2.37.1
rev: v2.37.3
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/PyCQA/doc8
rev: 0.11.2
rev: v1.0.0
hooks:
- id: doc8
args: [--max-line-length=200]
exclude: docs/source/other/full-config.rst
stages: [manual]

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies:
[
"flake8-bugbear==20.1.4",
"flake8-logging-format==0.6.0",
"flake8-implicit-str-concat==0.2.0",
]
["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"]
stages: [manual]

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.19.0
rev: v8.23.0
hooks:
- id: eslint
stages: [manual]

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.17.0
rev: 0.18.1
hooks:
- id: check-jsonschema
name: "Check GitHub Workflows"
1 change: 1 addition & 0 deletions docs/doc-requirements.txt
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ ipykernel
jinja2
jupyter_client
jupyter_server
mistune<1.0.0
myst-parser
nbformat
prometheus_client
1 change: 1 addition & 0 deletions docs/environment.yml
Original file line number Diff line number Diff line change
@@ -5,3 +5,4 @@ dependencies:
- pip
- pip:
- -r doc-requirements.txt
- ..
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
#
__version__ = "2.0.0b0"
__version__ = "2.1.0.dev0"
# The short X.Y version.
version_parsed = parse_version(__version__)
version = f"{version_parsed.major}.{version_parsed.minor}"
2 changes: 1 addition & 1 deletion docs/source/operators/security.rst
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ as all requests requiring _authorization_ must first complete _authentication_.
Identity Providers
******************

The :class:`.IdentityProvider` class is responsible for the "authorization" step,
The :class:`.IdentityProvider` class is responsible for the "authentication" step,
identifying the user making the request,
and constructing information about them.

4 changes: 4 additions & 0 deletions examples/simple/simple_ext1/handlers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from jupyter_server.auth import authorized
from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.extension.handler import (
ExtensionHandlerJinjaMixin,
@@ -7,6 +8,9 @@


class DefaultHandler(ExtensionHandlerMixin, JupyterHandler):
auth_resource = "simple_ext1:default"

@authorized
def get(self):
# The name of the extension to which this handler is linked.
self.log.info(f"Extension Name in {self.name} Default Handler: {self.name}")
24 changes: 21 additions & 3 deletions examples/simple/tests/test_handlers.py
Original file line number Diff line number Diff line change
@@ -2,13 +2,31 @@


@pytest.fixture
def jp_server_config(jp_template_dir):
def jp_server_auth_resources(jp_server_auth_core_resources):
for url_regex in [
"/simple_ext1/default",
]:
jp_server_auth_core_resources[url_regex] = "simple_ext1:default"
return jp_server_auth_core_resources


@pytest.fixture
def jp_server_config(jp_template_dir, jp_server_authorizer):
return {
"ServerApp": {"jpserver_extensions": {"simple_ext1": True}},
"ServerApp": {
"jpserver_extensions": {"simple_ext1": True},
"authorizer_class": jp_server_authorizer,
},
}


async def test_handler_default(jp_fetch):
async def test_handler_default(jp_fetch, jp_serverapp):
jp_serverapp.authorizer.permissions = {
"actions": ["read"],
"resources": [
"simple_ext1:default",
],
}
r = await jp_fetch("simple_ext1/default", method="GET")
assert r.code == 200
assert r.body.decode().index("Hello Simple 1 - I am the default...") > -1
3 changes: 3 additions & 0 deletions jupyter_server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The Jupyter Server"""
import os
import pathlib
import subprocess
import sys

@@ -10,6 +11,8 @@
]

DEFAULT_JUPYTER_SERVER_PORT = 8888
JUPYTER_SERVER_EVENTS_URI = "https://events.jupyter.org/jupyter_server"
DEFAULT_EVENTS_SCHEMA_PATH = pathlib.Path(__file__).parent / "event_schemas"

del os

2 changes: 1 addition & 1 deletion jupyter_server/_version.py
Original file line number Diff line number Diff line change
@@ -2,5 +2,5 @@
store the current version info of the server.
"""
version_info = (2, 0, 0, "b", "0")
version_info = (2, 1, 0, ".dev", "0")
__version__ = ".".join(map(str, version_info[:3])) + "".join(version_info[3:])
30 changes: 26 additions & 4 deletions jupyter_server/auth/identity.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@

import binascii
import datetime
import json
import os
import re
import sys
@@ -24,6 +25,7 @@
from jupyter_server.transutils import _i18n

from .security import passwd_check, set_password
from .utils import get_anonymous_username

# circular imports for type checking
if TYPE_CHECKING:
@@ -290,11 +292,28 @@ def user_to_cookie(self, user: User) -> str:
Default is just the user's username.
"""
# default: username is enough
return user.username
cookie = json.dumps(
{
"username": user.username,
"name": user.name,
"display_name": user.display_name,
"initials": user.initials,
"color": user.color,
}
)
return cookie

def user_from_cookie(self, cookie_value: str) -> User | None:
"""Inverse of user_to_cookie"""
return User(username=cookie_value)
user = json.loads(cookie_value)
return User(
user["username"],
user["name"],
user["display_name"],
user["initials"],
None,
user["color"],
)

def get_cookie_name(self, handler: JupyterHandler) -> str:
"""Return the login cookie name
@@ -396,7 +415,6 @@ def get_token(self, handler: JupyterHandler) -> str | None:
- in URL parameters: ?token=<token>
- in header: Authorization: token <token>
"""

user_token = handler.get_argument("token", "")
if not user_token:
# get it from Authorization header
@@ -447,8 +465,12 @@ def generate_anonymous_user(self, handler: JupyterHandler) -> User:
but does not identify a user.
"""
user_id = uuid.uuid4().hex
moon = get_anonymous_username()
name = display_name = f"Anonymous {moon}"
initials = f"A{moon[0]}"
color = None
handler.log.info(f"Generating new user for token-authenticated request: {user_id}")
return User(user_id)
return User(user_id, name, display_name, initials, None, color)

def should_check_origin(self, handler: JupyterHandler) -> bool:
"""Should the Handler check for CORS origin validation?
93 changes: 93 additions & 0 deletions jupyter_server/auth/utils.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import importlib
import random
import re
import warnings

@@ -74,3 +75,95 @@ def match_url_to_resource(url, regex_mapping=None):
pattern = re.compile(regex)
if pattern.fullmatch(url):
return auth_resource


# From https://en.wikipedia.org/wiki/Moons_of_Jupiter
moons_of_jupyter = [
"Metis",
"Adrastea",
"Amalthea",
"Thebe",
"Io",
"Europa",
"Ganymede",
"Callisto",
"Themisto",
"Leda",
"Ersa",
"Pandia",
"Himalia",
"Lysithea",
"Elara",
"Dia",
"Carpo",
"Valetudo",
"Euporie",
"Eupheme",
# 'S/2003 J 18',
# 'S/2010 J 2',
"Helike",
# 'S/2003 J 16',
# 'S/2003 J 2',
"Euanthe",
# 'S/2017 J 7',
"Hermippe",
"Praxidike",
"Thyone",
"Thelxinoe",
# 'S/2017 J 3',
"Ananke",
"Mneme",
# 'S/2016 J 1',
"Orthosie",
"Harpalyke",
"Iocaste",
# 'S/2017 J 9',
# 'S/2003 J 12',
# 'S/2003 J 4',
"Erinome",
"Aitne",
"Herse",
"Taygete",
# 'S/2017 J 2',
# 'S/2017 J 6',
"Eukelade",
"Carme",
# 'S/2003 J 19',
"Isonoe",
# 'S/2003 J 10',
"Autonoe",
"Philophrosyne",
"Cyllene",
"Pasithee",
# 'S/2010 J 1',
"Pasiphae",
"Sponde",
# 'S/2017 J 8',
"Eurydome",
# 'S/2017 J 5',
"Kalyke",
"Hegemone",
"Kale",
"Kallichore",
# 'S/2011 J 1',
# 'S/2017 J 1',
"Chaldene",
"Arche",
"Eirene",
"Kore",
# 'S/2011 J 2',
# 'S/2003 J 9',
"Megaclite",
"Aoede",
# 'S/2003 J 23',
"Callirrhoe",
"Sinope",
]


def get_anonymous_username() -> str:
"""
Get a random user-name based on the moons of Jupyter.
This function returns names like "Anonymous Io" or "Anonymous Metis".
"""
return moons_of_jupyter[random.randint(0, len(moons_of_jupyter) - 1)]
5 changes: 3 additions & 2 deletions jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import prometheus_client
from jinja2 import TemplateNotFound
from jupyter_core.paths import is_hidden
from jupyter_events import EventLogger
from tornado import web
from tornado.log import app_log
from traitlets.config import Application
@@ -335,8 +336,8 @@ def config_manager(self):
return self.settings["config_manager"]

@property
def event_bus(self):
return self.settings["event_bus"]
def event_logger(self) -> EventLogger:
return self.settings["event_logger"]

# ---------------------------------------------------------------
# CORS
Loading