authentic2: when provisionning one use do it synchronously (#84815)
gitea/hobo/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2023-12-16 21:55:09 +01:00
parent 2de52d9eb2
commit 532e61f488
2 changed files with 13 additions and 2 deletions

View File

@ -126,6 +126,8 @@ class Provisionning(threading.local):
.select_related('ou')
.prefetch_related('attribute_values__attribute')
)
if len(users) == 1:
sync = True
else:
self.resolve_ou(users, ous)

View File

@ -740,7 +740,7 @@ def test_provision_using_http(transactional_db, tenant, settings, caplog):
assert notify_agents.call_count == 1
assert notify_agents.call_args[0][0]['audience'] == ['http://combo.example.net/metadata/']
assert requests_put.call_count == 1
assert '&sync=1' not in requests_put.call_args[0][0]
assert all('&sync=1' in call.args[0] for call in requests_put.mock_calls if call.args)
# cannot check audience passed to requests.put as it's the same
# dictionary that is altered afterwards and would thus also contain
# http://example.com.
@ -759,7 +759,16 @@ def test_provision_using_http(transactional_db, tenant, settings, caplog):
)
assert notify_agents.call_count == 0
assert requests_put.call_count == 2
assert '&sync=1' not in requests_put.call_args[0][0]
assert all('&sync=1' in call.args[0] for call in requests_put.mock_calls if call.args)
with patch('hobo.agent.authentic2.provisionning.notify_agents') as notify_agents:
with patch('hobo.agent.authentic2.provisionning.requests.put') as requests_put:
with provisionning:
User.objects.create(username='foo')
User.objects.create(username='bar')
assert notify_agents.call_count == 0
assert requests_put.call_count == 2
assert all('&sync=1' not in call.args[0] for call in requests_put.mock_calls if call.args)
def test_provisionning_api(transactional_db, app_factory, tenant, settings, caplog):