diff --git a/sssd_test_framework/misc/__init__.py b/sssd_test_framework/misc/__init__.py index 44989ff0..747c0990 100644 --- a/sssd_test_framework/misc/__init__.py +++ b/sssd_test_framework/misc/__init__.py @@ -17,16 +17,24 @@ def attrs_parse(lines: list[str], attrs: list[str] | None = None) -> dict[str, l :rtype: dict[str, list[str]] """ out: dict[str, list[str]] = {} - for line in lines: - line = line.strip() + i = 0 + while i < len(lines): + line = lines[i].strip() if not line: + i += 1 continue (key, value) = map(lambda x: x.strip(), line.split(":", 1)) + while i < len(lines) - 1: + if lines[i + 1].startswith(" "): + value += lines[i + 1][1:] + i += 1 + else: + break if attrs is None or key in attrs: out.setdefault(key, []) out[key].append(value) - + i += 1 return out diff --git a/tests/test_misc.py b/tests/test_misc.py index 67696831..23b4cec1 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -20,9 +20,8 @@ def test_attrs_parse__nofilter(): param1: value1 param2: value2 param3: value3 - """.split( - "\n" - ) + """ + lines = textwrap.dedent(lines).strip().split("\n") expected = { "param1": ["value1"], @@ -39,10 +38,8 @@ def test_attrs_parse__filter(): param2: value2 param3: value3 param4: value4 - """.split( - "\n" - ) - + """ + lines = textwrap.dedent(lines).strip().split("\n") expected = { "param2": ["value2"], "param3": ["value3"], @@ -51,6 +48,34 @@ def test_attrs_parse__filter(): assert attrs_parse(lines, ["param2", "param3"]) == expected +test_attrs_parse__filter() + + +@pytest.mark.parametrize( + "input,expected", + [ + ( + ["cn: sudorules", "distinguishedName: objectSID=123,cn=id_m", " appings,cn=test,cn=sysdb"], + {"cn": ["sudorules"], "distinguishedName": ["objectSID=123,cn=id_mappings,cn=test,cn=sysdb"]}, + ), + ( + [ + "description: My teacher is a goo", + " d one but I do not like him", + " very much: he wears a dirty coat.", + ], + {"description": ["My teacher is a good one but I do not like him very much: he wears a dirty coat."]}, + ), + ( + ["cn: sudorules", "numbers: one,", " two,", " three"], + {"cn": ["sudorules"], "numbers": ["one, two, three"]}, + ), + ], +) +def test_attrs_parse__long_line(input, expected): + assert attrs_parse(input) == expected + + @pytest.mark.parametrize( "value,include,expected", [