GSS import name working
authorMark Donnelly <mark@painless-security.com>
Wed, 30 Apr 2014 20:40:25 +0000 (16:40 -0400)
committerMark Donnelly <mark@painless-security.com>
Wed, 30 Apr 2014 20:40:25 +0000 (16:40 -0400)
.gitignore
json_gssapi/src/GSSImportName.cpp
json_gssapi/src/datamodel/GSSName.cpp
json_gssapi/src/datamodel/GSSName.h
json_gssapi/test/GSSImportNameTest.cpp

index a0028da..b6c2844 100644 (file)
@@ -81,4 +81,4 @@ Doxyfile
 json_gssapi/build
 json_gssapi/debug
 json_gssapi/manual
-test/
\ No newline at end of file
+./test/
\ No newline at end of file
index feb9127..2cf6a42 100644 (file)
 void GSSImportName::execute()
 {
   this->outputName = GSSName(inputName, inputNameType, function);
+  this->retVal = this->outputName.getMajorStatus();
+  this->minor_status = this->outputName.getMinorStatus();
+  this->outputName.setKey("constant for now");
 }
 
 JSONObject *GSSImportName::toJSON()
 {
-  return new JSONObject();
+  /* Variables */
+  JSONObject *ret = new JSONObject();
+  JSONObject *values = new JSONObject();
+  
+  /* Error checking */
+  
+  /* Setup */
+  
+  /* Main */
+  values->set("major_status", this->retVal);
+  values->set("minor_status", this->minor_status);
+  values->set("gss_name", this->outputName.getKey().c_str() );
+  ret->set("command", "gss_import_name");
+  ret->set("return_values", *values);
+  
+  /* Cleanup */
+  
+  /* Return */
+  return(ret);
 }
 
 GSSImportName::GSSImportName(JSONObject *params, gss_imp_name_type fn) : GSSCommand(params)
index 9260bf4..a009c64 100644 (file)
 void GSSName::init(const GSSBuffer namestr, GSSOID name_type, gss_imp_name_type fn)
 {
   /* Variables */
-  OM_uint32 major, minor;
   /* Error checking */
   /* Setup */
   /* Main */ 
-  major = fn(&minor, namestr.toGss(), name_type.toGss(), &name);
-  if ( GSS_ERROR(major) )
+  this->major_status = fn(&(this->minor_status), namestr.toGss(), name_type.toGss(), &name);
+  if ( GSS_ERROR(this->major_status) )
   {
     std::string errMsg;
     errMsg += "Cannot import name: ";
     errMsg += namestr.toString();
-    throw GSSException(errMsg.c_str(), major, minor, name_type.toGss());
+    throw GSSException(errMsg.c_str(), this->major_status, this->minor_status, name_type.toGss());
   }
   
   /* Cleanup */
index 32f1908..05fe2a1 100644 (file)
@@ -62,10 +62,17 @@ public:
   std::string toString();
   
   bool setValue(gss_name_t newName);
+  bool setKey(std::string key) { this->hashKey = key; }
+  std::string getKey() const { return this->hashKey; }
+  
+  OM_uint32 getMajorStatus() const { return this->major_status; }
+  OM_uint32 getMinorStatus() const { return this->minor_status; }
   
 private:
+  OM_uint32 major_status, minor_status;
   gss_name_t name;
   gss_imp_name_type function;
+  std::string hashKey;
   
   void init(const GSSBuffer namestr, GSSOID name_type, gss_imp_name_type fn);
   void release();
index 49a3ec0..2a57987 100644 (file)
@@ -163,11 +163,48 @@ void GSSImportNameTest::testConstructorWithJSONObject()
 void GSSImportNameTest::testJSONMarshal()
 {
   /* Variables */
-  GSSImportName cmd = GSSImportName();
+  std::string name("dns@google.com");
+  std::string type("{ 1 2 840 113554 1 2 1 4 }");
+  JSONObject *result;
+  GSSImportName cmd = GSSImportName(&mock_import_name);
   
   /* Error checking */
   /* Setup */
+  cmd.setInputName(name);
+  cmd.setInputNameType(type);
+  MockImportName::minor_status = 0;
+  MockImportName::retVal = 0;
+  MockImportName::output_name.setValue(GSS_C_NO_NAME);
+  
   /* Main */
+  cmd.execute();
+  result = cmd.toJSON();
+  
+  CPPUNIT_ASSERT_EQUAL_MESSAGE(
+    "The command name is incorrect",
+    std::string("gss_import_name"),
+    std::string( (*result)["command"].string() )
+  );
+  
+  
+  CPPUNIT_ASSERT_EQUAL_MESSAGE(
+    "The return value was reported incorrectly",
+    (int)MockImportName::retVal,
+    (int)( (*result)["return_values"]["major_status"].integer() )
+  );
+  
+  CPPUNIT_ASSERT_EQUAL_MESSAGE(
+    "The minor_status value was reported incorrectly",
+    (int)MockImportName::minor_status,
+    (int)( (*result)["return_values"]["minor_status"].integer() )
+  );
+  
+  CPPUNIT_ASSERT_EQUAL_MESSAGE(
+    "The gss_name was reported incorrectly",
+    std::string("constant for now"),
+    std::string( (*result)["return_values"]["gss_name"].string() )
+  );
+  
   
   /* Cleanup */
   /* Return */