<s> from django . test import TestCase <EOL> from django . core . exceptions import ValidationError <EOL> from mozdns . domain . models import Domain <EOL> from mozdns . nameserver . models import Nameserver <EOL> from mozdns . mx . models import MX <EOL> from mozdns . srv . models import SRV <EOL> from mozdns . txt . models import TXT <EOL> from mozdns . ptr . models import PTR <EOL> from mozdns . cname . models import CNAME <EOL> from mozdns . address_record . models import AddressRecord <EOL> from core . registration . static . models import StaticReg <EOL> from mozdns . ip . utils import ip_to_domain_name <EOL> from systems . tests . utils import create_fake_host <EOL> from mozdns . tests . utils import create_fake_zone <EOL> class CNAMETests ( TestCase ) : <EOL> def create_domain ( self , name , ip_type = None , delegated = False ) : <EOL> if ip_type is None : <EOL> ip_type = '<STR_LIT:4>' <EOL> if name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> pass <EOL> else : <EOL> name = ip_to_domain_name ( name , ip_type = ip_type ) <EOL> d = Domain ( name = name , delegated = delegated ) <EOL> d . clean ( ) <EOL> self . assertTrue ( d . is_reverse ) <EOL> return d <EOL> def setUp ( self ) : <EOL> self . g = create_fake_zone ( "<STR_LIT>" , suffix = "<STR_LIT>" ) <EOL> self . c_g = create_fake_zone ( "<STR_LIT>" , suffix = "<STR_LIT>" ) <EOL> self . d = create_fake_zone ( "<STR_LIT>" , suffix = "<STR_LIT>" ) <EOL> self . r1 = create_fake_zone ( "<STR_LIT>" , suffix = "<STR_LIT>" ) <EOL> self . r1 . save ( ) <EOL> self . s = create_fake_host ( hostname = "<STR_LIT>" ) <EOL> self . s . save ( ) <EOL> def do_add ( self , label , domain , data ) : <EOL> cn = CNAME ( label = label , domain = domain , target = data ) <EOL> cn . full_clean ( ) <EOL> cn . save ( ) <EOL> cn . save ( ) <EOL> self . assertTrue ( cn . get_absolute_url ( ) ) <EOL> self . assertTrue ( cn . get_edit_url ( ) ) <EOL> self . assertTrue ( cn . get_delete_url ( ) ) <EOL> self . assertTrue ( cn . details ( ) ) <EOL> cs = CNAME . objects . filter ( <EOL> label = label , domain = domain , target = data ) <EOL> self . assertEqual ( len ( cs ) , <NUM_LIT:1> ) <EOL> return cn <EOL> def test_add ( self ) : <EOL> label = "<STR_LIT:foo>" <EOL> domain = self . g <EOL> data = "<STR_LIT>" <EOL> self . do_add ( label , domain , data ) <EOL> label = "<STR_LIT>" <EOL> domain = self . c_g <EOL> data = "<STR_LIT>" <EOL> self . do_add ( label , domain , data ) <EOL> label = "<STR_LIT>" <EOL> domain = self . g <EOL> data = "<STR_LIT>" <EOL> self . do_add ( label , domain , data ) <EOL> self . assertRaises ( ValidationError , self . do_add , * ( label , domain , data ) ) <EOL> label = "<STR_LIT>" <EOL> domain = self . c_g <EOL> data = "<STR_LIT>" <EOL> self . do_add ( label , domain , data ) <EOL> def test1_add_glob ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . g <EOL> data = "<STR_LIT>" <EOL> self . do_add ( label , domain , data ) <EOL> label = "<STR_LIT:*>" <EOL> domain = self . c_g <EOL> data = "<STR_LIT>" <EOL> self . do_add ( label , domain , data ) <EOL> label = "<STR_LIT>" <EOL> domain = self . g <EOL> data = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , self . do_add , * ( label , domain , data ) ) <EOL> label = "<STR_LIT>" <EOL> domain = self . g <EOL> data = "<STR_LIT>" <EOL> self . do_add ( label , domain , data ) <EOL> def test2_add_glob ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . g <EOL> data = "<STR_LIT>" <EOL> self . do_add ( label , domain , data ) <EOL> label = "<STR_LIT:*>" <EOL> domain = self . c_g <EOL> data = "<STR_LIT>" <EOL> self . do_add ( label , domain , data ) <EOL> def test_soa_condition ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . c_g <EOL> data = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , self . do_add , * ( label , domain , data ) ) <EOL> def test_add_bad ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . g <EOL> data = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , self . do_add , * ( label , domain , data ) ) <EOL> def test_add_mx_with_cname ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . c_g <EOL> data = "<STR_LIT>" <EOL> fqdn = label + '<STR_LIT:.>' + domain . name <EOL> mx_data = { '<STR_LIT:label>' : '<STR_LIT>' , '<STR_LIT>' : self . c_g , '<STR_LIT>' : <EOL> fqdn , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT> } <EOL> mx = MX ( ** mx_data ) <EOL> mx . save ( ) <EOL> cn = CNAME ( label = label , domain = domain , target = data ) <EOL> self . assertRaises ( ValidationError , cn . full_clean ) <EOL> def test_address_record_exists ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> rec , _ = AddressRecord . objects . get_or_create ( <EOL> label = label , domain = dom , ip_type = '<STR_LIT:4>' , ip_str = "<STR_LIT>" ) <EOL> cn = CNAME ( label = label , domain = dom , target = data ) <EOL> self . assertRaises ( ValidationError , cn . full_clean ) <EOL> def test_address_record_exists_upper_case ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> rec , _ = AddressRecord . objects . get_or_create ( <EOL> label = label , domain = dom , ip_type = '<STR_LIT:4>' , ip_str = "<STR_LIT>" ) <EOL> cn = CNAME ( label = label . title ( ) , domain = dom , target = data ) <EOL> self . assertRaises ( ValidationError , cn . full_clean ) <EOL> def test_address_record_cname_exists ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> CNAME . objects . get_or_create ( label = label , domain = dom , target = data ) <EOL> rec = AddressRecord ( label = label , domain = dom , ip_str = "<STR_LIT>" ) <EOL> self . assertRaises ( ValidationError , rec . save ) <EOL> def test_address_record_cname_exists_upper ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> CNAME . objects . get_or_create ( label = label , domain = dom , target = data ) <EOL> rec = AddressRecord ( <EOL> label = label . title ( ) , domain = dom , ip_str = "<STR_LIT>" ) <EOL> self . assertRaises ( ValidationError , rec . save ) <EOL> def test_srv_exists ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> rec , _ = SRV . objects . get_or_create ( <EOL> label = label , domain = dom , target = "<STR_LIT>" , <EOL> port = <NUM_LIT:2> , priority = <NUM_LIT:2> , weight = <NUM_LIT:4> ) <EOL> cn = CNAME ( label = label , domain = dom , target = data ) <EOL> self . assertRaises ( ValidationError , cn . full_clean ) <EOL> def test_srv_cname_exists ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> CNAME . objects . get_or_create ( <EOL> label = label , domain = dom , target = data ) <EOL> rec = SRV ( label = label , domain = dom , target = "<STR_LIT>" , <EOL> port = <NUM_LIT:2> , priority = <NUM_LIT:2> , weight = <NUM_LIT:4> ) <EOL> self . assertRaises ( ValidationError , rec . save ) <EOL> def test_txt_exists ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> rec , _ = TXT . objects . get_or_create ( <EOL> label = label , domain = dom , txt_data = "<STR_LIT>" ) <EOL> cn = CNAME ( label = label , domain = dom , target = data ) <EOL> self . assertRaises ( ValidationError , cn . full_clean ) <EOL> def test_txt_cname_exists ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> cn , _ = CNAME . objects . get_or_create ( <EOL> label = label , domain = dom , target = data ) <EOL> cn . full_clean ( ) <EOL> cn . save ( ) <EOL> rec = TXT ( label = label , domain = dom , txt_data = "<STR_LIT>" ) <EOL> self . assertRaises ( ValidationError , rec . save ) <EOL> def test_mx_exists ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> rec , _ = MX . objects . get_or_create ( <EOL> label = label , domain = dom , server = "<STR_LIT>" , <EOL> priority = <NUM_LIT> , ttl = <NUM_LIT> ) <EOL> cn = CNAME ( label = label , domain = dom , target = data ) <EOL> self . assertRaises ( ValidationError , cn . full_clean ) <EOL> def test_mx_cname_exists ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> cn , _ = CNAME . objects . get_or_create ( <EOL> label = label , domain = dom , target = data ) <EOL> cn . full_clean ( ) <EOL> cn . save ( ) <EOL> rec = MX ( label = label , domain = dom , server = "<STR_LIT>" , <EOL> priority = <NUM_LIT> , ttl = <NUM_LIT> ) <EOL> self . assertRaises ( ValidationError , rec . save ) <EOL> def test_ns_exists ( self ) : <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> rec = Nameserver ( domain = dom , server = "<STR_LIT>" ) <EOL> rec . save ( ) <EOL> cn = CNAME ( label = '<STR_LIT>' , domain = dom , target = data ) <EOL> self . assertRaises ( ValidationError , cn . clean ) <EOL> def test_ns_cname_exists ( self ) : <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> cn , _ = CNAME . objects . get_or_create ( <EOL> label = '<STR_LIT>' , domain = dom , target = data ) <EOL> cn . full_clean ( ) <EOL> cn . save ( ) <EOL> rec = Nameserver ( domain = dom , server = "<STR_LIT>" ) <EOL> self . assertRaises ( ValidationError , rec . save ) <EOL> def test_sreg_exists ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> StaticReg . objects . create ( <EOL> label = label , domain = dom , ip_str = "<STR_LIT>" , ip_type = '<STR_LIT:4>' , <EOL> system = self . s ) <EOL> cn = CNAME ( label = label , domain = dom , target = data ) <EOL> self . assertRaises ( ValidationError , cn . full_clean ) <EOL> def test_sreg_cname_exists ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> cn , _ = CNAME . objects . get_or_create ( <EOL> label = label , domain = dom , target = data ) <EOL> cn . full_clean ( ) <EOL> cn . save ( ) <EOL> sreg = StaticReg ( <EOL> label = label , domain = dom , ip_str = "<STR_LIT>" , ip_type = '<STR_LIT:4>' , <EOL> system = self . s ) <EOL> self . assertRaises ( ValidationError , sreg . clean ) <EOL> cn . label = "<STR_LIT>" <EOL> cn . save ( ) <EOL> sreg . clean ( ) <EOL> sreg . save ( ) <EOL> def test_ptr_exists ( self ) : <EOL> print "<STR_LIT>" <EOL> return <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> rec = PTR ( ip_str = "<STR_LIT>" , ip_type = '<STR_LIT:4>' , name = '<STR_LIT>' ) <EOL> rec . full_clean ( ) <EOL> rec . save ( ) <EOL> cn = CNAME ( label = label , domain = dom , target = data ) <EOL> self . assertRaises ( ValidationError , cn . full_clean ) <EOL> def test_ptr_cname_exists ( self ) : <EOL> print "<STR_LIT>" <EOL> return <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> CNAME . objects . get_or_create ( label = label , domain = dom , target = data ) <EOL> rec = PTR ( ip_str = "<STR_LIT>" , ip_type = '<STR_LIT:4>' , name = '<STR_LIT>' ) <EOL> self . assertRaises ( ValidationError , rec . clean ) <EOL> def test_cname_cname_exists ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> CNAME . objects . get_or_create ( <EOL> label = label , domain = dom , target = '<STR_LIT>' <EOL> ) <EOL> self . assertRaises ( <EOL> ValidationError , CNAME . objects . create , <EOL> ** { '<STR_LIT:label>' : label , '<STR_LIT>' : dom , '<STR_LIT:target>' : data } <EOL> ) <EOL> def test_cname_point_to_itself ( self ) : <EOL> label = "<STR_LIT>" <EOL> data = "<STR_LIT>" <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> dom , _ = Domain . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> cn = CNAME ( label = label , domain = dom , target = data ) <EOL> self . assertRaises ( ValidationError , cn . clean ) </s>
