0001-agent-authentic2-add-debug-mode-for-provisionning-54.patch
hobo/agent/authentic2/provisionning.py | ||
---|---|---|
1 | 1 |
import copy |
2 |
import datetime |
|
2 | 3 |
import json |
3 | 4 |
import logging |
4 | 5 |
import threading |
... | ... | |
486 | 487 |
self.add_saved(other_instance) |
487 | 488 | |
488 | 489 |
def notify_agents(self, data): |
490 |
log_path = getattr(settings, 'DEBUG_PROVISIONNING_LOG_PATH', '') |
|
491 |
if log_path and getattr(settings, 'HOBO_PROVISIONNING_DEBUG', False): |
|
492 |
try: |
|
493 |
with open(log_path, 'a') as f: |
|
494 |
f.write('%s %s ' % (datetime.datetime.now().isoformat(), connection.tenant.domain_url)) |
|
495 |
json.dump(data, f) |
|
496 |
f.write('\n') |
|
497 |
except IOError: |
|
498 |
pass |
|
499 | ||
489 | 500 |
if getattr(settings, 'HOBO_HTTP_PROVISIONNING', False): |
490 | 501 |
leftover_audience = self.notify_agents_http(data) |
491 | 502 |
if not leftover_audience: |
tests_authentic/test_provisionning.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 | |
3 | 3 |
import json |
4 |
import os |
|
4 | 5 | |
5 | 6 |
import lasso |
6 | 7 |
import pytest |
... | ... | |
739 | 740 |
) |
740 | 741 |
assert resp.json['err'] == 1 |
741 | 742 |
assert resp.json['leftover_audience'] |
743 | ||
744 | ||
745 |
def test_provision_debug(transactional_db, tenant, caplog, settings, tmpdir): |
|
746 |
log_path = str(tmpdir / 'debug-provisionning.log') |
|
747 |
settings.DEBUG_PROVISIONNING_LOG_PATH = log_path |
|
748 |
settings.HOBO_PROVISIONNING_DEBUG = True |
|
749 | ||
750 |
assert not os.path.exists(log_path) |
|
751 | ||
752 |
with patch('hobo.agent.authentic2.provisionning.notify_agents') as notify_agents: |
|
753 |
with tenant_context(tenant): |
|
754 |
LibertyProvider.objects.create( |
|
755 |
ou=get_default_ou(), |
|
756 |
name='provider', |
|
757 |
entity_id='http://provider.com', |
|
758 |
protocol_conformance=lasso.PROTOCOL_SAML_2_0, |
|
759 |
) |
|
760 |
with provisionning: |
|
761 |
role = Role.objects.create(name='coin', ou=get_default_ou()) |
|
762 | ||
763 |
assert notify_agents.call_count == 1 |
|
764 |
assert os.path.exists(log_path) |
|
742 |
- |