diff --git a/notebook/tests/test_notebookapp.py b/notebook/tests/test_notebookapp.py index 22a9cfc12..a7f38e2cd 100644 --- a/notebook/tests/test_notebookapp.py +++ b/notebook/tests/test_notebookapp.py @@ -1,11 +1,18 @@ """Test NotebookApp""" - +import getpass import logging import os import re +from subprocess import Popen, PIPE, STDOUT +import sys from tempfile import NamedTemporaryFile +try: + from unittest.mock import patch +except ImportError: + from mock import patch # py2 + import nose.tools as nt from traitlets.tests.utils import check_help_all_output @@ -14,7 +21,7 @@ from jupyter_core.application import NoStart from ipython_genutils.tempdir import TemporaryDirectory from traitlets import TraitError from notebook import notebookapp, __version__ -from notebook import notebookapp +from notebook.auth.security import passwd_check NotebookApp = notebookapp.NotebookApp @@ -117,3 +124,17 @@ def raise_on_bad_version(version): def test_current_version(): raise_on_bad_version(__version__) + +def test_notebook_password(): + password = 'secret' + with TemporaryDirectory() as td: + with patch.dict('os.environ', { + 'JUPYTER_CONFIG_DIR': td, + }), patch.object(getpass, 'getpass', return_value=password): + app = notebookapp.NotebookPasswordApp(log_level=logging.ERROR) + app.initialize([]) + app.start() + nb = NotebookApp() + nb.load_config_file() + nt.assert_not_equal(nb.password, '') + passwd_check(nb.password, password)