From d015b1933920a855a6a2cafdda863162b804ecbe Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Fri, 2 Feb 2018 08:13:12 -0500 Subject: [PATCH] ceph-volume tests for keyring parsing Signed-off-by: Alfredo Deza (cherry picked from commit b90c1a86843d8f0c8c7fb68fe059bdd72f3730fd) --- .../tests/devices/simple/test_scan.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/ceph-volume/ceph_volume/tests/devices/simple/test_scan.py b/src/ceph-volume/ceph_volume/tests/devices/simple/test_scan.py index d68fe63cb65b8..bd713f3d4f8eb 100644 --- a/src/ceph-volume/ceph_volume/tests/devices/simple/test_scan.py +++ b/src/ceph-volume/ceph_volume/tests/devices/simple/test_scan.py @@ -50,3 +50,27 @@ class TestEtcPath(object): scanner._etc_path = path with pytest.raises(RuntimeError): scanner.etc_path + + +class TestParseKeyring(object): + + def test_newlines_are_removed(self): + contents = [ + '[client.osd-lockbox.8d7a8ab2-5db0-4f83-a785-2809aba403d5]', + '\tkey = AQDtoGha/GYJExAA7HNl7Ukhqr7AKlCpLJk6UA==', ''] + assert '\n' not in scan.parse_keyring('\n'.join(contents)) + + def test_key_has_spaces_removed(self): + contents = [ + '[client.osd-lockbox.8d7a8ab2-5db0-4f83-a785-2809aba403d5]', + '\tkey = AQDtoGha/GYJExAA7HNl7Ukhqr7AKlCpLJk6UA==', ''] + result = scan.parse_keyring('\n'.join(contents)) + assert result.startswith(' ') is False + assert result.endswith(' ') is False + + def test_actual_key_is_extracted(self): + contents = [ + '[client.osd-lockbox.8d7a8ab2-5db0-4f83-a785-2809aba403d5]', + '\tkey = AQDtoGha/GYJExAA7HNl7Ukhqr7AKlCpLJk6UA==', ''] + result = scan.parse_keyring('\n'.join(contents)) + assert result == 'AQDtoGha/GYJExAA7HNl7Ukhqr7AKlCpLJk6UA==' -- 2.39.5