ChickenBenny commented on code in PR #76746:
URL: https://github.com/apache/airflow/pull/76746#discussion_r4595040083
##########
providers/fab/tests/unit/fab/auth_manager/security_manager/test_override.py:
##########
@@ -189,6 +189,99 @@ def
test_add_role_returns_existing_on_concurrent_insert(self, mock_log):
assert mock_session.rollback.called
assert mock_log.error.call_count == 0
+
@mock.patch("airflow.providers.fab.auth_manager.security_manager.override.log")
+ def test_add_user_returns_none_when_commit_fails(self, mock_log):
+ sm = EmptySecurityManager()
+ sm._hash_password = Mock(return_value="hashed")
+
+ mock_session = Mock(spec=Session)
+ mock_session.commit.side_effect = IntegrityError("stmt", {},
Exception("Duplicate entry"))
+
+ with mock.patch.object(EmptySecurityManager, "session", mock_session):
+ result = sm.add_user("alice", "Alice", "Smith",
"[email protected]", password="secret")
+
+ assert result is None
+ mock_session.rollback.assert_called_once()
+ mock_log.error.assert_called_once()
+
+ @mock.patch.object(EmptySecurityManager, "auth_user_registration",
new_callable=mock.PropertyMock)
+ def test_auth_user_oauth_returns_none_when_registration_fails(self,
mock_auth_user_registration):
+ mock_auth_user_registration.return_value = True
+ sm = EmptySecurityManager()
+ sm.find_user = Mock(return_value=None)
+ sm._oauth_calculate_user_roles = Mock(return_value=[])
+ sm._hash_password = Mock(return_value="hashed")
+
+ mock_session = Mock(spec=Session)
+ mock_session.commit.side_effect = IntegrityError("stmt", {},
Exception("Duplicate entry"))
+
+ with mock.patch.object(EmptySecurityManager, "session", mock_session):
+ result = sm.auth_user_oauth({"username": "alice", "email":
"[email protected]"})
+
+ assert result is None
+ mock_session.rollback.assert_called_once()
+
+ @mock.patch.object(
+ EmptySecurityManager,
+ "auth_user_registration_role",
+ new_callable=mock.PropertyMock,
+ return_value="User",
+ )
+ @mock.patch.object(
+ EmptySecurityManager, "auth_user_registration",
new_callable=mock.PropertyMock, return_value=True
+ )
+ def test_auth_user_remote_user_returns_none_when_registration_fails(self,
_, __):
Review Comment:
I merged them into one parametrized test for the helper. It covers insert
succeeded, insert failed, and a parallel login leaving an active or inactive
user. Each auth path also got a small test to make sure it goes through the
helper.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]