Re: [Freeipa-devel] [PATCH] 143 Fix dnszone-add name_from_ip server validation

2011-10-11 Thread Martin Kosek
On Tue, 2011-10-11 at 09:10 -0400, Rob Crittenden wrote:
> Martin Kosek wrote:
> > On Tue, 2011-10-11 at 11:03 +0200, Martin Kosek wrote:
> >> Based mainly on Rob's fix proposed in Trac.
> >> ---
> >> Ticket 1627 contained a (temporary hack-ish) fix for dnszone-add
> >> name_from_ip validation which works fine for CLI. However, when
> >> the command is not proceeded via CLI and sent directly to the
> >> RPC server, the server throws Internal Server Error.
> >>
> >> Make sure that the server returns a reasonable error.
> >>
> >> https://fedorahosted.org/freeipa/ticket/1941
> >>
> >
> > We miss a test for name_from_ip parameter. I added 2 unit cases that
> > verify this option works + reports a ValidationError when the IP address
> > is wrong.
> >
> > Martin
> 
> ack
> 

Pushed to master, ipa-2-1.

Martin

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


Re: [Freeipa-devel] [PATCH] 143 Fix dnszone-add name_from_ip server validation

2011-10-11 Thread Rob Crittenden

Martin Kosek wrote:

On Tue, 2011-10-11 at 11:03 +0200, Martin Kosek wrote:

Based mainly on Rob's fix proposed in Trac.
---
Ticket 1627 contained a (temporary hack-ish) fix for dnszone-add
name_from_ip validation which works fine for CLI. However, when
the command is not proceeded via CLI and sent directly to the
RPC server, the server throws Internal Server Error.

Make sure that the server returns a reasonable error.

https://fedorahosted.org/freeipa/ticket/1941



We miss a test for name_from_ip parameter. I added 2 unit cases that
verify this option works + reports a ValidationError when the IP address
is wrong.

Martin


ack

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


Re: [Freeipa-devel] [PATCH] 143 Fix dnszone-add name_from_ip server validation

2011-10-11 Thread Martin Kosek
On Tue, 2011-10-11 at 11:03 +0200, Martin Kosek wrote:
> Based mainly on Rob's fix proposed in Trac.
> ---
> Ticket 1627 contained a (temporary hack-ish) fix for dnszone-add
> name_from_ip validation which works fine for CLI. However, when
> the command is not proceeded via CLI and sent directly to the
> RPC server, the server throws Internal Server Error.
> 
> Make sure that the server returns a reasonable error.
> 
> https://fedorahosted.org/freeipa/ticket/1941
> 

We miss a test for name_from_ip parameter. I added 2 unit cases that
verify this option works + reports a ValidationError when the IP address
is wrong.

Martin
>From d37bfdcd88bafb27f619ca012d7111611f25f860 Mon Sep 17 00:00:00 2001
From: Martin Kosek 
Date: Tue, 11 Oct 2011 10:54:34 +0200
Subject: [PATCH] Fix dnszone-add name_from_ip server validation

Ticket 1627 contained a (temporary hack-ish) fix for dnszone-add
name_from_ip validation which works fine for CLI. However, when
the command is not proceeded via CLI and sent directly to the
RPC server, the server throws Internal Server Error.

Make sure that the server returns a reasonable error. Also implement
2 unit cases testing this option

https://fedorahosted.org/freeipa/ticket/1941
---
 ipaserver/rpcserver.py   |9 +-
 tests/test_xmlrpc/test_dns_plugin.py |   48 ++
 2 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/ipaserver/rpcserver.py b/ipaserver/rpcserver.py
index 39cdbcc7f353c1d0a01d10ff442a9bf0c66c3df9..35a10926292f01933825772edb852f34ef164619 100644
--- a/ipaserver/rpcserver.py
+++ b/ipaserver/rpcserver.py
@@ -231,7 +231,14 @@ class WSGIExecutioner(Executioner):
 finally:
 os.environ['LANG'] = lang
 if name:
-params = self.Command[name].args_options_2_params(*args, **options)
+try:
+params = self.Command[name].args_options_2_params(*args, **options)
+except Exception, e:
+self.info(
+   'exception %s caught when converting options: %s', e.__class__.__name__, str(e)
+)
+# get at least some context of what is going on
+params = options
 if error:
 self.info('%s: %s(%s): %s', context.principal, name, ', '.join(self.Command[name]._repr_iter(**params)), e.__class__.__name__)
 else:
diff --git a/tests/test_xmlrpc/test_dns_plugin.py b/tests/test_xmlrpc/test_dns_plugin.py
index f9bce61d9193e72b1a0b6d9b092be6e50251e7fc..679f285d5f053d26c46a400498c51e7bf889eefe 100644
--- a/tests/test_xmlrpc/test_dns_plugin.py
+++ b/tests/test_xmlrpc/test_dns_plugin.py
@@ -29,6 +29,7 @@ from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid
 dnszone1 = u'dnszone.test'
 dnszone2 = u'dnszone2.test'
 revdnszone1 = u'15.142.80.in-addr.arpa.'
+revdnszone1_ip = u'80.142.15.0/24'
 dnsres1 = u'testdnsres'
 
 class test_dns(Declarative):
@@ -551,6 +552,53 @@ class test_dns(Declarative):
 
 
 dict(
+desc='Try to create a reverse zone from invalid IP',
+command=(
+'dnszone_add', [], {
+'name_from_ip': u'foo',
+'idnssoamname': u'ns1.%s' % dnszone1,
+'idnssoarname': u'root.%s' % dnszone1,
+'ip_address' : u'1.2.3.4',
+}
+),
+expected=errors.ValidationError(name='name_from_ip', error='invalid format'),
+),
+
+
+dict(
+desc='Create reverse from IP %s zone using name_from_ip option' % revdnszone1_ip,
+command=(
+'dnszone_add', [], {
+'name_from_ip': revdnszone1_ip,
+'idnssoamname': u'ns1.%s' % dnszone1,
+'idnssoarname': u'root.%s' % dnszone1,
+'ip_address' : u'1.2.3.4',
+}
+),
+expected={
+'value': revdnszone1,
+'summary': None,
+'result': {
+'dn': lambda x: DN(x) == \
+DN(('idnsname',revdnszone1),('cn','dns'),api.env.basedn),
+'idnsname': [revdnszone1],
+'idnszoneactive': [u'TRUE'],
+'idnssoamname': [u'ns1.%s.' % dnszone1],
+'nsrecord': [u'ns1.%s.' % dnszone1],
+'idnssoarname': [u'root.%s.' % dnszone1],
+'idnssoaserial': [fuzzy_digits],
+'idnssoarefresh': [fuzzy_digits],
+'idnssoaretry': [fuzzy_digits],
+'idnssoaexpire': [fuzzy_digits],
+'idnssoaminimum': [fuzzy_digits],
+'idnsallowdynupdate': [u'FALSE'],
+'objectclass': [u'top', u'idnsrecord', u'idnszone'],
+},
+},
+),
+
+
+dict(
 desc='Delete zone %r' % dnszone1,
 command=('