mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-12 20:43:02 +00:00
SSL setup for testing
Setup general ssl request, not just to api Basic tests comprised of non-ssl test copies Create the context only when request is http Refactor ssl key, cert, ca names Configure the AsyncHTTPClient at app start Change tests to import existing ones with ssl on Override __new__ in MockHub to turn on SSL
This commit is contained in:
@@ -72,7 +72,7 @@ def test_init_tokens():
|
||||
'also-super-secret': 'gordon',
|
||||
'boagasdfasdf': 'chell',
|
||||
}
|
||||
app = MockHub(db_url=db_file, api_tokens=tokens)
|
||||
app = MockHub(db_url=db_file, api_tokens=tokens, internal_certs_location=td)
|
||||
yield app.initialize([])
|
||||
db = app.db
|
||||
for token, username in tokens.items():
|
||||
@@ -82,7 +82,7 @@ def test_init_tokens():
|
||||
assert user.name == username
|
||||
|
||||
# simulate second startup, reloading same tokens:
|
||||
app = MockHub(db_url=db_file, api_tokens=tokens)
|
||||
app = MockHub(db_url=db_file, api_tokens=tokens, internal_certs_location=td)
|
||||
yield app.initialize([])
|
||||
db = app.db
|
||||
for token, username in tokens.items():
|
||||
@@ -93,7 +93,7 @@ def test_init_tokens():
|
||||
|
||||
# don't allow failed token insertion to create users:
|
||||
tokens['short'] = 'gman'
|
||||
app = MockHub(db_url=db_file, api_tokens=tokens)
|
||||
app = MockHub(db_url=db_file, api_tokens=tokens, internal_certs_location=td)
|
||||
with pytest.raises(ValueError):
|
||||
yield app.initialize([])
|
||||
assert orm.User.find(app.db, 'gman') is None
|
||||
@@ -101,7 +101,7 @@ def test_init_tokens():
|
||||
|
||||
def test_write_cookie_secret(tmpdir):
|
||||
secret_path = str(tmpdir.join('cookie_secret'))
|
||||
hub = MockHub(cookie_secret_file=secret_path)
|
||||
hub = MockHub(cookie_secret_file=secret_path, internal_certs_location=str(tmpdir))
|
||||
hub.init_secrets()
|
||||
assert os.path.exists(secret_path)
|
||||
assert os.stat(secret_path).st_mode & 0o600
|
||||
@@ -113,7 +113,7 @@ def test_cookie_secret_permissions(tmpdir):
|
||||
secret_path = str(secret_file)
|
||||
secret = os.urandom(COOKIE_SECRET_BYTES)
|
||||
secret_file.write(binascii.b2a_hex(secret))
|
||||
hub = MockHub(cookie_secret_file=secret_path)
|
||||
hub = MockHub(cookie_secret_file=secret_path, internal_certs_location=str(tmpdir))
|
||||
|
||||
# raise with public secret file
|
||||
os.chmod(secret_path, 0o664)
|
||||
@@ -131,13 +131,13 @@ def test_cookie_secret_content(tmpdir):
|
||||
secret_file.write('not base 64: uñiço∂e')
|
||||
secret_path = str(secret_file)
|
||||
os.chmod(secret_path, 0o660)
|
||||
hub = MockHub(cookie_secret_file=secret_path)
|
||||
hub = MockHub(cookie_secret_file=secret_path, internal_certs_location=str(tmpdir))
|
||||
with pytest.raises(SystemExit):
|
||||
hub.init_secrets()
|
||||
|
||||
|
||||
def test_cookie_secret_env(tmpdir):
|
||||
hub = MockHub(cookie_secret_file=str(tmpdir.join('cookie_secret')))
|
||||
hub = MockHub(cookie_secret_file=str(tmpdir.join('cookie_secret')), internal_certs_location=str(tmpdir))
|
||||
|
||||
with patch.dict(os.environ, {'JPY_COOKIE_SECRET': 'not hex'}):
|
||||
with pytest.raises(ValueError):
|
||||
@@ -150,12 +150,12 @@ def test_cookie_secret_env(tmpdir):
|
||||
|
||||
|
||||
@pytest.mark.gen_test
|
||||
def test_load_groups():
|
||||
def test_load_groups(tmpdir):
|
||||
to_load = {
|
||||
'blue': ['cyclops', 'rogue', 'wolverine'],
|
||||
'gold': ['storm', 'jean-grey', 'colossus'],
|
||||
}
|
||||
hub = MockHub(load_groups=to_load)
|
||||
hub = MockHub(load_groups=to_load, internal_certs_location=str(tmpdir))
|
||||
hub.init_db()
|
||||
yield hub.init_users()
|
||||
yield hub.init_groups()
|
||||
@@ -178,7 +178,7 @@ def test_resume_spawners(tmpdir, request):
|
||||
request.addfinalizer(p.stop)
|
||||
@gen.coroutine
|
||||
def new_hub():
|
||||
app = MockHub()
|
||||
app = MockHub(internal_certs_location=str(tmpdir))
|
||||
app.config.ConfigurableHTTPProxy.should_start = False
|
||||
app.config.ConfigurableHTTPProxy.auth_token = 'unused'
|
||||
yield app.initialize([])
|
||||
|
Reference in New Issue
Block a user