Repository: incubator-airflow Updated Branches: refs/heads/master e5fb9c799 -> 29dbedfd0
[AIRFLOW-2462] Change PasswordUser setter to correct syntax Closes #3415 from Noremac201/setterFix Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/29dbedfd Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/29dbedfd Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/29dbedfd Branch: refs/heads/master Commit: 29dbedfd0a49c54eaf388ff940ec7cfe4a6e1f7f Parents: e5fb9c7 Author: Cameron Moberg <[email protected]> Authored: Sun Jun 3 15:07:11 2018 +0200 Committer: Fokko Driesprong <[email protected]> Committed: Sun Jun 3 15:07:11 2018 +0200 ---------------------------------------------------------------------- airflow/contrib/auth/backends/password_auth.py | 2 +- tests/core.py | 38 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/29dbedfd/airflow/contrib/auth/backends/password_auth.py ---------------------------------------------------------------------- diff --git a/airflow/contrib/auth/backends/password_auth.py b/airflow/contrib/auth/backends/password_auth.py index 9e16bb6..879aaa1 100644 --- a/airflow/contrib/auth/backends/password_auth.py +++ b/airflow/contrib/auth/backends/password_auth.py @@ -63,7 +63,7 @@ class PasswordUser(models.User): return self._password @password.setter - def _set_password(self, plaintext): + def password(self, plaintext): self._password = generate_password_hash(plaintext, 12) if PY3: self._password = str(self._password, 'utf-8') http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/29dbedfd/tests/core.py ---------------------------------------------------------------------- diff --git a/tests/core.py b/tests/core.py index 83737ed..0312fed 100644 --- a/tests/core.py +++ b/tests/core.py @@ -1865,6 +1865,44 @@ class SecureModeWebUiTests(unittest.TestCase): configuration.conf.remove_option("core", "SECURE_MODE") +class PasswordUserTest(unittest.TestCase): + def setUp(self): + user = models.User() + from airflow.contrib.auth.backends.password_auth import PasswordUser + self.password_user = PasswordUser(user) + self.password_user.username = "password_test" + + @mock.patch('airflow.contrib.auth.backends.password_auth.generate_password_hash') + def test_password_setter(self, mock_gen_pass_hash): + mock_gen_pass_hash.return_value = b"hashed_pass" if six.PY3 else "hashed_pass" + + self.password_user.password = "secure_password" + mock_gen_pass_hash.assert_called_with("secure_password", 12) + + def test_password_unicode(self): + # In python2.7 no conversion is required back to str + # In python >= 3 the method must convert from bytes to str + self.password_user.password = "secure_password" + self.assertIsInstance(self.password_user.password, str) + + def test_password_user_authenticate(self): + self.password_user.password = "secure_password" + self.assertTrue(self.password_user.authenticate("secure_password")) + + def test_password_authenticate_session(self): + from airflow.contrib.auth.backends.password_auth import PasswordUser + self.password_user.password = 'test_password' + session = Session() + session.add(self.password_user) + session.commit() + query_user = session.query(PasswordUser).filter_by( + username=self.password_user.username).first() + self.assertTrue(query_user.authenticate('test_password')) + session.query(models.User).delete() + session.commit() + session.close() + + class WebPasswordAuthTest(unittest.TestCase): def setUp(self): configuration.conf.set("webserver", "authenticate", "True")
