2013-02-12 09:50:00 -06:00
# Authors:
# Ana Krivokapic <akrivoka@redhat.com>
#
# Copyright (C) 2013 Red Hat
# see file 'COPYING' for use and warranty information
#
# 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.
#
# 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
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Test the ` ipalib / plugins / realmdomains . py ` module .
"""
from ipalib import api , errors
from ipapython . dn import DN
2013-05-21 06:40:27 -05:00
from ipatests . test_xmlrpc import objectclasses
2015-07-31 03:15:01 -05:00
from ipatests . test_xmlrpc . xmlrpc_test import Declarative
2015-04-24 07:39:48 -05:00
import pytest
2013-02-12 09:50:00 -06:00
cn = u ' Realm Domains '
dn = DN ( ( ' cn ' , cn ) , ( ' cn ' , ' ipa ' ) , ( ' cn ' , ' etc ' ) , api . env . basedn )
our_domain = api . env . domain
new_domain_1 = u ' example1.com '
new_domain_2 = u ' example2.com '
2013-02-21 06:40:20 -06:00
bad_domain = u ' doesnotexist.test '
2013-02-12 09:50:00 -06:00
2015-04-24 07:39:48 -05:00
@pytest.mark.tier1
2013-02-12 09:50:00 -06:00
class test_realmdomains ( Declarative ) :
2015-07-21 07:12:31 -05:00
# Make sure your environment has sound DNS configuration where
# the IPA domain has either NS or SOA record. Check your resolver
# if getting errors with the realmdomains_mod cleanup command.
2013-02-12 09:50:00 -06:00
cleanup_commands = [
( ' realmdomains_mod ' , [ ] , { ' associateddomain ' : [ our_domain ] } ) ,
]
tests = [
dict (
desc = ' Retrieve realm domains ' ,
command = ( ' realmdomains_show ' , [ ] , { } ) ,
expected = dict (
2014-03-27 08:04:00 -05:00
value = None ,
2013-02-12 09:50:00 -06:00
summary = None ,
result = dict (
dn = dn ,
associateddomain = [ our_domain ] ,
) ,
) ,
) ,
dict (
desc = ' Retrieve realm domains - print all attributes ' ,
command = ( ' realmdomains_show ' , [ ] , { ' all ' : True } ) ,
expected = dict (
2014-03-27 08:04:00 -05:00
value = None ,
2013-02-12 09:50:00 -06:00
summary = None ,
result = dict (
dn = dn ,
associateddomain = [ our_domain ] ,
cn = [ cn ] ,
objectclass = objectclasses . realmdomains ,
2014-04-11 05:32:08 -05:00
aci = [
u ' (targetattr = " associateddomain || cn || '
2014-09-12 02:59:52 -05:00
u ' createtimestamp || entryusn || '
u ' modifytimestamp || objectclass " ) '
2014-04-11 05:32:08 -05:00
u ' (targetfilter = " (objectclass=domainrelatedobject) " ) '
u ' (version 3.0;acl '
u ' " permission:System: Read Realm Domains " ; '
2014-06-19 12:06:19 -05:00
u ' allow (compare,read,search) '
2014-07-08 06:28:24 -05:00
u ' userdn = " ldap:///all " ;) ' ,
u ' (targetattr = " associateddomain " ) '
u ' (targetfilter = " (objectclass=domainrelatedobject) " ) '
u ' (version 3.0;acl '
u ' " permission:System: Modify Realm Domains " ; '
u ' allow (write) groupdn = " ldap:/// %s " ;) ' %
DN ( ' cn=System: Modify Realm Domains ' ,
api . env . container_permission ,
api . env . basedn ) ,
2014-04-11 05:32:08 -05:00
] ,
2013-02-12 09:50:00 -06:00
) ,
) ,
) ,
dict (
desc = ' Replace list of realm domains with " %s " ' % [ our_domain , new_domain_1 ] ,
2015-10-09 05:21:27 -05:00
command = ( ' realmdomains_mod ' , [ ] , { ' associateddomain ' : [ our_domain , new_domain_1 ] , ' force ' : True } ) ,
2013-02-12 09:50:00 -06:00
expected = dict (
2014-03-27 08:04:00 -05:00
value = None ,
2013-02-12 09:50:00 -06:00
summary = None ,
2015-10-09 05:21:27 -05:00
messages = ( { u ' message ' : u " The _kerberos TXT record from domain "
" example1.com could not be created ( %s .: "
" DNS zone not found). \n This can happen if the zone "
" is not managed by IPA. Please create the record "
" manually, containing the following value: "
" ' %s ' " % ( new_domain_1 , api . env . realm ) ,
u ' code ' : 13011 ,
u ' type ' : u ' warning ' ,
u ' name ' : u ' KerberosTXTRecordCreationFailure ' } ,
) ,
2013-02-12 09:50:00 -06:00
result = dict (
associateddomain = [ our_domain , new_domain_1 ] ,
) ,
) ,
) ,
dict (
desc = ' Add domain " %s " to list ' % new_domain_2 ,
2015-10-09 05:21:27 -05:00
command = ( ' realmdomains_mod ' , [ ] , { ' add_domain ' : new_domain_2 , ' force ' : True } ) ,
2013-02-12 09:50:00 -06:00
expected = dict (
2014-03-27 08:04:00 -05:00
value = None ,
2013-02-12 09:50:00 -06:00
summary = None ,
result = dict (
associateddomain = [ our_domain , new_domain_1 , new_domain_2 ] ,
) ,
2015-10-09 05:21:27 -05:00
messages = ( { u ' message ' : u " The _kerberos TXT record from domain "
" %(domain)s could not be created ( %(domain)s .: "
" DNS zone not found). \n This can happen if the zone "
" is not managed by IPA. Please create the record "
" manually, containing the following value: "
" ' %(realm)s ' " % dict ( domain = new_domain_2 ,
realm = api . env . realm ) ,
u ' code ' : 13011 ,
u ' type ' : u ' warning ' ,
u ' name ' : u ' KerberosTXTRecordCreationFailure ' } ,
) ,
2013-02-12 09:50:00 -06:00
) ,
) ,
dict (
desc = ' Delete domain " %s " from list ' % new_domain_2 ,
command = ( ' realmdomains_mod ' , [ ] , { ' del_domain ' : new_domain_2 } ) ,
expected = dict (
2014-03-27 08:04:00 -05:00
value = None ,
2013-02-12 09:50:00 -06:00
summary = None ,
result = dict (
associateddomain = [ our_domain , new_domain_1 ] ,
) ,
2015-10-09 05:21:27 -05:00
messages = ( { u ' message ' : u " The _kerberos TXT record from domain "
" %(domain)s could not be removed ( %(domain)s .: "
" DNS zone not found). \n This can happen if the zone "
" is not managed by IPA. Please remove the record "
" manually. " % dict ( domain = new_domain_2 ) ,
u ' code ' : 13012 ,
u ' type ' : u ' warning ' ,
u ' name ' : u ' KerberosTXTRecordDeletionFailure ' } ,
) ,
2013-02-12 09:50:00 -06:00
) ,
) ,
dict (
desc = ' Add domain " %s " and delete domain " %s " ' % ( new_domain_2 , new_domain_1 ) ,
2015-10-09 05:21:27 -05:00
command = ( ' realmdomains_mod ' , [ ] , { ' add_domain ' : new_domain_2 , ' del_domain ' : new_domain_1 , ' force ' : True } ) ,
2013-02-12 09:50:00 -06:00
expected = dict (
2014-03-27 08:04:00 -05:00
value = None ,
2013-02-12 09:50:00 -06:00
summary = None ,
result = dict (
associateddomain = [ our_domain , new_domain_2 ] ,
) ,
2015-10-09 05:21:27 -05:00
messages = ( { u ' message ' : u " The _kerberos TXT record from domain "
" %(domain)s could not be created ( %(domain)s .: "
" DNS zone not found). \n This can happen if the zone "
" is not managed by IPA. Please create the record "
" manually, containing the following value: "
" ' %(realm)s ' " % dict ( domain = new_domain_2 ,
realm = api . env . realm ) ,
u ' code ' : 13011 ,
u ' type ' : u ' warning ' ,
u ' name ' : u ' KerberosTXTRecordCreationFailure ' } ,
{ u ' message ' : u " The _kerberos TXT record from domain "
" %(domain)s could not be removed ( %(domain)s .: "
" DNS zone not found). \n This can happen if the zone "
" is not managed by IPA. Please remove the record "
" manually. " % dict ( domain = new_domain_1 ) ,
u ' code ' : 13012 ,
u ' type ' : u ' warning ' ,
u ' name ' : u ' KerberosTXTRecordDeletionFailure ' } ,
) ,
2013-02-12 09:50:00 -06:00
) ,
) ,
dict (
desc = ' Try to specify --domain and --add-domain options together ' ,
command = ( ' realmdomains_mod ' , [ ] , {
' associateddomain ' : [ our_domain , new_domain_1 ] ,
' add_domain ' : new_domain_1 ,
} ) ,
expected = errors . MutuallyExclusiveError (
2015-10-09 05:21:27 -05:00
reason = ' The --domain option cannot be used together with --add-domain or --del-domain. Use --domain to specify the whole realm domain list explicitly, to add/remove individual domains, use --add-domain/del-domain. ' ) ,
2013-02-12 09:50:00 -06:00
) ,
dict (
desc = ' Try to replace list of realm domains with a list without our domain ' ,
command = ( ' realmdomains_mod ' , [ ] , { ' associateddomain ' : [ new_domain_1 ] } ) ,
expected = errors . ValidationError (
2015-10-09 05:21:27 -05:00
name = ' realmdomain list ' , error = ' IPA server domain cannot be omitted ' ) ,
2013-02-12 09:50:00 -06:00
) ,
dict (
desc = ' Try to replace list of realm domains with a list with an invalid domain " %s " ' % bad_domain ,
command = ( ' realmdomains_mod ' , [ ] , { ' associateddomain ' : [ our_domain , bad_domain ] } ) ,
expected = errors . ValidationError (
2015-10-09 05:21:27 -05:00
name = ' domain ' , error = ' DNS zone for each realmdomain must contain SOA or NS records. No records found for: %s ' % bad_domain ) ,
2013-02-12 09:50:00 -06:00
) ,
dict (
desc = ' Try to add an invalid domain " %s " ' % bad_domain ,
command = ( ' realmdomains_mod ' , [ ] , { ' add_domain ' : bad_domain } ) ,
expected = errors . ValidationError (
2015-10-09 05:21:27 -05:00
name = ' domain ' , error = ' DNS zone for each realmdomain must contain SOA or NS records. No records found for: %s ' % bad_domain ) ,
2013-02-12 09:50:00 -06:00
) ,
dict (
desc = ' Try to delete our domain ' ,
command = ( ' realmdomains_mod ' , [ ] , { ' del_domain ' : our_domain } ) ,
expected = errors . ValidationError (
2015-10-09 05:21:27 -05:00
name = ' del_domain ' , error = ' IPA server domain cannot be deleted ' ) ,
2013-02-12 09:50:00 -06:00
) ,
dict (
desc = ' Try to delete domain which is not in list ' ,
command = ( ' realmdomains_mod ' , [ ] , { ' del_domain ' : new_domain_1 } ) ,
expected = errors . AttrValueNotFound (
attr = ' associateddomain ' , value = new_domain_1 ) ,
) ,
dict (
desc = ' Add an invalid domain " %s " with --force option ' % bad_domain ,
command = ( ' realmdomains_mod ' , [ ] , { ' add_domain ' : bad_domain , ' force ' : True } ) ,
expected = dict (
2014-03-27 08:04:00 -05:00
value = None ,
2013-02-12 09:50:00 -06:00
summary = None ,
result = dict (
associateddomain = [ our_domain , new_domain_2 , bad_domain ] ,
) ,
2015-10-09 05:21:27 -05:00
messages = ( { u ' message ' : u " The _kerberos TXT record from domain "
" %(domain)s could not be created ( %(domain)s .: "
" DNS zone not found). \n This can happen if the zone "
" is not managed by IPA. Please create the record "
" manually, containing the following value: "
" ' %(realm)s ' " % dict ( domain = bad_domain ,
realm = api . env . realm ) ,
u ' code ' : 13011 ,
u ' type ' : u ' warning ' ,
u ' name ' : u ' KerberosTXTRecordCreationFailure ' } ,
) ,
2013-02-12 09:50:00 -06:00
) ,
) ,
]