openmainframeproject / feilong

Feilong is a open source z/VM cloud connector project under the Open Mainframe Project umbrella that will accelerate the z/VM adoption, extending its ecosystem and its user experience. It provides a set of APIs to operate z/VM including guest, image, network, volume etc.
https://www.openmainframeproject.org/projects/feilong
Apache License 2.0
35 stars 70 forks source link

Fix regex for validating "remotehost" parameter #771

Closed Bischoff closed 9 months ago

Bischoff commented 9 months ago

The regular expression used to validate "remotehost" parameter has two problems:

This small python program permits to reproduce the problem in isolation:

import re

rbad = '^[a-zA-Z0-9\-]+\@([0-9]{1,3}(.[0-9]{1,3}){3}$|[a-zA-Z0-9\-]+(.[a-zA-Z0-9\-]){1,}$)'
rok  = '^[a-zA-Z0-9\-]+\@([0-9]{1,3}(\.[0-9]{1,3}){3}$|[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+){1,}$)'
if re.compile(rbad).match("johndoe@test-05.example.us") == None:
  print("failed")
else:
  print("matched")

Matching fails for johndoe@test-05.example.us, while this is a legitimate user@domain syntax. With the correct regular exception, it works.

Reference: https://cloudlib4zvm.readthedocs.io/en/latest/restapi.html#deploy-guest

the format is username@ip, for example, nova@9.x.x.x or username@hostname eg.``test@test.ibm.com``
Bischoff commented 9 months ago

Thank you @bjhuangr .