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

pacific: pybind/argparse: blocklist ip validation #51812

Merged
merged 1 commit into from Aug 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/pybind/ceph_argparse.py
Expand Up @@ -386,10 +386,21 @@ class CephIPAddr(CephArgtype):
def valid(self, s, partial=False):
# parse off port, use socket to validate addr
type = 6
if s.startswith('['):
p: Optional[str] = None
if s.startswith('v1:'):
s = s[3:]
type = 4
elif s.startswith('v2:'):
s = s[3:]
type = 6
elif s.startswith('any:'):
s = s[4:]
type = 4
elif s.startswith('['):
type = 6
elif s.find('.') != -1:
type = 4

if type == 4:
port = s.find(':')
if port != -1:
Expand Down Expand Up @@ -441,6 +452,9 @@ def valid(self, s, partial=False):
nonce = None
if '/' in s:
ip, nonce = s.split('/')
if nonce.endswith(']'):
nonce = nonce[:-1]
ip += ']'
else:
ip = s
super(self.__class__, self).valid(ip)
Expand Down
28 changes: 26 additions & 2 deletions src/test/pybind/test_ceph_argparse.py
Expand Up @@ -32,8 +32,11 @@


def get_command_descriptions(what):
print ("get_command_descriptions --" + what)
CEPH_BIN = os.environ.get('CEPH_BIN', ".")
return os.popen(CEPH_BIN + "/get_command_descriptions " + "--" + what).read()
with os.popen(CEPH_BIN + "/get_command_descriptions " + "--" + what) as output_file:
output_contents = output_file.read()
return output_contents


class ParseJsonFuncsigs(unittest.TestCase):
Expand All @@ -45,7 +48,6 @@ def test_parse_json_funcsigs(self):
commands = get_command_descriptions("pull585")
self.assertRaises(TypeError, parse_json_funcsigs, commands, 'cli')


sigdict = parse_json_funcsigs(get_command_descriptions("all"), 'cli')


Expand Down Expand Up @@ -910,6 +912,20 @@ def test_blocklist(self):
'1.2.3.4/567', '600.40'])
self._assert_valid_command(['osd', 'blocklist', action,
'1.2.3.4', '600.40'])

self._assert_valid_command(['osd', 'blocklist', action,
'v1:1.2.3.4', '600.40'])
self._assert_valid_command(['osd', 'blocklist', action,
'v1:1.2.3.4/0', '600.40'])
self._assert_valid_command(['osd', 'blocklist', action,
'v2:2001:0db8:85a3:0000:0000:8a2e:0370:7334', '600.40'])
self._assert_valid_command(['osd', 'blocklist', action,
'v2:fe80::1/0', '600.40'])
self._assert_valid_command(['osd', 'blocklist', action,
'v2:[2607:f298:4:2243::5522]:0/0', '600.40'])
self._assert_valid_command(['osd', 'blocklist', action,
'[2001:0db8::85a3:0000:8a2e:0370:7334]:0/0', '600.40'])

self.assertEqual({}, validate_command(sigdict, ['osd', 'blocklist',
action,
'invalid',
Expand All @@ -923,6 +939,14 @@ def test_blocklist(self):
'1.2.3.4/567',
'600.40',
'toomany']))
self.assertEqual({}, validate_command(sigdict, ['osd', 'blocklist',
action,
'v2:1.2.3.4/567',
'600.40']))
self.assertEqual({}, validate_command(sigdict, ['osd', 'blocklist',
action,
'v1:1.2.3.4:65536/567',
'600.40']))

def test_pool_mksnap(self):
self._assert_valid_command(['osd', 'pool', 'mksnap',
Expand Down