.*kate-swp
#build
#build/
+
+
+#
+# Files specific to gssweb
+############################
+json_gssapi/build
+json_gssapi/debug
+json_gssapi/manual
+test/
\ No newline at end of file
project(json_gssapi)
-add_executable(json_gssapi src/GSSException.cpp src/GSSCreateSecContextCommand.cpp src/GSSCommand.cpp src/util_json.cpp main.cpp)
+add_executable(json_gssapi src/datamodel/GSSName.cpp src/datamodel/GSSOID.cpp src/datamodel/GSSBuffer.cpp src/GSSException.cpp
+ src/GSSCreateSecContextCommand.cpp
+ src/GSSCommand.cpp
+ src/GSSImportName.cpp
+ src/util_json.cpp
+ main.cpp)
target_link_libraries(json_gssapi gssapi_krb5 jansson)
--- /dev/null
+#include <iostream>
+
+int main(int argc, char **argv) {
+ std::cout << "Hello, world!" << std::endl;
+ return 0;
+}
+
+add_subdirectory(datamodel)
\ No newline at end of file
{
public:
GSSCommand() {};
- GSSCommand(void *fn) : function(fn) {};
- GSSCommand(JSONObject params, void *fn) : function(fn) { };
+ GSSCommand(JSONObject params) : parameters(params) { };
- void *getGSSFunction() { return function; };
virtual void execute() { std::cout << "\ninside GSSCommand::invoke()\n"; };
virtual JSONObject *toJSON() { return new JSONObject(); }
protected:
- void *function;
+ JSONObject parameters;
};
#endif // GSSCOMMAND_H
GSSCreateSecContextCommand::GSSCreateSecContextCommand(
JSONObject *params,
- void *fn) : GSSCommand(params, fn)
+ void *fn) : GSSCommand(params)
{
zeroOut(false);
loadParameters(params);
+ function = fn;
}
-GSSCreateSecContextCommand::GSSCreateSecContextCommand(void *fn) : GSSCommand(fn)
+GSSCreateSecContextCommand::GSSCreateSecContextCommand(void *fn)
{
zeroOut(false);
+ function = fn;
}
OM_uint32 getReqFlags() { return req_flags; }
OM_uint32 getTimeReq() { return time_req; }
gss_ctx_id_t getContextHandle() { return context_handle; }
+ void *getGSSFunction() { return function; }
// complex accessors
const char * getTargetDisplayName();
const char * getActualMechType();
private:
+ void *function;
const char * oidToStr(gss_OID oid);
};
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#include "GSSImportName.h"
+
+void GSSImportName::execute()
+{
+
+}
+
+JSONObject *GSSImportName::toJSON()
+{
+ return new JSONObject();
+}
+
+GSSImportName::GSSImportName(JSONObject *params, gss_imp_name_type fn) : GSSCommand(params)
+{
+ /* Variables */
+ /* Error checking */
+ /* Setup */
+ /* Main */
+ loadParameters(params);
+ function = fn;
+ /* Cleanup */
+ /* Return */
+
+}
+
+bool GSSImportName::loadParameters(JSONObject *params)
+{
+ /* Variables */
+ /* Error checking */
+ /* Setup */
+ // Should I zeroOut?
+
+ /* Main processing */
+ // Easy stuff(*params)
+ std::string input_name = (*params)["arguments"]["input_name"].string();
+ std::string input_name_type = (*params)["arguments"]["input_name_type"].string();
+
+ this->inputName.setValue( (*params)["arguments"]["input_name"].string() );
+ this->inputNameType.setValue( (*params)["arguments"]["input_name_type"].string() );
+
+ /* Cleanup */
+ /* Return */
+ return true;
+}
+
+
+/* Variables */
+/* Error checking */
+/* Setup */
+/* Main */
+/* Cleanup */
+/* Return */
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#ifndef GSSIMPORTNAME_H
+#define GSSIMPORTNAME_H
+
+#include "GSSCommand.h"
+#include "datamodel/GSSBuffer.h"
+#include "datamodel/GSSName.h"
+
+#include <gssapi.h>
+
+class GSSImportName : public GSSCommand
+{
+public:
+ GSSImportName(gss_imp_name_type fn = &gss_import_name) : function(fn) {};
+ GSSImportName(JSONObject *params, gss_imp_name_type fn = &gss_import_name);
+
+ void execute();
+ JSONObject* toJSON();
+
+ GSSBuffer getInputName() { return GSSBuffer(inputName); }
+ GSSBuffer getInputNameType() { return GSSBuffer(inputNameType); }
+
+ gss_imp_name_type getGSSFunction() { return function; }
+
+private:
+ gss_imp_name_type function;
+ bool loadParameters(JSONObject *params);
+ GSSBuffer inputName;
+ GSSBuffer inputNameType;
+
+};
+
+#endif // GSSIMPORTNAME_H
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#include <stdexcept>
+#include <cstring>
+#include "GSSBuffer.h"
+#include "../GSSException.h"
+
+
+/* Constructor pattern:
+ * 1) Set gssInternal to false, so that setting values is permitted.
+ * 2) Allocate memory for a new gss_buffer_desc
+ * 3) Set the buffer length to 0, so that setting values doesn't try
+ * to free memory.
+ * 4) Set the value of the buffer.
+ * 5) Set the value of gssInternal correctly
+ */
+GSSBuffer::GSSBuffer ( const GSSBuffer &other )
+{
+ gss_buffer_t otherBuf = other.buf;
+ initEmpty();
+ setValue( (char *)(otherBuf->value), otherBuf->length);
+ this->gssInternal = false;
+}
+
+GSSBuffer::GSSBuffer(std::string str, bool gssInternal)
+{
+ initEmpty();
+ setValue(str);
+ this->gssInternal = gssInternal;
+}
+
+GSSBuffer::GSSBuffer(char *str, bool gssInternal)
+{
+ initEmpty();
+ setValue(str);
+ this->gssInternal = gssInternal;
+}
+
+GSSBuffer::GSSBuffer(char *str, int len, bool gssInternal)
+{
+ initEmpty();
+ setValue(str, len);
+ this->gssInternal = gssInternal;
+}
+
+GSSBuffer::GSSBuffer(gss_buffer_t gssbuf, bool gssInternal)
+{
+ initEmpty();
+ setValue(gssbuf);
+ this->gssInternal = gssInternal;
+}
+
+GSSBuffer::~GSSBuffer(void)
+{
+ OM_uint32 major, minor;
+
+ if (this->gssInternal)
+ {
+ major = gss_release_buffer(&minor, buf);
+ if (GSS_ERROR(major))
+ {
+ throw GSSException("Error in releasing a buffer allocated by GSS", major, minor);
+ }
+ } else {
+ freeBufValue();
+ }
+}
+
+
+void GSSBuffer::initEmpty()
+{
+ this->gssInternal = false;
+ this->buf = new gss_buffer_desc;
+ this->buf->length = 0;
+ this->buf->value = NULL;
+}
+
+void GSSBuffer::freeBufValue()
+{
+ if (this->buf->length == 0 && this->buf->value != NULL)
+ delete[] ( (char *)(this->buf->value) );
+ this->buf->length = 0;
+ this->buf->value = NULL;
+}
+
+
+/* setValue pattern:
+ * 1) Throw an exception when attempting to mutate a buffer supplied by
+ * GSS itself.
+ * 2) Free the GSS buffer value, if needed.
+ * 3) Set the buffer value as needed.
+ */
+void GSSBuffer::setValue(std::string str)
+{
+ setValue((char *)str.c_str(), str.size());
+}
+
+void GSSBuffer::setValue(char *str)
+{
+ setValue(str, std::strlen(str));
+}
+
+void GSSBuffer::setValue(char *str, int len)
+{
+ /* Variables */
+ /* Error checking */
+ if (this->gssInternal)
+ throw std::logic_error("Attempting to modify an immutable GSSBuffer");
+
+ /* Setup */
+ freeBufValue();
+
+ /* Main */
+ this->buf->value = new char[len];
+ std::memcpy( (void *)(this->buf->value), (void *)str, len);
+ this->buf->length = len;
+
+ /* Cleanup */
+ /* Return */
+}
+
+void GSSBuffer::setValue(gss_buffer_t gssbuf)
+{
+ if (this->gssInternal)
+ throw std::logic_error("Attempting to modify an immutable GSSBuffer");
+ freeBufValue();
+ delete buf;
+ this->buf = gssbuf;
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#ifndef GSSBUFFER_H
+#define GSSBUFFER_H
+
+#include <string>
+#include "gssapi.h"
+#include <iostream>
+
+class GSSBuffer {
+public:
+ GSSBuffer(std::string str = "", bool gssInternal = false);
+ GSSBuffer(char *str, bool gssInternal = false);
+ GSSBuffer(char *str, int len, bool gssInternal = false);
+ GSSBuffer(gss_buffer_t gssbuf, bool gssInternal = false);
+ GSSBuffer(const GSSBuffer &other);
+ ~GSSBuffer(void);
+
+ std::string toString() { return(std::string((char *)buf->value, buf->length)); }
+ gss_buffer_t toGss() { return( buf ); }
+ int length() { return(buf->length); }
+
+ void setValue(std::string str);
+ void setValue(char *str);
+ void setValue(char *str, int len);
+ void setValue(gss_buffer_t gssbuf);
+
+ bool operator==(GSSBuffer B) { return(this->toString() == B.toString()); }
+
+private:
+ gss_buffer_t buf;
+ bool gssInternal;
+
+ void freeBufValue();
+ void initEmpty();
+};
+
+
+
+
+#endif // GSSBUFFER_H
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#include "GSSName.h"
+#include "../GSSException.h"
+
+void GSSName::init(GSSBuffer namestr, GSSOID name_type, gss_imp_name_type fn)
+{
+ /* Variables */
+ OM_uint32 major, minor;
+ /* Error checking */
+ /* Setup */
+ /* Main */
+ major = gss_import_name(&minor, namestr.toGss(), name_type.toGss(), &name);
+ if ( GSS_ERROR(major) )
+ {
+ std::string errMsg;
+ errMsg += "Cannot import name: ";
+ errMsg += namestr.toString();
+ throw GSSException(errMsg.c_str(), major, minor, name_type.toGss());
+ }
+ this->function = fn;
+
+ /* Cleanup */
+ /* Return */
+}
+
+
+
+GSSName::GSSName(std::string namestr, GSSOID name_type, gss_imp_name_type fn)
+{
+ init(namestr, name_type, fn);
+}
+
+GSSName::GSSName(char *namestr, GSSOID name_type, gss_imp_name_type fn)
+{
+ init(GSSBuffer(namestr), name_type, fn);
+}
+
+GSSName::GSSName(GSSBuffer namestr, GSSOID name_type, gss_imp_name_type fn)
+{
+ init(GSSBuffer(namestr), name_type, fn);
+}
+
+GSSName::GSSName(std::string namestr, gss_OID name_type, gss_imp_name_type fn)
+{
+ init(GSSBuffer(namestr), GSSOID(name_type), fn);
+}
+
+GSSName::GSSName(char *namestr, gss_OID name_type, gss_imp_name_type fn)
+{
+ init(GSSBuffer(namestr), GSSOID(name_type), fn);
+}
+
+GSSName::GSSName(GSSBuffer namestr, gss_OID name_type, gss_imp_name_type fn)
+{
+ init(namestr, GSSOID(name_type), fn);
+}
+
+GSSName::GSSName(std::string namestr, std::string name_type, gss_imp_name_type fn)
+{
+ init(GSSBuffer(namestr), GSSOID(name_type), fn);
+}
+
+GSSName::GSSName(char *namestr, std::string name_type, gss_imp_name_type fn)
+{
+ init(GSSBuffer(namestr), GSSOID(name_type), fn);
+}
+
+GSSName::GSSName(GSSBuffer namestr, std::string name_type, gss_imp_name_type fn)
+{
+ init(namestr, GSSOID(name_type), fn);
+}
+
+
+GSSName::~GSSName()
+{
+ /* Variables */
+ OM_uint32 major, minor;
+
+ /* Error checking */
+ /* Setup */
+ /* Main */
+ major = gss_release_name(&minor, &name);
+ if ( GSS_ERROR(major) && !( major & GSS_S_BAD_NAME ) )
+ {
+ throw GSSException("Cannot free memory for a GSS name.", major, minor);
+ }
+
+ /* Cleanup */
+ /* Return */
+}
+
+
+std::string GSSName::toString()
+{
+ /* Variables */
+ OM_uint32 major, minor;
+ gss_OID oid;
+ GSSBuffer buf;
+
+ /* Error checking */
+ /* Setup */
+ /* Main */
+ major = gss_display_name(&minor, (this->name), buf.toGss(), &oid);
+ if ( GSS_ERROR(major) )
+ {
+ throw GSSException("Cannot convert a GSS name to a string.", major, minor);
+ }
+
+ /* Cleanup */
+ /* Return */
+ return buf.toString();
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#include <string>
+#include "GSSBuffer.h"
+#include "GSSOID.h"
+
+#ifndef GSSNAME_H
+#define GSSNAME_H
+
+
+typedef OM_uint32 (*gss_imp_name_type)(
+ OM_uint32 *, /* minor_status */
+ gss_buffer_t, /* input_name_buffer */
+ gss_OID, /* input_name_type(used to be const) */
+ gss_name_t *); /* output_name */
+
+
+class GSSName {
+public:
+ GSSName(std::string nameStr,
+ GSSOID name_type = GSSOID( (gss_OID)GSS_C_NO_OID ),
+ gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+ GSSName(char *namestr,
+ GSSOID name_type = GSSOID( (gss_OID)GSS_C_NO_OID ),
+ gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+ GSSName(GSSBuffer namestr,
+ GSSOID name_type = GSSOID( (gss_OID)GSS_C_NO_OID ),
+ gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+
+ GSSName(std::string nameStr,
+ gss_OID name_type,
+ gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+ GSSName(char *namestr,
+ gss_OID name_type,
+ gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+ GSSName(GSSBuffer namestr,
+ gss_OID name_type,
+ gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+
+ GSSName(std::string nameStr,
+ std::string name_type,
+ gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+ GSSName(char *namestr,
+ std::string name_type,
+ gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+ GSSName(GSSBuffer namestr,
+ std::string name_type,
+ gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+
+ ~GSSName();
+
+
+ gss_name_t toGSS() { return(name); }
+ std::string toString();
+
+private:
+ gss_name_t name;
+ void init(GSSBuffer namestr, GSSOID name_type, gss_imp_name_type fn);
+ gss_imp_name_type function;
+};
+
+
+#endif // GSSNAME_H
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#include "GSSOID.h"
+#include "../GSSException.h"
+
+GSSOID::GSSOID(std::string oid_str)
+{
+ init( GSSBuffer(oid_str) );
+}
+
+GSSOID::GSSOID(char *oid_str)
+{
+ init( GSSBuffer(oid_str) );
+}
+
+GSSOID::GSSOID(GSSBuffer oid_str)
+{
+ init(oid_str);
+}
+
+GSSOID::GSSOID(gss_OID gssoid)
+{
+ oid = gssoid;
+ this->gssInternal = true;
+}
+
+GSSOID::~GSSOID()
+{
+ OM_uint32 major, minor;
+ if (! this->gssInternal)
+ {
+ major = gss_release_oid(&minor, &(this->oid));
+ if (GSS_ERROR(major))
+ {
+ throw GSSException("Error in releasing a GSS OID", major, minor);
+ }
+ }
+}
+
+void GSSOID::init(GSSBuffer oid_str)
+{
+ /* Variables */
+ OM_uint32 major, minor;
+
+ /* Error checking */
+ /* Setup */
+
+ /* Main */
+ major = gss_str_to_oid(&minor, oid_str.toGss(), &(this->oid));
+ if (GSS_ERROR(major))
+ {
+ throw GSSException("Error creating GSS OID", major, minor);
+ }
+ this->gssInternal = false;
+
+ /* Cleanup */
+ /* Return */
+}
+
+std::string GSSOID::toString()
+{
+ /* Variables */
+ OM_uint32 major, minor;
+ gss_buffer_desc buf;
+ std::string ret;
+
+ /* Error checking */
+ /* Setup */
+ /* Main */
+ major = gss_oid_to_str(&minor, this->oid, &buf);
+ if (GSS_ERROR(major))
+ {
+ throw GSSException("Error in creating a string representation of a GSS OID",
+ major, minor);
+ }
+ ret = std::string((char *)buf.value);
+
+ /* Cleanup */
+ major = gss_release_buffer(&minor, &buf);
+ if (GSS_ERROR(major))
+ {
+ throw GSSException("Error releasing a gss_buffer",
+ major, minor);
+ }
+
+ /* Return */
+ return(ret);
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#include <string>
+#include "gssapi.h"
+
+#include "GSSBuffer.h"
+
+#ifndef GSSOID_H
+#define GSSOID_H
+
+class GSSOID {
+public:
+ GSSOID(char *oid_str);
+ GSSOID(std::string oid_str);
+ GSSOID(GSSBuffer oid_str);
+ GSSOID(gss_OID gssoid);
+ ~GSSOID();
+
+ gss_OID toGss() { return(oid); };
+ std::string toString();
+
+private:
+ gss_OID oid;
+ bool gssInternal;
+
+ void init(GSSBuffer oid_str);
+};
+
+
+#endif // GSSOID_H
bool JSONObject::isNull(void) const
{
- return json_is_null(m_obj);
+ return json_is_null(m_obj);
}
JSONIterator::JSONIterator(const JSONObject &obj)
include_directories(${CMAKE_SOURCE_DIR}/src)
-add_executable(test GSSExceptionTest.cpp InitSecContextMock.cpp
- GSSCreateSecContextTest.cpp test_run.cpp
+add_executable(test GSSExceptionTest.cpp
+ InitSecContextMock.cpp
+ GSSCreateSecContextTest.cpp
+ GSSImportNameTest.cpp
+ MockImportName.cpp
+ test_run.cpp
../src/GSSCreateSecContextCommand.cpp
- ../src/util_json.cpp ../src/GSSException.cpp)
+ ../src/util_json.cpp
+ ../src/GSSImportName.cpp
+ ../src/GSSException.cpp
+ ../src/datamodel/GSSBuffer.cpp
+ datamodel/GSSBufferTest.cpp
+ )
target_link_libraries(test cppunit gssapi_krb5 jansson)
# install(TARGETS test RUNTIME DESTINATION bin)
+
+add_subdirectory(datamodel)
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2014 Painless Security LLC
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ * GSSImportNameTest.h - Test the GSSImportName object.
+ * Tests include:
+ * testConstructor -
+ * Testing basic object creation
+ * testConstructorWithJSONObject -
+ * Test object creation with a set of arguments
+ * testEmptyCall -
+ * Basic test of the system, with an empty call to
+ * a mocked out gss_import_name function, to test
+ * whether the object passes and records arguments
+ * correctly
+ * testJSONMarshal -
+ * test the JSON serialization of the object
+ */
+
+#include "GSSImportNameTest.h"
+#include "GSSImportName.h"
+#include "MockImportName.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( GSSImportNameTest );
+
+
+/*
+ * a mock of the gss_import_name call
+ *
+ * Basically, just copy the arguments over to/from the
+ * MockImportName global object
+ */
+static OM_uint32 KRB5_CALLCONV
+mock_import_name(
+ OM_uint32 *minor_status,
+ gss_buffer_t input_name_buffer,
+ gss_OID input_name_type,
+ gss_name_t *output_name)
+{
+ /* Error checking */
+ /* Variables */
+ /* Setup */
+ /* Main */
+ // Copy our input from the appropriate parameters to MockImportName
+ MockImportName::input_name_buffer = input_name_buffer;
+ MockImportName::input_name_type = input_name_type;
+
+ // copy our output to the appropriate parameters
+ *minor_status = MockImportName::minor_status;
+ *output_name = MockImportName::output_name;
+
+
+ /* Cleanup */
+ /* return */
+ return MockImportName::retVal;
+}
+
+void GSSImportNameTest::setUp()
+{
+ CppUnit::TestFixture::setUp();
+ MockImportName::reset();
+}
+
+void GSSImportNameTest::tearDown()
+{
+ CppUnit::TestFixture::tearDown();
+}
+
+void GSSImportNameTest::testConstructor()
+{
+ /* Variables */
+ GSSImportName cmd = GSSImportName();
+
+ /* Error checking */
+ /* Setup */
+ /* Main */
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(
+ "The GSSImportName object has the wrong GSS function",
+ (void *)&gss_import_name,
+ (void *)cmd.getGSSFunction()
+ );
+
+ /* Cleanup */
+ /* Return */
+}
+void GSSImportNameTest::testEmptyCall()
+{
+ /* Variables */
+ GSSImportName cmd = GSSImportName();
+
+ /* Error checking */
+ /* Setup */
+ /* Main */
+
+ /* Cleanup */
+ /* Return */
+}
+void GSSImportNameTest::testConstructorWithJSONObject()
+{
+ /* Variables */
+ const char* input = "{\"method\": \"gss_import_name\", \
+ \"arguments\": {\"input_name\": \"http@localhost\", \
+ \"input_name_type\": \"{ 1 2 840 113554 1 2 1 4 }\"}}";
+ json_error_t jsonErr;
+ JSONObject json = JSONObject::load(input, 0, &jsonErr);
+
+ GSSImportName cmd = GSSImportName(&json, &mock_import_name);
+
+ /* Error checking */
+ /* Setup */
+ /* Main */
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(
+ "GSSImportName did not parse the input_name argument correctly",
+ std::string("http@localhost"),
+ cmd.getInputName().toString()
+ );
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(
+ "GSSImportName did not parse the input_name_type argument correctly",
+ std::string("{ 1 2 840 113554 1 2 1 4 }"),
+ cmd.getInputNameType().toString()
+ );
+
+ /* Cleanup */
+ /* Return */
+}
+void GSSImportNameTest::testJSONMarshal()
+{
+ /* Variables */
+ GSSImportName cmd = GSSImportName();
+
+ /* Error checking */
+ /* Setup */
+ /* Main */
+
+ /* Cleanup */
+ /* Return */
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2014 Painless Security LLC
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ * GSSImportNameTest.h - Test the GSSImportName object.
+ * Tests include:
+ * testConstructor -
+ * Testing basic object creation
+ * testConstructorWithJSONObject -
+ * Test object creation with a set of arguments
+ * testEmptyCall -
+ * Basic test of the system, with an empty call to
+ * a mocked out gss_import_name function, to test
+ * whether the object passes and records arguments
+ * correctly
+ * testJSONMarshal -
+ * test the JSON serialization of the object
+ */
+
+#ifndef GSSIMPORTNAMETEST_H
+#define GSSIMPORTNAMETEST_H
+
+// #include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <gssapi.h>
+#include "GSSCreateSecContextCommand.h"
+
+#include <stdlib.h>
+
+class GSSImportNameTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE( GSSImportNameTest );
+ CPPUNIT_TEST( testConstructor );
+ CPPUNIT_TEST( testConstructorWithJSONObject );
+ CPPUNIT_TEST( testEmptyCall );
+ CPPUNIT_TEST( testJSONMarshal );
+ CPPUNIT_TEST_SUITE_END();
+
+
+
+public:
+ void setUp();
+ void tearDown();
+
+
+ void testConstructor();
+ void testConstructorWithJSONObject();
+ void testEmptyCall();
+ void testJSONMarshal();
+};
+
+#endif // GSSIMPORTNAMETEST_H
--- /dev/null
+/*
+ * Copyright (c) 2014 Painless Security, LLC.
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ * MockImportName - Mock out the parameters for calling the
+ * GSSImportName object's function
+ *
+ */
+
+#include "MockImportName.h"
+#include <string>
+
+/*
+class MockImportName
+{
+public:
+ static OM_uint32 retVal;
+ static OM_uint32 minor_status;
+ static gss_buffer_t input_name_buffer;
+ static gss_OID input_name_type;
+ static gss_name_t output_name;
+
+ static bool visited;
+
+ static void reset();
+};
+
+*/
+
+OM_uint32 MockImportName::retVal = 0;
+OM_uint32 MockImportName::minor_status = 0;
+GSSBuffer MockImportName::input_name_buffer = GSSBuffer(std::string(""));
+gss_OID MockImportName::input_name_type = NULL;
+gss_name_t MockImportName::output_name = NULL;
+
+
+
+void MockImportName::reset()
+{
+ retVal = 0;
+ minor_status = 0;
+ input_name_buffer.setValue(std::string());
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#ifndef MOCKIMPORTNAME_H
+#define MOCKIMPORTNAME_H
+
+#include <gssapi.h>
+
+#include "datamodel/GSSBuffer.h"
+
+class MockImportName
+{
+public:
+ static OM_uint32 retVal;
+ static OM_uint32 minor_status;
+ static GSSBuffer input_name_buffer;
+ static gss_OID input_name_type;
+ static gss_name_t output_name;
+
+ static bool visited;
+
+ static void reset();
+};
+
+#endif // MOCKIMPORTNAME_H
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#include "GSSBufferTest.h"
+#include <datamodel/GSSBuffer.h>
+#include <cstring>
+
+CPPUNIT_TEST_SUITE_REGISTRATION( GSSBufferTest );
+
+void
+GSSBufferTest::setUp()
+{
+
+}
+
+void
+GSSBufferTest::tearDown()
+{
+
+}
+
+void GSSBufferTest::testStringConstructor()
+{
+ /* Variables */
+ std::string str("test string");
+ GSSBuffer buf(str);
+ gss_buffer_t gssBuf = buf.toGss();
+
+ /* Error checking */
+ /* Setup */
+
+ /* Main */
+ CPPUNIT_ASSERT_MESSAGE(
+ "The string was not copied in :(",
+ (std::strncmp( (char *)str.c_str(), (char *)gssBuf->value, gssBuf->length ) == 0)
+ );
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(
+ "The string was not output correctly",
+ str,
+ buf.toString()
+ );
+
+ /* Cleanup */
+ /* Return */
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#ifndef GSSBUFFERTEST_H
+#define GSSBUFFERTEST_H
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class GSSBufferTest : public CppUnit::TestFixture
+{
+
+ CPPUNIT_TEST_SUITE( GSSBufferTest );
+ CPPUNIT_TEST( testStringConstructor );
+ CPPUNIT_TEST_SUITE_END();
+
+
+public:
+ virtual void setUp();
+ virtual void tearDown();
+
+ virtual void testStringConstructor();
+};
+
+#endif // GSSBUFFERTEST_H