2013-11-27 07:53:57 -06:00
|
|
|
#! /usr/bin/python2 -E
|
2007-09-21 09:24:36 -05:00
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2007-09-21 09:24:36 -05:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2010-12-09 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-09-21 09:24:36 -05:00
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
|
|
|
sys.path.insert(0, ".")
|
|
|
|
|
|
|
|
import unittest
|
2015-04-24 07:39:48 -05:00
|
|
|
import pytest
|
2007-09-21 09:24:36 -05:00
|
|
|
|
2009-02-09 14:17:17 -06:00
|
|
|
from ipapython import ipavalidate
|
2007-09-21 09:24:36 -05:00
|
|
|
|
2015-04-24 07:39:48 -05:00
|
|
|
pytestmark = pytest.mark.tier0
|
|
|
|
|
2007-09-21 09:24:36 -05:00
|
|
|
class TestValidate(unittest.TestCase):
|
2007-12-07 16:07:03 -06:00
|
|
|
def test_validEmail(self):
|
2008-08-06 12:00:36 -05:00
|
|
|
self.assertEqual(True, ipavalidate.Email("test@freeipa.org"))
|
|
|
|
self.assertEqual(True, ipavalidate.Email("", notEmpty=False))
|
2007-09-21 09:24:36 -05:00
|
|
|
|
2007-12-07 16:07:03 -06:00
|
|
|
def test_invalidEmail(self):
|
2008-08-06 12:00:36 -05:00
|
|
|
self.assertEqual(False, ipavalidate.Email("test"))
|
|
|
|
self.assertEqual(False, ipavalidate.Email("test@freeipa"))
|
|
|
|
self.assertEqual(False, ipavalidate.Email("test@.com"))
|
|
|
|
self.assertEqual(False, ipavalidate.Email(""))
|
|
|
|
self.assertEqual(False, ipavalidate.Email(None))
|
2007-09-21 09:24:36 -05:00
|
|
|
|
2007-12-07 16:07:03 -06:00
|
|
|
def test_validPlain(self):
|
2008-08-06 12:00:36 -05:00
|
|
|
self.assertEqual(True, ipavalidate.Plain("Joe User"))
|
|
|
|
self.assertEqual(True, ipavalidate.Plain("Joe O'Malley"))
|
|
|
|
self.assertEqual(True, ipavalidate.Plain("", notEmpty=False))
|
|
|
|
self.assertEqual(True, ipavalidate.Plain(None, notEmpty=False))
|
|
|
|
self.assertEqual(True, ipavalidate.Plain("JoeUser", allowSpaces=False))
|
|
|
|
self.assertEqual(True, ipavalidate.Plain("JoeUser", allowSpaces=True))
|
2007-09-21 09:24:36 -05:00
|
|
|
|
2007-12-07 16:07:03 -06:00
|
|
|
def test_invalidPlain(self):
|
2008-08-06 12:00:36 -05:00
|
|
|
self.assertEqual(False, ipavalidate.Plain("Joe (User)"))
|
|
|
|
self.assertEqual(False, ipavalidate.Plain("Joe C. User"))
|
|
|
|
self.assertEqual(False, ipavalidate.Plain("", notEmpty=True))
|
|
|
|
self.assertEqual(False, ipavalidate.Plain(None, notEmpty=True))
|
|
|
|
self.assertEqual(False, ipavalidate.Plain("Joe User", allowSpaces=False))
|
|
|
|
self.assertEqual(False, ipavalidate.Plain("Joe C. User"))
|
2007-09-21 09:24:36 -05:00
|
|
|
|
2007-12-07 16:07:03 -06:00
|
|
|
def test_validString(self):
|
2008-08-06 12:00:36 -05:00
|
|
|
self.assertEqual(True, ipavalidate.String("Joe User"))
|
|
|
|
self.assertEqual(True, ipavalidate.String("Joe O'Malley"))
|
|
|
|
self.assertEqual(True, ipavalidate.String("", notEmpty=False))
|
|
|
|
self.assertEqual(True, ipavalidate.String(None, notEmpty=False))
|
|
|
|
self.assertEqual(True, ipavalidate.String("Joe C. User"))
|
2007-09-21 09:24:36 -05:00
|
|
|
|
2007-12-07 16:07:03 -06:00
|
|
|
def test_invalidString(self):
|
2008-08-06 12:00:36 -05:00
|
|
|
self.assertEqual(False, ipavalidate.String("", notEmpty=True))
|
|
|
|
self.assertEqual(False, ipavalidate.String(None, notEmpty=True))
|
2007-12-07 16:07:03 -06:00
|
|
|
|
|
|
|
def test_validPath(self):
|
2008-08-06 12:00:36 -05:00
|
|
|
self.assertEqual(True, ipavalidate.Path("/"))
|
|
|
|
self.assertEqual(True, ipavalidate.Path("/home/user"))
|
|
|
|
self.assertEqual(True, ipavalidate.Path("../home/user"))
|
|
|
|
self.assertEqual(True, ipavalidate.Path("", notEmpty=False))
|
|
|
|
self.assertEqual(True, ipavalidate.Path(None, notEmpty=False))
|
2007-12-07 16:07:03 -06:00
|
|
|
|
|
|
|
def test_invalidPath(self):
|
2008-08-06 12:00:36 -05:00
|
|
|
self.assertEqual(False, ipavalidate.Path("(foo)"))
|
|
|
|
self.assertEqual(False, ipavalidate.Path("", notEmpty=True))
|
|
|
|
self.assertEqual(False, ipavalidate.Path(None, notEmpty=True))
|
|
|
|
|
|
|
|
def test_validName(self):
|
|
|
|
self.assertEqual(True, ipavalidate.GoodName("foo"))
|
|
|
|
self.assertEqual(True, ipavalidate.GoodName("1foo"))
|
|
|
|
self.assertEqual(True, ipavalidate.GoodName("foo.bar"))
|
|
|
|
self.assertEqual(True, ipavalidate.GoodName("foo.bar$"))
|
|
|
|
|
|
|
|
def test_invalidName(self):
|
|
|
|
self.assertEqual(False, ipavalidate.GoodName("foo bar"))
|
|
|
|
self.assertEqual(False, ipavalidate.GoodName("foo%bar"))
|
|
|
|
self.assertEqual(False, ipavalidate.GoodName("*foo"))
|
|
|
|
self.assertEqual(False, ipavalidate.GoodName("$foo.bar$"))
|
2007-09-21 09:24:36 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|