2009-06-24 15:12:27 +02:00
# Authors:
# Rob Crittenden <rcritten@redhat.com>
# Pavel Zuna <pzuna@redhat.com>
#
2009-12-15 13:36:14 -07:00
# Copyright (C) 2008, 2009 Red Hat
2009-06-24 15:12:27 +02:00
# see file 'COPYING' for use and warranty information
#
2010-12-09 13:59:11 +01: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.
2009-06-24 15:12:27 +02: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 13:59:11 +01:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2009-12-15 13:36:14 -07:00
2009-06-24 15:12:27 +02:00
"""
2009-12-15 13:36:14 -07:00
Test the ` ipalib . plugins . host ` module .
2009-06-24 15:12:27 +02:00
"""
2011-04-26 16:45:19 -04:00
from ipalib import api , errors , x509
2011-08-09 21:21:56 -04:00
from ipalib . dn import *
2011-04-26 16:45:19 -04:00
from tests . test_xmlrpc . xmlrpc_test import Declarative , fuzzy_uuid , fuzzy_digits
2011-07-27 11:02:00 +02:00
from tests . test_xmlrpc . xmlrpc_test import fuzzy_hash , fuzzy_date , fuzzy_issuer
2012-03-06 15:53:07 -05:00
from tests . test_xmlrpc . xmlrpc_test import fuzzy_hex
2009-12-15 13:36:14 -07:00
from tests . test_xmlrpc import objectclasses
2010-11-05 15:16:53 -04:00
import base64
2009-12-15 13:36:14 -07:00
fqdn1 = u ' testhost1. %s ' % api . env . domain
2010-03-29 11:31:10 -04:00
short1 = u ' testhost1 '
2011-08-09 21:21:56 -04:00
dn1 = DN ( ( ' fqdn ' , fqdn1 ) , ( ' cn ' , ' computers ' ) , ( ' cn ' , ' accounts ' ) ,
api . env . basedn )
2010-03-29 11:31:10 -04:00
service1 = u ' dns/ %s @ %s ' % ( fqdn1 , api . env . realm )
2011-08-09 21:21:56 -04:00
service1dn = DN ( ( ' krbprincipalname ' , service1 . lower ( ) ) , ( ' cn ' , ' services ' ) ,
( ' cn ' , ' accounts ' ) , api . env . basedn )
2010-07-22 14:16:22 -04:00
fqdn2 = u ' shouldnotexist. %s ' % api . env . domain
2011-08-09 21:21:56 -04:00
dn2 = DN ( ( ' fqdn ' , fqdn2 ) , ( ' cn ' , ' computers ' ) , ( ' cn ' , ' accounts ' ) ,
api . env . basedn )
2010-11-10 16:47:29 -05:00
fqdn3 = u ' testhost2. %s ' % api . env . domain
short3 = u ' testhost2 '
2011-08-09 21:21:56 -04:00
dn3 = DN ( ( ' fqdn ' , fqdn3 ) , ( ' cn ' , ' computers ' ) , ( ' cn ' , ' accounts ' ) ,
api . env . basedn )
2011-07-05 13:36:48 -04:00
fqdn4 = u ' testhost2.lab. %s ' % api . env . domain
2011-08-09 21:21:56 -04:00
dn4 = DN ( ( ' fqdn ' , fqdn4 ) , ( ' cn ' , ' computers ' ) , ( ' cn ' , ' accounts ' ) ,
api . env . basedn )
2012-02-29 13:31:20 -05:00
invalidfqdn1 = u ' foo_bar.lab. %s ' % api . env . domain
2009-12-15 13:36:14 -07:00
2011-04-26 16:45:19 -04:00
# We can use the same cert we generated for the service tests
fd = open ( ' tests/test_xmlrpc/service.crt ' , ' r ' )
servercert = fd . readlines ( )
servercert = ' ' . join ( servercert )
servercert = x509 . strip_header ( servercert )
fd . close ( )
2009-12-15 13:36:14 -07:00
class test_host ( Declarative ) :
cleanup_commands = [
( ' host_del ' , [ fqdn1 ] , { } ) ,
2010-07-22 14:16:22 -04:00
( ' host_del ' , [ fqdn2 ] , { } ) ,
2010-11-10 16:47:29 -05:00
( ' host_del ' , [ fqdn3 ] , { } ) ,
2011-07-05 13:36:48 -04:00
( ' host_del ' , [ fqdn4 ] , { } ) ,
2010-03-29 11:31:10 -04:00
( ' service_del ' , [ service1 ] , { } ) ,
2009-12-15 13:36:14 -07:00
]
tests = [
dict (
desc = ' Try to retrieve non-existent %r ' % fqdn1 ,
command = ( ' host_show ' , [ fqdn1 ] , { } ) ,
expected = errors . NotFound ( reason = ' no such entry ' ) ,
) ,
dict (
desc = ' Try to update non-existent %r ' % fqdn1 ,
command = ( ' host_mod ' , [ fqdn1 ] , dict ( description = u ' Nope ' ) ) ,
expected = errors . NotFound ( reason = ' no such entry ' ) ,
) ,
dict (
desc = ' Try to delete non-existent %r ' % fqdn1 ,
command = ( ' host_del ' , [ fqdn1 ] , { } ) ,
expected = errors . NotFound ( reason = ' no such entry ' ) ,
) ,
dict (
desc = ' Create %r ' % fqdn1 ,
command = ( ' host_add ' , [ fqdn1 ] ,
dict (
description = u ' Test host 1 ' ,
2010-02-12 16:34:21 -05:00
l = u ' Undisclosed location 1 ' ,
2010-07-22 14:16:22 -04:00
force = True ,
2009-12-15 13:36:14 -07:00
) ,
) ,
expected = dict (
value = fqdn1 ,
summary = u ' Added host " %s " ' % fqdn1 ,
result = dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn1 ,
2009-12-17 06:16:18 -07:00
fqdn = [ fqdn1 ] ,
description = [ u ' Test host 1 ' ] ,
2010-02-12 16:34:21 -05:00
l = [ u ' Undisclosed location 1 ' ] ,
2009-12-17 06:16:18 -07:00
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn1 , api . env . realm ) ] ,
2009-12-15 13:36:14 -07:00
objectclass = objectclasses . host ,
2009-12-17 06:16:18 -07:00
ipauniqueid = [ fuzzy_uuid ] ,
2010-11-10 16:47:29 -05:00
managedby_host = [ fqdn1 ] ,
2011-08-22 16:24:07 -04:00
has_keytab = False ,
has_password = False ,
2009-12-15 13:36:14 -07:00
) ,
) ,
) ,
dict (
desc = ' Try to create duplicate %r ' % fqdn1 ,
command = ( ' host_add ' , [ fqdn1 ] ,
dict (
description = u ' Test host 1 ' ,
localityname = u ' Undisclosed location 1 ' ,
2010-07-22 14:16:22 -04:00
force = True ,
2009-12-15 13:36:14 -07:00
) ,
) ,
expected = errors . DuplicateEntry ( ) ,
) ,
dict (
desc = ' Retrieve %r ' % fqdn1 ,
command = ( ' host_show ' , [ fqdn1 ] , { } ) ,
expected = dict (
value = fqdn1 ,
summary = None ,
result = dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn1 ,
2009-12-17 06:16:18 -07:00
fqdn = [ fqdn1 ] ,
description = [ u ' Test host 1 ' ] ,
2010-02-12 16:34:21 -05:00
l = [ u ' Undisclosed location 1 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn1 , api . env . realm ) ] ,
2010-11-10 16:47:29 -05:00
has_keytab = False ,
2011-08-22 16:24:07 -04:00
has_password = False ,
2010-11-10 16:47:29 -05:00
managedby_host = [ fqdn1 ] ,
2009-12-15 13:36:14 -07:00
) ,
) ,
) ,
dict (
desc = ' Retrieve %r with all=True ' % fqdn1 ,
command = ( ' host_show ' , [ fqdn1 ] , dict ( all = True ) ) ,
expected = dict (
value = fqdn1 ,
summary = None ,
result = dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn1 ,
2009-12-17 06:16:18 -07:00
cn = [ fqdn1 ] ,
fqdn = [ fqdn1 ] ,
description = [ u ' Test host 1 ' ] ,
2009-12-15 13:36:14 -07:00
# FIXME: Why is 'localalityname' returned as 'l' with --all?
# It is intuitive for --all to return additional attributes,
# but not to return existing attributes under different
# names.
2009-12-17 06:16:18 -07:00
l = [ u ' Undisclosed location 1 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn1 , api . env . realm ) ] ,
serverhostname = [ u ' testhost1 ' ] ,
2009-12-15 13:36:14 -07:00
objectclass = objectclasses . host ,
2010-11-10 16:47:29 -05:00
managedby_host = [ fqdn1 ] ,
2011-06-13 16:23:09 +02:00
managing_host = [ fqdn1 ] ,
2009-12-17 06:16:18 -07:00
ipauniqueid = [ fuzzy_uuid ] ,
2011-08-22 16:24:07 -04:00
has_keytab = False ,
has_password = False ,
2009-12-15 13:36:14 -07:00
) ,
) ,
) ,
dict (
desc = ' Search for %r ' % fqdn1 ,
command = ( ' host_find ' , [ fqdn1 ] , { } ) ,
expected = dict (
count = 1 ,
truncated = False ,
summary = u ' 1 host matched ' ,
2009-12-17 06:16:18 -07:00
result = [
2009-12-15 13:36:14 -07:00
dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn1 ,
2009-12-17 06:16:18 -07:00
fqdn = [ fqdn1 ] ,
description = [ u ' Test host 1 ' ] ,
2010-02-12 16:34:21 -05:00
l = [ u ' Undisclosed location 1 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn1 , api . env . realm ) ] ,
2010-11-10 16:47:29 -05:00
managedby_host = [ u ' %s ' % fqdn1 ] ,
2011-08-22 16:24:07 -04:00
has_keytab = False ,
has_password = False ,
2009-12-15 13:36:14 -07:00
) ,
2009-12-17 06:16:18 -07:00
] ,
2009-12-15 13:36:14 -07:00
) ,
) ,
dict (
desc = ' Search for %r with all=True ' % fqdn1 ,
command = ( ' host_find ' , [ fqdn1 ] , dict ( all = True ) ) ,
expected = dict (
count = 1 ,
truncated = False ,
summary = u ' 1 host matched ' ,
2009-12-17 06:16:18 -07:00
result = [
2009-12-15 13:36:14 -07:00
dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn1 ,
2009-12-17 06:16:18 -07:00
cn = [ fqdn1 ] ,
fqdn = [ fqdn1 ] ,
description = [ u ' Test host 1 ' ] ,
2009-12-15 13:36:14 -07:00
# FIXME: Why is 'localalityname' returned as 'l' with --all?
# It is intuitive for --all to return additional attributes,
# but not to return existing attributes under different
# names.
2009-12-17 06:16:18 -07:00
l = [ u ' Undisclosed location 1 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn1 , api . env . realm ) ] ,
serverhostname = [ u ' testhost1 ' ] ,
2009-12-15 13:36:14 -07:00
objectclass = objectclasses . host ,
2009-12-17 06:16:18 -07:00
ipauniqueid = [ fuzzy_uuid ] ,
2010-11-10 16:47:29 -05:00
managedby_host = [ u ' %s ' % fqdn1 ] ,
2011-06-13 16:23:09 +02:00
managing_host = [ u ' %s ' % fqdn1 ] ,
2011-08-22 16:24:07 -04:00
has_keytab = False ,
has_password = False ,
2009-12-15 13:36:14 -07:00
) ,
2009-12-17 06:16:18 -07:00
] ,
2009-12-15 13:36:14 -07:00
) ,
) ,
dict (
desc = ' Update %r ' % fqdn1 ,
2010-11-05 15:16:53 -04:00
command = ( ' host_mod ' , [ fqdn1 ] , dict ( description = u ' Updated host 1 ' ,
usercertificate = servercert ) ) ,
2009-12-15 13:36:14 -07:00
expected = dict (
value = fqdn1 ,
summary = u ' Modified host " %s " ' % fqdn1 ,
result = dict (
2009-12-17 06:16:18 -07:00
description = [ u ' Updated host 1 ' ] ,
2010-02-12 16:34:21 -05:00
fqdn = [ fqdn1 ] ,
l = [ u ' Undisclosed location 1 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn1 , api . env . realm ) ] ,
2010-11-10 16:47:29 -05:00
managedby_host = [ u ' %s ' % fqdn1 ] ,
2010-11-05 15:16:53 -04:00
usercertificate = [ base64 . b64decode ( servercert ) ] ,
2011-04-26 16:45:19 -04:00
valid_not_before = fuzzy_date ,
valid_not_after = fuzzy_date ,
2011-08-09 21:21:56 -04:00
subject = lambda x : DN ( x ) == \
DN ( ( ' CN ' , api . env . host ) , ( ' O ' , api . env . realm ) ) ,
2011-04-26 16:45:19 -04:00
serial_number = fuzzy_digits ,
2012-03-06 15:53:07 -05:00
serial_number_hex = fuzzy_hex ,
2011-04-26 16:45:19 -04:00
md5_fingerprint = fuzzy_hash ,
sha1_fingerprint = fuzzy_hash ,
2011-07-27 11:02:00 +02:00
issuer = fuzzy_issuer ,
2011-08-25 09:24:47 -04:00
has_keytab = False ,
has_password = False ,
2009-12-15 13:36:14 -07:00
) ,
) ,
) ,
dict (
desc = ' Retrieve %r to verify update ' % fqdn1 ,
command = ( ' host_show ' , [ fqdn1 ] , { } ) ,
expected = dict (
value = fqdn1 ,
summary = None ,
result = dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn1 ,
2009-12-17 06:16:18 -07:00
fqdn = [ fqdn1 ] ,
description = [ u ' Updated host 1 ' ] ,
2010-02-12 16:34:21 -05:00
l = [ u ' Undisclosed location 1 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn1 , api . env . realm ) ] ,
2010-11-05 15:16:53 -04:00
has_keytab = False ,
2011-08-22 16:24:07 -04:00
has_password = False ,
2010-11-10 16:47:29 -05:00
managedby_host = [ u ' %s ' % fqdn1 ] ,
2010-11-05 15:16:53 -04:00
usercertificate = [ base64 . b64decode ( servercert ) ] ,
2011-04-26 16:45:19 -04:00
valid_not_before = fuzzy_date ,
valid_not_after = fuzzy_date ,
2011-08-09 21:21:56 -04:00
subject = lambda x : DN ( x ) == \
DN ( ( ' CN ' , api . env . host ) , ( ' O ' , api . env . realm ) ) ,
2011-04-26 16:45:19 -04:00
serial_number = fuzzy_digits ,
2012-03-06 15:53:07 -05:00
serial_number_hex = fuzzy_hex ,
2011-04-26 16:45:19 -04:00
md5_fingerprint = fuzzy_hash ,
sha1_fingerprint = fuzzy_hash ,
2011-07-27 11:02:00 +02:00
issuer = fuzzy_issuer ,
2009-12-15 13:36:14 -07:00
) ,
) ,
) ,
2010-11-10 16:47:29 -05:00
dict (
desc = ' Create %r ' % fqdn3 ,
command = ( ' host_add ' , [ fqdn3 ] ,
dict (
description = u ' Test host 2 ' ,
l = u ' Undisclosed location 2 ' ,
force = True ,
) ,
) ,
expected = dict (
value = fqdn3 ,
summary = u ' Added host " %s " ' % fqdn3 ,
result = dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn3 ,
2010-11-10 16:47:29 -05:00
fqdn = [ fqdn3 ] ,
description = [ u ' Test host 2 ' ] ,
l = [ u ' Undisclosed location 2 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn3 , api . env . realm ) ] ,
objectclass = objectclasses . host ,
ipauniqueid = [ fuzzy_uuid ] ,
managedby_host = [ u ' %s ' % fqdn3 ] ,
2011-08-22 16:24:07 -04:00
has_keytab = False ,
has_password = False ,
2010-11-10 16:47:29 -05:00
) ,
) ,
) ,
2011-07-05 13:36:48 -04:00
dict (
desc = ' Create %r ' % fqdn4 ,
command = ( ' host_add ' , [ fqdn4 ] ,
dict (
description = u ' Test host 4 ' ,
l = u ' Undisclosed location 4 ' ,
force = True ,
) ,
) ,
expected = dict (
value = fqdn4 ,
summary = u ' Added host " %s " ' % fqdn4 ,
result = dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn4 ,
2011-07-05 13:36:48 -04:00
fqdn = [ fqdn4 ] ,
description = [ u ' Test host 4 ' ] ,
l = [ u ' Undisclosed location 4 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn4 , api . env . realm ) ] ,
objectclass = objectclasses . host ,
ipauniqueid = [ fuzzy_uuid ] ,
managedby_host = [ u ' %s ' % fqdn4 ] ,
2011-08-22 16:24:07 -04:00
has_keytab = False ,
has_password = False ,
2011-07-05 13:36:48 -04:00
) ,
) ,
) ,
2010-11-10 16:47:29 -05:00
dict (
desc = ' Add managedby_host %r to %r ' % ( fqdn1 , fqdn3 ) ,
command = ( ' host_add_managedby ' , [ fqdn3 ] ,
dict (
host = u ' %s ' % fqdn1 ,
) ,
) ,
expected = dict (
completed = 1 ,
failed = dict (
managedby = dict (
host = tuple ( ) ,
) ,
) ,
result = dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn3 ,
2010-11-10 16:47:29 -05:00
fqdn = [ fqdn3 ] ,
description = [ u ' Test host 2 ' ] ,
l = [ u ' Undisclosed location 2 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn3 , api . env . realm ) ] ,
managedby_host = [ u ' %s ' % fqdn3 , u ' %s ' % fqdn1 ] ,
) ,
) ,
) ,
dict (
desc = ' Retrieve %r ' % fqdn3 ,
command = ( ' host_show ' , [ fqdn3 ] , { } ) ,
expected = dict (
value = fqdn3 ,
summary = None ,
result = dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn3 ,
2010-11-10 16:47:29 -05:00
fqdn = [ fqdn3 ] ,
description = [ u ' Test host 2 ' ] ,
l = [ u ' Undisclosed location 2 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn3 , api . env . realm ) ] ,
has_keytab = False ,
2011-08-22 16:24:07 -04:00
has_password = False ,
2010-11-10 16:47:29 -05:00
managedby_host = [ u ' %s ' % fqdn3 , u ' %s ' % fqdn1 ] ,
) ,
) ,
) ,
2012-01-26 13:41:39 +01:00
dict (
desc = ' Search for hosts with --man-hosts and --not-man-hosts ' ,
command = ( ' host_find ' , [ ] , { ' man_host ' : fqdn3 , ' not_man_host ' : fqdn1 } ) ,
expected = dict (
count = 1 ,
truncated = False ,
summary = u ' 1 host matched ' ,
result = [
dict (
dn = lambda x : DN ( x ) == dn3 ,
fqdn = [ fqdn3 ] ,
description = [ u ' Test host 2 ' ] ,
l = [ u ' Undisclosed location 2 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn3 , api . env . realm ) ] ,
has_keytab = False ,
has_password = False ,
managedby_host = [ u ' %s ' % fqdn3 , u ' %s ' % fqdn1 ] ,
) ,
] ,
) ,
) ,
dict (
desc = ' Try to search for hosts with --man-hosts ' ,
command = ( ' host_find ' , [ ] , { ' man_host ' : [ fqdn3 , fqdn4 ] } ) ,
expected = dict (
count = 0 ,
truncated = False ,
summary = u ' 0 hosts matched ' ,
result = [ ] ,
) ,
) ,
2010-11-10 16:47:29 -05:00
dict (
desc = ' Remove managedby_host %r from %r ' % ( fqdn1 , fqdn3 ) ,
command = ( ' host_remove_managedby ' , [ fqdn3 ] ,
dict (
host = u ' %s ' % fqdn1 ,
) ,
) ,
expected = dict (
completed = 1 ,
failed = dict (
managedby = dict (
host = tuple ( ) ,
) ,
) ,
result = dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn3 ,
2010-11-10 16:47:29 -05:00
fqdn = [ fqdn3 ] ,
description = [ u ' Test host 2 ' ] ,
l = [ u ' Undisclosed location 2 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn3 , api . env . realm ) ] ,
managedby_host = [ u ' %s ' % fqdn3 ] ,
) ,
) ,
) ,
2011-07-05 13:36:48 -04:00
dict (
desc = ' Show a host with multiple matches %s ' % short3 ,
command = ( ' host_show ' , [ short3 ] , { } ) ,
expected = errors . SingleMatchExpected ( found = 2 ) ,
) ,
2009-12-15 13:36:14 -07:00
2010-10-18 14:53:32 -04:00
dict (
desc = ' Try to rename %r ' % fqdn1 ,
command = ( ' host_mod ' , [ fqdn1 ] , dict ( setattr = u ' fqdn=changed ' ) ) ,
expected = errors . NotAllowedOnRDN ( )
) ,
2012-01-20 15:10:44 -05:00
dict (
desc = ' Add MAC address to %r ' % fqdn1 ,
command = ( ' host_mod ' , [ fqdn1 ] , dict ( macaddress = u ' 00:50:56:30:F6:5F ' ) ) ,
expected = dict (
value = fqdn1 ,
summary = u ' Modified host " %s " ' % fqdn1 ,
result = dict (
description = [ u ' Updated host 1 ' ] ,
fqdn = [ fqdn1 ] ,
l = [ u ' Undisclosed location 1 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn1 , api . env . realm ) ] ,
managedby_host = [ u ' %s ' % fqdn1 ] ,
usercertificate = [ base64 . b64decode ( servercert ) ] ,
valid_not_before = fuzzy_date ,
valid_not_after = fuzzy_date ,
subject = lambda x : DN ( x ) == \
DN ( ( ' CN ' , api . env . host ) , ( ' O ' , api . env . realm ) ) ,
serial_number = fuzzy_digits ,
2012-03-06 15:53:07 -05:00
serial_number_hex = fuzzy_hex ,
2012-01-20 15:10:44 -05:00
md5_fingerprint = fuzzy_hash ,
sha1_fingerprint = fuzzy_hash ,
macaddress = [ u ' 00:50:56:30:F6:5F ' ] ,
issuer = fuzzy_issuer ,
has_keytab = False ,
has_password = False ,
) ,
) ,
) ,
dict (
desc = ' Add another MAC address to %r ' % fqdn1 ,
command = ( ' host_mod ' , [ fqdn1 ] , dict ( macaddress = [ u ' 00:50:56:30:F6:5F ' , u ' 00:50:56:2C:8D:82 ' ] ) ) ,
expected = dict (
value = fqdn1 ,
summary = u ' Modified host " %s " ' % fqdn1 ,
result = dict (
description = [ u ' Updated host 1 ' ] ,
fqdn = [ fqdn1 ] ,
l = [ u ' Undisclosed location 1 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn1 , api . env . realm ) ] ,
managedby_host = [ u ' %s ' % fqdn1 ] ,
usercertificate = [ base64 . b64decode ( servercert ) ] ,
valid_not_before = fuzzy_date ,
valid_not_after = fuzzy_date ,
subject = lambda x : DN ( x ) == \
DN ( ( ' CN ' , api . env . host ) , ( ' O ' , api . env . realm ) ) ,
serial_number = fuzzy_digits ,
2012-03-06 15:53:07 -05:00
serial_number_hex = fuzzy_hex ,
2012-01-20 15:10:44 -05:00
md5_fingerprint = fuzzy_hash ,
sha1_fingerprint = fuzzy_hash ,
macaddress = [ u ' 00:50:56:30:F6:5F ' , u ' 00:50:56:2C:8D:82 ' ] ,
issuer = fuzzy_issuer ,
has_keytab = False ,
has_password = False ,
) ,
) ,
) ,
dict (
desc = ' Add an illegal MAC address to %r ' % fqdn1 ,
command = ( ' host_mod ' , [ fqdn1 ] , dict ( macaddress = [ u ' xx ' ] ) ) ,
expected = errors . ValidationError ( name = ' macaddress ' , error = ' invalid \' macaddress \' : Must be of the form HH:HH:HH:HH:HH:HH, where each H is a hexadecimal character. ' ) ,
) ,
2009-12-15 13:36:14 -07:00
dict (
desc = ' Delete %r ' % fqdn1 ,
command = ( ' host_del ' , [ fqdn1 ] , { } ) ,
expected = dict (
value = fqdn1 ,
summary = u ' Deleted host " %s " ' % fqdn1 ,
2011-01-07 11:17:55 -05:00
result = dict ( failed = u ' ' ) ,
2009-12-15 13:36:14 -07:00
) ,
) ,
dict (
desc = ' Try to retrieve non-existent %r ' % fqdn1 ,
command = ( ' host_show ' , [ fqdn1 ] , { } ) ,
expected = errors . NotFound ( reason = ' no such entry ' ) ,
) ,
dict (
desc = ' Try to update non-existent %r ' % fqdn1 ,
command = ( ' host_mod ' , [ fqdn1 ] , dict ( description = u ' Nope ' ) ) ,
expected = errors . NotFound ( reason = ' no such entry ' ) ,
) ,
dict (
desc = ' Try to delete non-existent %r ' % fqdn1 ,
command = ( ' host_del ' , [ fqdn1 ] , { } ) ,
expected = errors . NotFound ( reason = ' no such entry ' ) ,
) ,
2010-03-29 11:31:10 -04:00
# Test deletion using a non-fully-qualified hostname. Services
# associated with this host should also be removed.
dict (
desc = ' Re-create %r ' % fqdn1 ,
command = ( ' host_add ' , [ fqdn1 ] ,
dict (
description = u ' Test host 1 ' ,
l = u ' Undisclosed location 1 ' ,
2010-07-22 14:16:22 -04:00
force = True ,
2010-03-29 11:31:10 -04:00
) ,
) ,
expected = dict (
value = fqdn1 ,
summary = u ' Added host " %s " ' % fqdn1 ,
result = dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn1 ,
2010-03-29 11:31:10 -04:00
fqdn = [ fqdn1 ] ,
description = [ u ' Test host 1 ' ] ,
l = [ u ' Undisclosed location 1 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn1 , api . env . realm ) ] ,
objectclass = objectclasses . host ,
ipauniqueid = [ fuzzy_uuid ] ,
2010-11-10 16:47:29 -05:00
managedby_host = [ u ' %s ' % fqdn1 ] ,
2011-08-22 16:24:07 -04:00
has_keytab = False ,
has_password = False ,
2010-03-29 11:31:10 -04:00
) ,
) ,
) ,
dict (
desc = ' Add a service to host %r ' % fqdn1 ,
2010-07-22 14:16:22 -04:00
command = ( ' service_add ' , [ service1 ] , { ' force ' : True } ) ,
2010-03-29 11:31:10 -04:00
expected = dict (
value = service1 ,
summary = u ' Added service " %s " ' % service1 ,
result = dict (
2011-08-22 16:24:07 -04:00
dn = lambda x : DN ( x ) == service1dn ,
2010-03-29 11:31:10 -04:00
krbprincipalname = [ service1 ] ,
objectclass = objectclasses . service ,
2010-08-05 22:41:32 -04:00
managedby_host = [ fqdn1 ] ,
2010-03-29 11:31:10 -04:00
ipauniqueid = [ fuzzy_uuid ] ,
) ,
) ,
) ,
dict (
desc = ' Delete using host name %r ' % short1 ,
command = ( ' host_del ' , [ short1 ] , { } ) ,
expected = dict (
value = short1 ,
summary = u ' Deleted host " %s " ' % short1 ,
2011-01-07 11:17:55 -05:00
result = dict ( failed = u ' ' ) ,
2010-03-29 11:31:10 -04:00
) ,
) ,
dict (
desc = ' Search for services for %r ' % fqdn1 ,
command = ( ' service_find ' , [ fqdn1 ] , { } ) ,
expected = dict (
count = 0 ,
truncated = False ,
2010-08-05 22:41:32 -04:00
summary = u ' 0 services matched ' ,
2010-03-29 11:31:10 -04:00
result = [
] ,
) ,
) ,
2010-07-22 14:16:22 -04:00
dict (
desc = ' Try to add host not in DNS %r without force ' % fqdn2 ,
command = ( ' host_add ' , [ fqdn2 ] , { } ) ,
expected = errors . DNSNotARecordError ( reason = ' Host does not have corresponding DNS A record ' ) ,
) ,
dict (
desc = ' Try to add host not in DNS %r with force ' % fqdn2 ,
command = ( ' host_add ' , [ fqdn2 ] ,
dict (
description = u ' Test host 2 ' ,
l = u ' Undisclosed location 2 ' ,
force = True ,
) ,
) ,
expected = dict (
value = fqdn2 ,
summary = u ' Added host " %s " ' % fqdn2 ,
result = dict (
2011-08-09 21:21:56 -04:00
dn = lambda x : DN ( x ) == dn2 ,
2010-07-22 14:16:22 -04:00
fqdn = [ fqdn2 ] ,
description = [ u ' Test host 2 ' ] ,
l = [ u ' Undisclosed location 2 ' ] ,
krbprincipalname = [ u ' host/ %s @ %s ' % ( fqdn2 , api . env . realm ) ] ,
objectclass = objectclasses . host ,
ipauniqueid = [ fuzzy_uuid ] ,
2010-11-10 16:47:29 -05:00
managedby_host = [ u ' %s ' % fqdn2 ] ,
2011-08-22 16:24:07 -04:00
has_keytab = False ,
has_password = False ,
2010-07-22 14:16:22 -04:00
) ,
) ,
) ,
2012-02-22 17:42:38 -05:00
# This test will only succeed when running against lite-server.py
# on same box as IPA install.
dict (
desc = ' Delete the current host (master?) %s should be caught ' % api . env . host ,
command = ( ' host_del ' , [ api . env . host ] , { } ) ,
expected = errors . ValidationError ( name = ' fqdn ' , error = ' An IPA master host cannot be deleted ' ) ,
) ,
2012-02-29 13:31:20 -05:00
dict (
desc = ' Test that validation is enabled on adds ' ,
command = ( ' host_add ' , [ invalidfqdn1 ] , { } ) ,
expected = errors . ValidationError ( name = ' fqdn ' , error = ' may only include letters, numbers, and - ' ) ,
) ,
# The assumption on these next 4 tests is that if we don't get a
# validation error then the request was processed normally.
dict (
desc = ' Test that validation is disabled on mods ' ,
command = ( ' host_mod ' , [ invalidfqdn1 ] , { } ) ,
expected = errors . NotFound ( reason = ' no such entry ' ) ,
) ,
dict (
desc = ' Test that validation is disabled on deletes ' ,
command = ( ' host_del ' , [ invalidfqdn1 ] , { } ) ,
expected = errors . NotFound ( reason = ' no such entry ' ) ,
) ,
dict (
desc = ' Test that validation is disabled on show ' ,
command = ( ' host_show ' , [ invalidfqdn1 ] , { } ) ,
expected = errors . NotFound ( reason = ' no such entry ' ) ,
) ,
dict (
desc = ' Test that validation is disabled on find ' ,
command = ( ' host_find ' , [ invalidfqdn1 ] , { } ) ,
expected = dict (
count = 0 ,
truncated = False ,
summary = u ' 0 hosts matched ' ,
result = [ ] ,
) ,
) ,
2009-12-15 13:36:14 -07:00
]