Browse Source

[2157] throw InvalidParameter instead of assert, updated doxygen

Yoshitaka Aharen 12 years ago
parent
commit
bfad7cb107
2 changed files with 26 additions and 3 deletions
  1. 8 3
      src/bin/auth/statistics.h
  2. 18 0
      src/bin/auth/tests/statistics_unittest.cc.pre

+ 8 - 3
src/bin/auth/statistics.h

@@ -175,10 +175,15 @@ public:
     /// \brief Set TSIG attributes of the request.
     /// \brief Set TSIG attributes of the request.
     ///
     ///
     /// \param signed_tsig true if the request is signed with TSIG
     /// \param signed_tsig true if the request is signed with TSIG
-    /// \param badsig true if the signature of the request is bad
-    /// \throw None
+    /// \param badsig true if the signature of the request is bad; it must not
+    //                be true unless signed_tsig is true
+    /// \throw isc::InvalidParameter if badsig is true though the request is
+    ///                              not signed
     void setRequestTSIG(const bool signed_tsig, const bool badsig) {
     void setRequestTSIG(const bool signed_tsig, const bool badsig) {
-        assert(!(!signed_tsig && badsig));
+        if (!signed_tsig && badsig) {
+            isc_throw(isc::InvalidParameter, "Message is not signed but badsig"
+                                             " is true");
+        }
         bit_attributes_[REQ_TSIG_SIGNED] = signed_tsig;
         bit_attributes_[REQ_TSIG_SIGNED] = signed_tsig;
         bit_attributes_[REQ_BADSIG] = badsig;
         bit_attributes_[REQ_BADSIG] = badsig;
     }
     }

+ 18 - 0
src/bin/auth/tests/statistics_unittest.cc.pre

@@ -75,6 +75,24 @@ TEST_F(CountersTest, invalidOperationForGetRequestOpCode) {
     EXPECT_EQ(Opcode::QUERY(), msgattrs.getRequestOpCode().get());
     EXPECT_EQ(Opcode::QUERY(), msgattrs.getRequestOpCode().get());
 }
 }
 
 
+TEST_F(CountersTest, invalidParameterForSetRequestTSIG) {
+    MessageAttributes msgattrs;
+
+    // These patterns should not throw:
+    //      request signature  badsig
+    //     --------------------------
+    //      (none)             false 
+    //      TSIG               false 
+    //      TSIG               true  
+    EXPECT_NO_THROW(msgattrs.setRequestTSIG(false, false));
+    EXPECT_NO_THROW(msgattrs.setRequestTSIG(true, false));
+    EXPECT_NO_THROW(msgattrs.setRequestTSIG(true, true));
+
+    // It should throw isc::InvalidParameter if a message is not signed but
+    // badsig is true
+    EXPECT_THROW(msgattrs.setRequestTSIG(false, true), isc::InvalidParameter);
+}
+
 TEST_F(CountersTest, incrementResponse) {
 TEST_F(CountersTest, incrementResponse) {
     Message response(Message::RENDER);
     Message response(Message::RENDER);
     MessageAttributes msgattrs;
     MessageAttributes msgattrs;