Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GBM Private key fix #1108

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions kairon/shared/chat/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def save_channel_config(configuration: Dict, bot: Text, user: Text):
:return: None
"""
primary_slack_config_changed = False
private_key = configuration['config'].get('private_key', None)
if configuration['connector_type'] == ChannelTypes.BUSINESS_MESSAGES.value and private_key:
configuration['config']['private_key'] = private_key.replace("\\n", "\n")
try:
filter_args = ChatDataProcessor.__attach_metadata_and_get_filter(configuration, bot)
channel = Channels.objects(**filter_args).get()
Expand Down
28 changes: 28 additions & 0 deletions tests/unit_test/chat/chat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,34 @@ def test_fetch_session_history(self, mock_mongo):
assert len(history[0]["events"]) == 2
assert message is None

@responses.activate
def test_save_channel_config_business_messages_with_invalid_private_key(self):
def __mock_endpoint(*args):
return f"https://[email protected]/api/bot/business_messages/tests/test"

with patch('kairon.shared.data.utils.DataUtility.get_channel_endpoint', __mock_endpoint):
channel_endpoint = ChatDataProcessor.save_channel_config(
{
"connector_type": "business_messages",
"config": {
"type": "service_account",
"private_key_id": "fa006e13b1e17eddf3990eede45ca6111eb74945",
"private_key": "test_private_key\\n399045ca\\n6111eb74945",
"client_email": "[email protected]",
"client_id": "102056160806575769486"
}
},
"test",
"test")
assert channel_endpoint == "https://[email protected]/api/bot/business_messages/tests/test"
business_messages_config = ChatDataProcessor.get_channel_config("business_messages",
"test")
assert business_messages_config['config'] == {'type': 'service_account',
'private_key_id': 'fa006e13b1e17eddf3990eede45ca6111eb*****',
'private_key': 'test_private_key\n399045ca\n6111eb*****',
'client_email': '[email protected]*****',
'client_id': '1020561608065757*****'}

@responses.activate
def test_save_channel_config_business_messages(self):
def __mock_endpoint(*args):
Expand Down
Loading