1#!/usr/bin/perl -w 2 3use Net::DRI; 4use Net::DRI::Data::Raw; 5use DateTime::Duration; 6 7use Test::More tests => 13; 8eval { no warnings; require Test::LongString; Test::LongString->import(max => 100); $Test::LongString::Context=50; }; 9*{'main::is_string'}=\&main::is if $@; 10 11our $E1='<?xml version="1.0" encoding="UTF-8" standalone="no"?><epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">'; 12our $E2='</epp>'; 13our $TRID='<trID><clTRID>ABC-12345</clTRID><svTRID>54322-XYZ</svTRID></trID>'; 14 15our $R1; 16sub mysend 17{ 18 my ($transport,$count,$msg)=@_; 19 $R1=$msg->as_string(); 20 return 1; 21} 22 23our $R2; 24sub myrecv 25{ 26 return Net::DRI::Data::Raw->new_from_string($R2? $R2 : $E1.'<response>'.r().$TRID.'</response>'.$E2); 27} 28 29my $dri=Net::DRI::TrapExceptions->new(10); 30$dri->{trid_factory}=sub { return 'ABC-12345'; }; 31$dri->add_registry('CentralNic'); 32$dri->target('CentralNic')->add_current_profile('p1','test=epp',{f_send=>\&mysend,f_recv=>\&myrecv}); 33 34my $rc; 35my $s; 36my $d; 37my ($dh,@c); 38 39#################################################################################################### 40## DNS TTL extension 41 42$R2=$E1.'<response>'.r().'<resData><domain:infData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"><domain:name>example2.eu.com</domain:name><domain:roid>CNIC-DO302520</domain:roid><domain:status s="ok"/><domain:registrant>C11480</domain:registrant><domain:contact type="tech">C11480</domain:contact><domain:clID>C11480</domain:clID><domain:ns><domain:hostObj>ns0.example.com</domain:hostObj><domain:hostObj>ns1.example.com</domain:hostObj></domain:ns><domain:crDate>1995-01-01T00:00:00.0Z</domain:crDate><domain:exDate>2020-01-01T23:59:59.0Z</domain:exDate><domain:upDate>2005-05-14T11:15:19.0Z</domain:upDate></domain:infData></resData><extension><ttl:infData xmlns:ttl="urn:centralnic:params:xml:ns:ttl-1.0" xsi:schemaLocation="urn:centralnic:params:xml:ns:ttl-1.0 ttl-1.0.xsd"><ttl:secs>3600</ttl:secs></ttl:infData></extension>'.$TRID.'</response>'.$E2; 43$rc=$dri->domain_info('example2.eu.com'); 44$s=$dri->get_info('ttl'); 45isa_ok($s,'DateTime::Duration','TTL extension : ttl key'); 46is($s->in_units('seconds'),3600,'TTL extension : value'); 47 48$R2=''; 49my $cs=$dri->local_object('contactset'); 50$cs->set($dri->local_object('contact')->srid('C11480'),'registrant'); 51$cs->set($dri->local_object('contact')->srid('C11480'),'tech'); 52$rc=$dri->domain_create('example2.eu.com',{pure_create=>1,contact=>$cs,auth=>{pw=>'2fooBAR'},ttl=>DateTime::Duration->new(seconds => 300)}); 53is_string($R1,$E1.'<command><create><domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"><domain:name>example2.eu.com</domain:name><domain:registrant>C11480</domain:registrant><domain:contact type="tech">C11480</domain:contact><domain:authInfo><domain:pw>2fooBAR</domain:pw></domain:authInfo></domain:create></create><extension><ttl:create xmlns:ttl="urn:centralnic:params:xml:ns:ttl-1.0" xsi:schemaLocation="urn:centralnic:params:xml:ns:ttl-1.0 ttl-1.0.xsd"><ttl:secs>300</ttl:secs></ttl:create></extension><clTRID>ABC-12345</clTRID></command>'.$E2,'TTL extension : domain_create build with DateTime::Duration'); 54 55 56$R2=''; 57$rc=$dri->domain_create('example3.eu.com',{pure_create=>1,contact=>$cs,auth=>{pw=>'2fooBAR'},ttl=>600}); 58is_string($R1,$E1.'<command><create><domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"><domain:name>example3.eu.com</domain:name><domain:registrant>C11480</domain:registrant><domain:contact type="tech">C11480</domain:contact><domain:authInfo><domain:pw>2fooBAR</domain:pw></domain:authInfo></domain:create></create><extension><ttl:create xmlns:ttl="urn:centralnic:params:xml:ns:ttl-1.0" xsi:schemaLocation="urn:centralnic:params:xml:ns:ttl-1.0 ttl-1.0.xsd"><ttl:secs>600</ttl:secs></ttl:create></extension><clTRID>ABC-12345</clTRID></command>'.$E2,'TTL extension : domain_create build with integer'); 59 60$R2=''; 61my $toc=$dri->local_object('changes'); 62$toc->set('ttl',300); 63$rc=$dri->domain_update('example4.eu.com',$toc); 64is_string($R1,$E1.'<command><update><domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"><domain:name>example4.eu.com</domain:name></domain:update></update><extension><ttl:update xmlns:ttl="urn:centralnic:params:xml:ns:ttl-1.0" xsi:schemaLocation="urn:centralnic:params:xml:ns:ttl-1.0 ttl-1.0.xsd"><ttl:secs>300</ttl:secs></ttl:update></extension><clTRID>ABC-12345</clTRID></command>'.$E2,'TTL extension : domain_update build'); 65 66#################################################################################################### 67## Web Forwarding extension 68 69$R2=$E1.'<response>'.r().'<resData><domain:infData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"><domain:name>example5.eu.com</domain:name><domain:roid>CNIC-DO302520</domain:roid><domain:status s="ok"/><domain:registrant>C11480</domain:registrant><domain:contact type="tech">C11480</domain:contact><domain:clID>C11480</domain:clID><domain:crDate>1995-01-01T00:00:00.0Z</domain:crDate><domain:exDate>2020-01-01T23:59:59.0Z</domain:exDate><domain:upDate>2005-05-14T11:15:19.0Z</domain:upDate></domain:infData></resData><extension><wf:infData xmlns:wf="urn:centralnic:params:xml:ns:wf-1.0" xsi:schemaLocation="urn:centralnic:params:xml:ns:wf-1.0 wf-1.0.xsd"><wf:url>http://www.example.com/</wf:url></wf:infData></extension>'.$TRID.'</response>'.$E2; 70$rc=$dri->domain_info('example5.eu.com'); 71$s=$dri->get_info('web_forwarding'); 72is($s,'http://www.example.com/','WebForwarding extension : value'); 73 74$R2=''; 75$cs=$dri->local_object('contactset'); 76$cs->set($dri->local_object('contact')->srid('C11480'),'registrant'); 77$cs->set($dri->local_object('contact')->srid('C11480'),'tech'); 78$rc=$dri->domain_create('example6.eu.com',{pure_create=>1,contact=>$cs,auth=>{pw=>'2fooBAR'},web_forwarding=>'http://www.example.com/'}); 79is_string($R1,$E1.'<command><create><domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"><domain:name>example6.eu.com</domain:name><domain:registrant>C11480</domain:registrant><domain:contact type="tech">C11480</domain:contact><domain:authInfo><domain:pw>2fooBAR</domain:pw></domain:authInfo></domain:create></create><extension><wf:create xmlns:wf="urn:centralnic:params:xml:ns:wf-1.0" xsi:schemaLocation="urn:centralnic:params:xml:ns:wf-1.0 wf-1.0.xsd"><wf:url>http://www.example.com/</wf:url></wf:create></extension><clTRID>ABC-12345</clTRID></command>'.$E2,'WebForwarding extension : domain_create build'); 80 81$R2=''; 82$toc=$dri->local_object('changes'); 83$toc->set('web_forwarding','http://www.example.com/'); 84$rc=$dri->domain_update('example7.eu.com',$toc); 85is_string($R1,$E1.'<command><update><domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"><domain:name>example7.eu.com</domain:name></domain:update></update><extension><wf:update xmlns:wf="urn:centralnic:params:xml:ns:wf-1.0" xsi:schemaLocation="urn:centralnic:params:xml:ns:wf-1.0 wf-1.0.xsd"><wf:url>http://www.example.com/</wf:url></wf:update></extension><clTRID>ABC-12345</clTRID></command>'.$E2,'WebForwarding extension: domain_update build'); 86 87$R2=''; 88$toc=$dri->local_object('changes'); 89$toc->set('web_forwarding',''); 90$rc=$dri->domain_update('example8.eu.com',$toc); 91is_string($R1,$E1.'<command><update><domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"><domain:name>example8.eu.com</domain:name></domain:update></update><extension><wf:update xmlns:wf="urn:centralnic:params:xml:ns:wf-1.0" xsi:schemaLocation="urn:centralnic:params:xml:ns:wf-1.0 wf-1.0.xsd"><wf:url/></wf:update></extension><clTRID>ABC-12345</clTRID></command>'.$E2,'WebForwarding extension: domain_update build with empty url'); 92 93#################################################################################################### 94## Release extension 95 96 97$R2=$E1.'<response>'.r(1001,'Command completed successfully.').'<resData><domain:trnData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"><domain:name>example9.eu.com</domain:name><domain:trStatus>approved</domain:trStatus></domain:trnData></resData>'.$TRID.'</response>'.$E2; 98$rc=$dri->domain_release('example9.eu.com',{clID=>'H12345'}); 99is_string($R1,$E1.'<command><transfer op="release"><domain:transfer xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"><domain:name>example9.eu.com</domain:name><domain:clID>H12345</domain:clID></domain:transfer></transfer><clTRID>ABC-12345</clTRID></command>'.$E2,'Release extension: domain_release build'); 100is($rc->is_success(),1,'Release extension: domain_release is_success'); 101is($rc->is_pending(),1,'Release extension: domain_release is_pending'); 102is($dri->get_info('trStatus'),'approved','Release extension: domain_release get_info(trStatus)'); 103 104#################################################################################################### 105exit 0; 106 107sub r 108{ 109 my ($c,$m)=@_; 110 return '<result code="'.($c || 1000).'"><msg>'.($m || 'Command completed successfully').'</msg></result>'; 111} 112