Skip to content

Commit 9bc5946

Browse files
committed
Fix list command with blank lines
Some versions of at_client print blank lines before/after the list of certificates. This commit filters out blank lines from the response. Resolves #15 Signed-off-by: Gregers Gram Rygg <[email protected]>
1 parent 3adbebb commit 9bc5946

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/nrfcredstore/credstore.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def list(self, tag = None, type: CredType = CredType.ANY) -> List[Credential]:
6161
cmd = f'{cmd},{CredType(type).value}'
6262

6363
response_lines = self.at_client.at_command(cmd)
64+
response_lines = [line for line in response_lines if line.strip()]
65+
6466
columns = map(lambda line: line.replace('%CMNG: ', '').replace('"', '').split(','), response_lines)
6567
cred_map = map(lambda columns:
6668
Credential(int(columns[0]), int(columns[1]), columns[2].strip()),

tests/test_credstore.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ def list_all_resp(self, cred_store):
2525
'%CMNG: 567890, 1, "C485...CF09"'
2626
]
2727

28+
@pytest.fixture
29+
def list_all_resp_blank_lines(self, cred_store):
30+
cred_store.at_client.at_command.return_value = [
31+
'',
32+
'%CMNG: 12345678, 0, "978C...02C4"',
33+
'%CMNG: 567890, 1, "C485...CF09"',
34+
''
35+
]
36+
2837
@pytest.fixture
2938
def ok_resp(self, cred_store):
3039
cred_store.at_client.at_command.return_value = []
@@ -83,6 +92,12 @@ def test_list_all_credentials_returns_multiple_credentials(self, cred_store, lis
8392
assert result[0].sha == '978C...02C4'
8493
assert result[1].sha == 'C485...CF09'
8594

95+
def test_list_all_with_blank_lines_in_resp(self, cred_store, list_all_resp_blank_lines):
96+
result = cred_store.list()
97+
assert len(result) == 2
98+
assert result[0].sha == '978C...02C4'
99+
assert result[1].sha == 'C485...CF09'
100+
86101
def test_list_type_without_tag(self, cred_store):
87102
with pytest.raises(RuntimeError):
88103
cred_store.list(None, CredType(0))

0 commit comments

Comments
 (0)