|
|
|
@ -11,13 +11,14 @@ import time |
|
|
|
|
from unittest.mock import patch, Mock |
|
|
|
|
|
|
|
|
|
import flask |
|
|
|
|
import gssapi |
|
|
|
|
import ldap3 |
|
|
|
|
import pytest |
|
|
|
|
import requests |
|
|
|
|
import socket |
|
|
|
|
from zope import component |
|
|
|
|
|
|
|
|
|
from .utils import gssapi_creds_ctx, ccache_cleanup # noqa: F401 |
|
|
|
|
from .utils import gssapi_token_ctx, ccache_cleanup # noqa: F401 |
|
|
|
|
from ceo_common.interfaces import IConfig, IKerberosService, ILDAPService, \ |
|
|
|
|
IFileService, IMailmanService, IHTTPClient, IUWLDAPService, IMailService |
|
|
|
|
from ceo_common.model import Config, HTTPClient |
|
|
|
@ -99,13 +100,13 @@ def g_admin_ctx(app): |
|
|
|
|
""" |
|
|
|
|
@contextlib.contextmanager |
|
|
|
|
def wrapper(): |
|
|
|
|
with gssapi_creds_ctx('ceod/admin') as creds, app.app_context(): |
|
|
|
|
with gssapi_token_ctx('ceod/admin') as token, app.app_context(): |
|
|
|
|
try: |
|
|
|
|
flask.g.auth_user = 'ceod/admin' |
|
|
|
|
flask.g.client_creds = creds |
|
|
|
|
flask.g.client_token = token |
|
|
|
|
yield |
|
|
|
|
finally: |
|
|
|
|
flask.g.pop('client_creds') |
|
|
|
|
flask.g.pop('client_token') |
|
|
|
|
flask.g.pop('auth_user') |
|
|
|
|
return wrapper |
|
|
|
|
|
|
|
|
@ -117,13 +118,13 @@ def g_syscom(app): |
|
|
|
|
Use this fixture if you need syscom credentials for an HTTP request |
|
|
|
|
to a different process. |
|
|
|
|
""" |
|
|
|
|
with gssapi_creds_ctx('ctdalek') as creds, app.app_context(): |
|
|
|
|
with gssapi_token_ctx('ctdalek') as token, app.app_context(): |
|
|
|
|
try: |
|
|
|
|
flask.g.sasl_user = 'ctdalek' |
|
|
|
|
flask.g.client_creds = creds |
|
|
|
|
flask.g.client_token = token |
|
|
|
|
yield |
|
|
|
|
finally: |
|
|
|
|
flask.g.pop('client_creds') |
|
|
|
|
flask.g.pop('client_token') |
|
|
|
|
flask.g.pop('sasl_user') |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -135,7 +136,8 @@ def ldap_conn(cfg) -> ldap3.Connection: |
|
|
|
|
server_url = cfg.get('ldap_server_url') |
|
|
|
|
# sanity check |
|
|
|
|
assert server_url == cfg.get('uwldap_server_url') |
|
|
|
|
with gssapi_creds_ctx('ceod/admin') as creds: |
|
|
|
|
with gssapi_token_ctx('ceod/admin') as token: |
|
|
|
|
creds = gssapi.Credentials(token=token) |
|
|
|
|
conn = ldap3.Connection( |
|
|
|
|
server_url, auto_bind=True, raise_exceptions=True, |
|
|
|
|
authentication=ldap3.SASL, sasl_mechanism=ldap3.KERBEROS, |
|
|
|
@ -369,7 +371,7 @@ def app_process(cfg, app, http_client): |
|
|
|
|
try: |
|
|
|
|
# Currently the HTTPClient uses SPNEGO for all requests, |
|
|
|
|
# even GETs |
|
|
|
|
with gssapi_creds_ctx('ctdalek'): |
|
|
|
|
with gssapi_token_ctx('ctdalek'): |
|
|
|
|
for i in range(5): |
|
|
|
|
try: |
|
|
|
|
http_client.get(hostname, '/ping', delegate=False) |
|
|
|
|