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

Remove strip to avoid issue when the final header is blank - with tests! #80

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion greenswitch/esl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, data):

def parse_data(self, data):
data = unquote(data)
data = data.strip().splitlines()
data = data.splitlines()
last_key = None
value = ''
for line in data:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def outbound_session(request):

@pytest.fixture(scope="function")
def disconnect_event(request):
event_plain = """
event_plain = """\
Content-Type: text/disconnect-notice
Controlled-Session-UUID: e4c3f7e0-bcc1-11ea-a87f-a5a0acaa832c
Content-Disposition: disconnect
Expand Down
50 changes: 50 additions & 0 deletions tests/test_lib_esl.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,56 @@ def on_channel_create(self, event):
self.assertEqual(self.esl.parsed_event.headers['variable_switch_r_sdp'],
expected_variable_value)

def test_event_with_blank_values_trailing(self):
"""Should not break parser when fed a key with an empty value in last header"""

self.log_blanks = None

def on_log(event):
self.log_blanks = event
self.esl.register_handle('log', on_log)

event_plain = dedent("""\
Content-Type: log/data
Content-Length: 122
Log-Level: 4
Text-Channel: 0
Log-File: sofia_reg.c
Log-Func: sofia_reg_check_gateway
Log-Line: 510
User-Data:

2021-04-03 19:05:48.882502 [WARNING] sofia_reg.c:510 ast-test-102 Failed Registration [503], setting retry to 30 seconds.
""")
self.send_fake_raw_event_plain(event_plain)
self.assertEqual(self.log_blanks.headers['User-Data'],
'')

def test_event_with_blank_values(self):
"""Should not break parser when fed a key with an empty value in any position"""

self.log_blanks = None

def on_log(event):
self.log_blanks = event
self.esl.register_handle('log', on_log)

event_plain = dedent("""\
Content-Type: log/data
Content-Length: 122
Log-Level: 4
User-Data:
Text-Channel: 0
Log-File: sofia_reg.c
Log-Func: sofia_reg_check_gateway
Log-Line: 510

2021-04-03 19:05:48.882502 [WARNING] sofia_reg.c:510 ast-test-102 Failed Registration [503], setting retry to 30 seconds.
""")
self.send_fake_raw_event_plain(event_plain)
self.assertEqual(self.log_blanks.headers['User-Data'],
'')

def test_api_response(self):
"""Should properly read api response from ESL."""
response = self.esl.send('api khomp show links concise')
Expand Down