diff --git a/pyanaconda/regexes.py b/pyanaconda/regexes.py index b4e52a33946..26e7be93cef 100644 --- a/pyanaconda/regexes.py +++ b/pyanaconda/regexes.py @@ -135,3 +135,25 @@ # Product Version string, just the starting numbers like 21 or 21.1 VERSION_DIGITS = r'([\d.]+)' + + +#Regexes to validate iSCSI Names according to RFC 3720 and RFC 3721 +#The conditions for iSCSI name used in the following regexes are +#(https://tools.ietf.org/html/rfc3720#section-3.2.6.3.1 , https://tools.ietf.org/html/rfc3721#page-5 and http://standards.ieee.org/regauth/oui/tutorials/EUI64.html): +#1. For iqn format: +# a. Starts with string 'iqn.' +# b. A date code specifying the year and month in which the organization +# registered the domain or sub-domain name used as the naming authority +# string. "yyyy-mm" +# c. A dot (".") +# d. The organizational naming authority string, which consists of a +# valid, reversed domain or subdomain name. +# e. Optionally, a colon (":"), followed by a string of the assigning +# organization's choosing, which must make each assigned iSCSI name +# unique. With the exception of the colon prefix, the owner of the domain +# name can assign everything after the reversed domain name as desired. +ISCSI_IQN_NAME_REGEX = re.compile(r'^iqn\.\d{4}-\d{2}((?. + +# Author(s): Sujith Pandel +# Ajith Pandel +# +import unittest + +from regexcheck import regex_match +from pyanaconda.regexes import ISCSI_IQN_NAME_REGEX, ISCSI_EUI_NAME_REGEX + +class iSCSIiqnnameRegexTestCase(unittest.TestCase): + def iqnname_test(self): + good_tests = [ + 'iqn.2014-15.com.example', + 'iqn.2014-15.com.example:iscsi', + 'iqn.2014-15.c-om.example:iscsi', + 'iqn.2014-15.c.om.example:iscsi', + 'iqn.2014-15.com.example:...', + 'iqn.2014-15.com.example:iscsi_@nything_except_colon_after_colon!' + ] + + bad_tests = [ + 'iqn', + 'iqn.', + 'iqn.2014-15', + 'iqn.2014-15.', + 'iqn.2014-15..', + 'iqn.2014-15.com.example.', + 'iqn.2014-15.com.example...', + 'iqn.2014-15.com.example:', + 'iqn.2014-15.-com.example', + 'iqn.2014-15.com-.example', + 'iqn.2014-15.-.example', + 'iqn.2014-15.com.example-:iscsi', + 'abciqn.2014-15.com.example:iscsi', + 'iqn.2014-15.-.example:iscsi', + 'iqn.2014-15.com&com.example:iscsi', + 'iqn.2014-15.com.example:iscsi:doublecolon', + 'iqn.2014-15..om.example:iscsi', + ] + + if not regex_match(ISCSI_IQN_NAME_REGEX, good_tests, bad_tests): + self.fail() + +class iSCSIeuinameRegexTestCase(unittest.TestCase): + def euiname_test(self): + good_tests = [ + 'eui.ABCDEF0123456789', + 'eui.abcdef0123456789', + 'eui.0123456789ABCDEF' + ] + + bad_tests = [ + 'eui', + 'eui.', + 'eui.2014-', + 'eui.exampleeui789abc' + 'eui.AAAABBBBCCC2345', + 'eui.AAAABBBBCCCCD4567' + ] + + if not regex_match(ISCSI_EUI_NAME_REGEX, good_tests, bad_tests): + self.fail()