forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove config side effects from tests (apache#8607)
* Remove config side effects * Fix LatestOnlyOperator return type to be json serializable * Fix tests/test_configuration.py * Fix tests/executors/test_dask_executor.py * Fix tests/jobs/test_scheduler_job.py * Fix tests/models/test_cleartasks.py * Fix tests/models/test_taskinstance.py * Fix tests/models/test_xcom.py * Fix tests/security/test_kerberos.py * Fix tests/test_configuration.py * Fix tests/test_logging_config.py * Fix tests/utils/test_dag_processing.py * Apply isort * Fix tests/utils/test_email.py * Fix tests/utils/test_task_handler_with_custom_formatter.py * Fix tests/www/api/experimental/test_kerberos_endpoints.py * Fix tests/www/test_views.py * Code refactor * Fix tests/www/api/experimental/test_kerberos_endpoints.py * Fix requirements * fixup! Fix tests/www/test_views.py
- Loading branch information
Showing
16 changed files
with
161 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,47 +20,42 @@ | |
import unittest | ||
from argparse import Namespace | ||
|
||
from airflow.configuration import conf | ||
from airflow.security import kerberos | ||
from airflow.security.kerberos import renew_from_kt | ||
from tests.test_utils.config import conf_vars | ||
|
||
KRB5_KTNAME = os.environ.get('KRB5_KTNAME') | ||
|
||
@unittest.skipIf('KRB5_KTNAME' not in os.environ, | ||
'Skipping Kerberos API tests due to missing KRB5_KTNAME') | ||
|
||
@unittest.skipIf(KRB5_KTNAME is None, 'Skipping Kerberos API tests due to missing KRB5_KTNAME') | ||
class TestKerberos(unittest.TestCase): | ||
def setUp(self): | ||
|
||
if not conf.has_section("kerberos"): | ||
conf.add_section("kerberos") | ||
conf.set("kerberos", "keytab", | ||
os.environ['KRB5_KTNAME']) | ||
keytab_from_cfg = conf.get("kerberos", "keytab") | ||
self.args = Namespace(keytab=keytab_from_cfg, principal=None, pid=None, | ||
self.args = Namespace(keytab=KRB5_KTNAME, principal=None, pid=None, | ||
daemon=None, stdout=None, stderr=None, log_file=None) | ||
|
||
@conf_vars({('kerberos', 'keytab'): KRB5_KTNAME}) | ||
def test_renew_from_kt(self): | ||
""" | ||
We expect no result, but a successful run. No more TypeError | ||
""" | ||
self.assertIsNone(renew_from_kt(principal=self.args.principal, # pylint: disable=no-member | ||
keytab=self.args.keytab)) | ||
|
||
@conf_vars({('kerberos', 'keytab'): ''}) | ||
def test_args_from_cli(self): | ||
""" | ||
We expect no result, but a run with sys.exit(1) because keytab not exist. | ||
""" | ||
self.args.keytab = "test_keytab" | ||
|
||
with conf_vars({('kerberos', 'keytab'): ''}): | ||
with self.assertRaises(SystemExit) as err: | ||
renew_from_kt(principal=self.args.principal, # pylint: disable=no-member | ||
keytab=self.args.keytab) | ||
with self.assertRaises(SystemExit) as err: | ||
renew_from_kt(principal=self.args.principal, # pylint: disable=no-member | ||
keytab=self.args.keytab) | ||
|
||
with self.assertLogs(kerberos.log) as log: | ||
self.assertIn( | ||
'kinit: krb5_init_creds_set_keytab: Failed to find ' | ||
'[email protected] in keytab FILE:{} ' | ||
'(unknown enctype)'.format(self.args.keytab), log.output) | ||
with self.assertLogs(kerberos.log) as log: | ||
self.assertIn( | ||
'kinit: krb5_init_creds_set_keytab: Failed to find ' | ||
'[email protected] in keytab FILE:{} ' | ||
'(unknown enctype)'.format(self.args.keytab), log.output) | ||
|
||
self.assertEqual(err.exception.code, 1) | ||
self.assertEqual(err.exception.code, 1) |
Oops, something went wrong.