Browse Source

[1455] handling part and response building

Jelte Jansen 13 years ago
parent
commit
005a08df42

+ 8 - 0
src/lib/python/isc/ddns/libddns_messages.mes

@@ -39,3 +39,11 @@ possible, you may want to check the implementation or configuration of
 those clients to suppress the requests.  As specified in Section 3.1
 of RFC2136, the receiving server will return a response with an RCODE
 of NOTAUTH.
+
+% LIBDDNS_UPDATE_PREREQUISITE_FAILED prerequisite failed in update update client %1 for zone %2: result code %3
+The handling of the prerequisite section (RFC2136 Section 3.2) found
+that one of the prerequisites was not satisfied. The result code
+should give more information on what prerequisite type failed.
+If the result code is FORMERR, the prerequisite section was not well-formed.
+An error response with the given result code is sent back to the client.
+

+ 9 - 4
src/lib/python/isc/ddns/session.py

@@ -123,9 +123,14 @@ class UpdateSession:
         try:
             datasrc_client, zname, zclass = self.__get_update_zone()
             # conceptual code that would follow
-            prereq_result = self.__check_prerequisites(datasrc_client, zname, zclass)
-            if prereq_result != UPDATE_SUCCESS:
-                return prereq_result, zname, zclass
+            prereq_result = self.__check_prerequisites(datasrc_client,
+                                                       zname, zclass)
+            if prereq_result != Rcode.NOERROR():
+                logger.info(LIBDDNS_UPDATE_PREREQUISITE_FAILED,
+                            ClientFormatter(self.__client_addr),
+                            zname, prereq_result)
+                self.__make_response(prereq_result)
+                return UPDATE_ERROR, zname, zclass
             # self.__check_update_acl()
             # self.__do_update()
             # self.__make_response(Rcode.NOERROR())
@@ -247,7 +252,7 @@ class UpdateSession:
     def __check_prerequisite_name_not_in_use(self, datasrc_client, rrset):
         '''Check whether the name of the given RRset is not in use (i.e. does
            not exist at all, or is an empty nonterminal.
-           RFC2136 Section 2.4.5
+           RFC2136 Section 2.4.5.
         '''
         return not self.__check_prerequisite_name_in_use(datasrc_client, rrset)
 

+ 13 - 1
src/lib/python/isc/ddns/tests/session_tests.py

@@ -477,12 +477,24 @@ class SessionTest(unittest.TestCase):
            returns the Rcode specified in 'expected'.'''
         msg_data, msg = create_update_msg([TEST_ZONE_RECORD],
                                           prerequisites)
-        session = UpdateSession(msg, msg_data, TEST_CLIENT4, None)
+        zconfig = ZoneConfig([], TEST_RRCLASS, self.__datasrc_client)
+        session = UpdateSession(msg, msg_data, TEST_CLIENT4, zconfig)
         # compare the to_text output of the rcodes (nicer error messages)
+        # This call itself should also be done by handle(),
+        # but just for better failures, it is first called on itw own
         self.assertEqual(expected.to_text(),
             session._UpdateSession__check_prerequisites(self.__datasrc_client,
                                                         TEST_ZONE_NAME,
                                                         TEST_RRCLASS).to_text())
+        # Now see if handle finds the same result
+        (result, _, _) = session.handle()
+        self.assertEqual(expected,
+                         session._UpdateSession__message.get_rcode())
+        # And that the result looks right
+        if expected == Rcode.NOERROR():
+            self.assertEqual(UPDATE_SUCCESS, result)
+        else:
+            self.assertEqual(UPDATE_ERROR, result)
 
     def test_check_prerequisites(self):
         # This test checks if the actual prerequisite-type-specific