Update tests to deal with GSSCommand objects now taking only the 'argument' part...
authorMark Donnelly <mark@painless-security.com>
Thu, 20 Nov 2014 19:44:53 +0000 (14:44 -0500)
committerMark Donnelly <mark@painless-security.com>
Thu, 20 Nov 2014 19:44:53 +0000 (14:44 -0500)
json_gssapi/src/commands/GSSAcquireCred.cpp
json_gssapi/test/GSSAcquireCredTest.cpp
json_gssapi/test/GSSGetMicTest.cpp
json_gssapi/test/GSSPseudoRandomTest.cpp
json_gssapi/test/GSSUnwrapTest.cpp
json_gssapi/test/GSSWrapTest.cpp

index 037b8c6..fd173f0 100644 (file)
@@ -82,7 +82,7 @@ bool GSSAcquireCred::loadParameters(JSONObject *params)
   
   /* Main processing */
   // Easy stuff(*params)
-  this->time_req = (*params)["arguments"]["time_req"].integer();
+  this->time_req = (*params)["time_req"].integer();
 
   /**************
    * cred_usage *
index 358b9f2..e43645b 100644 (file)
@@ -9,6 +9,7 @@
 #include "GSSAcquireCred.h"
 #include "command_mocks/MockAcquireCred.h"
 #include <datamodel/GSSName.h>
+#include <cache/GSSNameCache.h>
 #include <gssapi.h>
 #include <stdexcept>
 
@@ -77,16 +78,35 @@ void GSSAcquireCredTest::testConstructorWithJSONObject()
   gss_cred_usage_t cred_usage = 2;
   GSSOID mech( (char *)"{ 1 2 840 113554 1 2 1 4 }" );
   std::stringstream input;
+  char *desired_name = (char *)"HTTP@localhost\0";
+  GSSName desired;
+  OM_uint32 major, minor;
+  gss_name_t des;
+  
+  
+  major = gss_import_name(&minor, GSSBuffer(desired_name).toGss(), GSS_C_NT_HOSTBASED_SERVICE, &des);
+  if (GSS_ERROR(major))
+  {
+    OM_uint32 min, context;
+    gss_buffer_desc buf;
+    
+    std::cout << "Error in importing name." << std::endl;
+    gss_display_status(&min, major, GSS_C_GSS_CODE, GSS_C_NT_HOSTBASED_SERVICE, &context, &buf);
+    std::cout << "  message: " << (char *)buf.value << std::endl;
+  }
+  CPPUNIT_ASSERT_MESSAGE(
+    "Could not generate a name to test GSSCreateSecContext JSON parsing.",
+    !GSS_ERROR(major)
+  );
+  desired.setValue(des);
+  std::string key = GSSNameCache::instance()->store(desired);
 
   // The JSON string
   input << 
-  "{\"method\"   : \"gss_acquire_cred\", \
-    \"arguments\": \
-       {\"desired_name\" : \"#################\", \
-        \"time_req\"     : " << time_req << ", \
-        \"cred_usage\"   : " << cred_usage << ", \
-        \"desired_mechs\": [\"" << mech.toString() << "\"] \
-       } \
+  "{\"desired_name\" : \"" << key << "\", \
+    \"time_req\"     : " << time_req << ", \
+    \"cred_usage\"   : " << cred_usage << ", \
+    \"desired_mechs\": [\"" << mech.toString() << "\"] \
    }";
   
   // The JSON itself
@@ -113,7 +133,7 @@ void GSSAcquireCredTest::testConstructorWithJSONObject()
     cmd.getCredUsage()
   );
   
-  json["arguments"].set( "cred_usage", "GSS_C_INITIATE" );
+  json.set( "cred_usage", "GSS_C_INITIATE" );
   cmd.loadParameters(&json);
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "GSSAcquireCred's cred_usage was not loaded correctly",
@@ -122,7 +142,7 @@ void GSSAcquireCredTest::testConstructorWithJSONObject()
   );
   
   // CPPUNIT_ASSERT_THROW(expression, exception);
-  json["arguments"].set( "cred_usage", "GSS_C_INITIATOR" );
+  json.set( "cred_usage", "GSS_C_INITIATOR" );
   CPPUNIT_ASSERT_THROW_MESSAGE(
     "GSSAcquireCred's JSON parsing is admitting invalid strings.", 
     cmd.loadParameters(&json), 
@@ -251,41 +271,35 @@ void GSSAcquireCredTest::testJSONMarshal()
   
 //   std::cout << "\n" << result->dump() << "\n";
   
-  CPPUNIT_ASSERT_EQUAL_MESSAGE(
-    "The command name is incorrect",
-    std::string("gss_acquire_cred"),
-    std::string( (*result)["command"].string() )
-  );
-  
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The return value was reported incorrectly",
     (int)MockAcquireCred::retVal,
-    (int)( (*result)["return_values"]["major_status"].integer() )
+    (int)( (*result)["major_status"].integer() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The minor_status value was reported incorrectly",
     (int)MockAcquireCred::minor_status,
-    (int)( (*result)["return_values"]["minor_status"].integer() )
+    (int)( (*result)["minor_status"].integer() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The gss_name was reported incorrectly",
     std::string("{ 1 2 3 4 }"),
-    std::string( (*result)["return_values"]["actual_mechs"][(size_t)0].string() )
+    std::string( (*result)["actual_mechs"][(size_t)0].string() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The gss_name was reported incorrectly",
     std::string("{ 1 5 6 7 8 }"),
-    std::string( (*result)["return_values"]["actual_mechs"][(size_t)1].string() )
+    std::string( (*result)["actual_mechs"][(size_t)1].string() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The minor_status value was reported incorrectly",
     (int)MockAcquireCred::time_rec,
-    (int)( (*result)["return_values"]["time_rec"].integer() )
+    (int)( (*result)["time_rec"].integer() )
   );
   
   
index 1875b36..1273761 100644 (file)
@@ -135,14 +135,11 @@ void GSSGetMicTest::testConstructorWithJSONObject()
   GSSContext context((gss_ctx_id_t)rand(), true);
   std::string key = GSSContextCache::instance()->store(context);
 
-  std::string input = "{\"method\": \"gss_get_mic\", \
-    \"arguments\": \
-    { \
+  std::string input = "{ \
          \"context_handle\": \"" + key + "\", \
          \"qop_req\": \"GSS_C_QOP_DEFAULT\", \
          \"input_message\": \"mary had a little lamb\" \
-    }\
-  }";
+    }";
   json_error_t jsonErr;
   JSONObject json = JSONObject::load(input.c_str(), 0, &jsonErr);
   
@@ -212,28 +209,21 @@ void GSSGetMicTest::testJSONMarshal()
 //   std::cout << "\nGSSGetMic JSON: \n" << result->dump() << "\n";
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
-    "The command name is incorrect",
-    std::string("gss_get_mic"),
-    std::string( (*result)["command"].string() )
-  );
-  
-  
-  CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The return value was reported incorrectly",
     (int)MockGetMic::retVal,
-    (int)( (*result)["return_values"]["major_status"].integer() )
+    (int)( (*result)["major_status"].integer() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The minor_status value was reported incorrectly",
     (int)MockGetMic::minor_status,
-    (int)( (*result)["return_values"]["minor_status"].integer() )
+    (int)( (*result)["minor_status"].integer() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The output message was reported incorrectly",
     output,
-    std::string( (*result)["return_values"]["output_token"].string() )
+    std::string( (*result)["output_token"].string() )
   );
   
   
index e38ab49..d28b8fd 100644 (file)
@@ -189,15 +189,12 @@ void GSSPseudoRandomTest::testConstructorWithJSONObject()
   GSSContext context( (gss_ctx_id_t)rand(), true );
   std::string key = GSSContextCache::instance()->store(context);
   
-  std::string input = "{\"method\": \"gss_pseudo_random\", \
-    \"arguments\": \
-    { \
+  std::string input = "{ \
          \"context_handle\": \"" + key + "\", \
          \"prf_key\": 1234567890, \
          \"prf_in\": \"mary had a little lamb\", \
          \"desired_output_len\": 256 \
-    }\
-  }";
+    }";
   json_error_t jsonErr;
   JSONObject json = JSONObject::load(input.c_str(), 0, &jsonErr);
   
@@ -267,27 +264,21 @@ void GSSPseudoRandomTest::testJSONMarshal()
 //   std::cout << "\nGSSWrap JSON: \n" << result->dump() << "\n";
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
-    "The command name is incorrect",
-    std::string("gss_pseudo_random"),
-    std::string( (*result)["command"].string() )
-  );
-  
-  CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The return value was reported incorrectly",
     (int)MockPseudoRandom::retVal,
-    (int)( (*result)["return_values"]["major_status"].integer() )
+    (int)( (*result)["major_status"].integer() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The minor_status value was reported incorrectly",
     (int)MockPseudoRandom::minor_status,
-    (int)( (*result)["return_values"]["minor_status"].integer() )
+    (int)( (*result)["minor_status"].integer() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The random bytes were reported incorrectly",
     MockPseudoRandom::outputMessageBuffer.toString(),
-    std::string( (*result)["return_values"]["random_bytes"].string() )
+    std::string( (*result)["random_bytes"].string() )
   );
   
   
index 7b26008..de0d9a1 100644 (file)
@@ -145,13 +145,10 @@ void GSSUnwrapTest::testConstructorWithJSONObject()
   /* Variables */
   GSSContext context((gss_ctx_id_t)rand(), true);
   std::string key = GSSContextCache::instance()->store(context);
-  std::string input = "{\"method\": \"gss_wrap\", \
-    \"arguments\": \
-    { \
+  std::string input = "{ \
          \"context_handle\": \"" + key + "\", \
          \"input_message\": \"mary had a little lamb\" \
-    }\
-  }";
+    }";
   json_error_t jsonErr;
   JSONObject json = JSONObject::load(input.c_str(), 0, &jsonErr);
   
@@ -202,35 +199,29 @@ void GSSUnwrapTest::testJSONMarshal()
   result = cmd.toJSON();
 //   std::cout << "\nGSSUnwrap JSON: \n" << result->dump() << "\n";
   
-  CPPUNIT_ASSERT_EQUAL_MESSAGE(
-    "The command name is incorrect",
-    std::string("gss_wrap"),
-    std::string( (*result)["command"].string() )
-  );
-  
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The return value was reported incorrectly",
     (int)MockUnwrap::retVal,
-    (int)( (*result)["return_values"]["major_status"].integer() )
+    (int)( (*result)["major_status"].integer() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The minor_status value was reported incorrectly",
     (int)MockUnwrap::minor_status,
-    (int)( (*result)["return_values"]["minor_status"].integer() )
+    (int)( (*result)["minor_status"].integer() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The output message was reported incorrectly",
     MockUnwrap::outputMessageBuffer.toString(),
-    std::string( (*result)["return_values"]["output_message"].string() )
+    std::string( (*result)["output_message"].string() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The minor_status value was reported incorrectly",
     (int)qopState,
-    (int)( (*result)["return_values"]["qop_state"].integer() )
+    (int)( (*result)["qop_state"].integer() )
   );
   
   
index 50dbf2d..0f170e1 100644 (file)
@@ -167,15 +167,12 @@ void GSSWrapTest::testConstructorWithJSONObject()
   GSSContext context( (gss_ctx_id_t)rand(), true );
   std::string key = GSSContextCache::instance()->store(context);
   
-  std::string input = "{\"method\": \"gss_wrap\", \
-    \"arguments\": \
-    { \
+  std::string input = "{ \
          \"context_handle\": \"" + key + "\", \
          \"conf_req\": \"TRUE\", \
          \"qop_req\": \"GSS_C_QOP_DEFAULT\", \
          \"input_message\": \"mary had a little lamb\" \
-    }\
-  }";
+    }";
   json_error_t jsonErr;
   JSONObject json = JSONObject::load(input.c_str(), 0, &jsonErr);
   
@@ -248,29 +245,23 @@ void GSSWrapTest::testJSONMarshal()
   result = cmd.toJSON();
 //   std::cout << "\nGSSWrap JSON: \n" << result->dump() << "\n";
   
-  CPPUNIT_ASSERT_EQUAL_MESSAGE(
-    "The command name is incorrect",
-    std::string("gss_wrap"),
-    std::string( (*result)["command"].string() )
-  );
-  
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The return value was reported incorrectly",
     (int)MockWrap::retVal,
-    (int)( (*result)["return_values"]["major_status"].integer() )
+    (int)( (*result)["major_status"].integer() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The minor_status value was reported incorrectly",
     (int)MockWrap::minor_status,
-    (int)( (*result)["return_values"]["minor_status"].integer() )
+    (int)( (*result)["minor_status"].integer() )
   );
   
   CPPUNIT_ASSERT_EQUAL_MESSAGE(
     "The output message was reported incorrectly",
     MockWrap::outputMessageBuffer.toString(),
-    std::string( (*result)["return_values"]["output_message"].string() )
+    std::string( (*result)["output_message"].string() )
   );