|
@@ -111,6 +111,7 @@ protected:
|
|
|
|
|
|
boost::scoped_ptr<TSIGContext> tsig_ctx;
|
|
|
boost::scoped_ptr<TSIGContext> tsig_verify_ctx;
|
|
|
+ TSIGKeyRing keyring;
|
|
|
const uint16_t qid;
|
|
|
const Name test_name;
|
|
|
const RRClass test_class;
|
|
@@ -199,6 +200,33 @@ TEST_F(TSIGTest, initialState) {
|
|
|
EXPECT_EQ(TSIGError(Rcode::NOERROR()), tsig_ctx->getError());
|
|
|
}
|
|
|
|
|
|
+TEST_F(TSIGTest, constructFromKeyRing) {
|
|
|
+ // Construct a TSIG context with an empty key ring. Key shouldn't be
|
|
|
+ // found, and the BAD_KEY error should be recorded.
|
|
|
+ TSIGContext ctx1(test_name, TSIGKey::HMACMD5_NAME(), keyring);
|
|
|
+ EXPECT_EQ(TSIGContext::INIT, ctx1.getState());
|
|
|
+ EXPECT_EQ(TSIGError::BAD_KEY(), ctx1.getError());
|
|
|
+
|
|
|
+ // Add a matching key (we don't use the secret so leave it empty), and
|
|
|
+ // construct it again. This time it should be constructed with a valid
|
|
|
+ // key.
|
|
|
+ keyring.add(TSIGKey(test_name, TSIGKey::HMACMD5_NAME(), NULL, 0));
|
|
|
+ TSIGContext ctx2(test_name, TSIGKey::HMACMD5_NAME(), keyring);
|
|
|
+ EXPECT_EQ(TSIGContext::INIT, ctx2.getState());
|
|
|
+ EXPECT_EQ(TSIGError::NOERROR(), ctx2.getError());
|
|
|
+
|
|
|
+ // Similar to the first case except that the key ring isn't empty but
|
|
|
+ // it doesn't contain a matching key.
|
|
|
+ TSIGContext ctx3(test_name, TSIGKey::HMACSHA1_NAME(), keyring);
|
|
|
+ EXPECT_EQ(TSIGContext::INIT, ctx3.getState());
|
|
|
+ EXPECT_EQ(TSIGError::BAD_KEY(), ctx3.getError());
|
|
|
+
|
|
|
+ TSIGContext ctx4(Name("different-key.example"), TSIGKey::HMACMD5_NAME(),
|
|
|
+ keyring);
|
|
|
+ EXPECT_EQ(TSIGContext::INIT, ctx4.getState());
|
|
|
+ EXPECT_EQ(TSIGError::BAD_KEY(), ctx4.getError());
|
|
|
+}
|
|
|
+
|
|
|
// Example output generated by
|
|
|
// "dig -y www.example.com:SFuWd/q99SzF8Yzd1QbB9g== www.example.com
|
|
|
// QID: 0x2d65
|