5c915fa7b24919914e6dc01e9857566980c5b4da
[gssweb.git] / json_gssapi / test / GSSImportNameTest.cpp
1 /*
2  * Copyright (c) 2014 Painless Security LLC
3  * 
4  * For license details, see the LICENSE file in the root of this project.
5  * 
6  * GSSImportNameTest.h - Test the GSSImportName object.
7  * Tests include:
8  *   testConstructor - 
9  *       Testing basic object creation
10  *   testConstructorWithJSONObject - 
11  *       Test object creation with a set of arguments
12  *   testEmptyCall - 
13  *       Basic test of the system, with an empty call to
14  *       a mocked out gss_import_name function, to test
15  *       whether the object passes and records arguments
16  *       correctly
17  *   testJSONMarshal - 
18  *       test the JSON serialization of the object
19  */
20
21 #include "GSSImportNameTest.h"
22 #include "GSSImportName.h"
23 #include "MockImportName.h"
24
25 CPPUNIT_TEST_SUITE_REGISTRATION( GSSImportNameTest );
26
27
28 /* 
29  * a mock of the gss_import_name call
30  * 
31  * Basically, just copy the arguments over to/from the
32  * MockImportName global object
33  */
34 static OM_uint32 KRB5_CALLCONV
35 mock_import_name(
36     OM_uint32     *minor_status,
37     gss_buffer_t   input_name_buffer, 
38     gss_OID        input_name_type,
39     gss_name_t    *output_name)
40 {
41   /* Error checking */
42   /* Variables */
43   /* Setup */
44   /* Main */
45   // Copy our input from the appropriate parameters to MockImportName
46   MockImportName::input_name_buffer = input_name_buffer;
47   MockImportName::input_name_type = input_name_type;
48   
49   // copy our output to the appropriate parameters
50   *minor_status = MockImportName::minor_status;
51   *output_name = MockImportName::output_name;
52   
53   
54   /* Cleanup */
55   /* return */
56   return MockImportName::retVal;
57 }
58
59 void GSSImportNameTest::setUp()
60 {
61   CppUnit::TestFixture::setUp();
62   MockImportName::reset();
63 }
64
65 void GSSImportNameTest::tearDown()
66 {
67     CppUnit::TestFixture::tearDown();
68 }
69
70 void GSSImportNameTest::testConstructor()
71 {
72   /* Variables */
73   GSSImportName cmd = GSSImportName();
74   
75   /* Error checking */
76   /* Setup */
77   /* Main */
78   CPPUNIT_ASSERT_EQUAL_MESSAGE(
79     "The GSSImportName object has the wrong GSS function",
80     (void *)&gss_import_name,
81     (void *)cmd.getGSSFunction()
82   );
83   
84   /* Cleanup */
85   /* Return */
86 }
87 void GSSImportNameTest::testEmptyCall()
88 {
89   /* Variables */
90   GSSImportName cmd = GSSImportName();
91   
92   /* Error checking */
93   /* Setup */
94   /* Main */
95   
96   /* Cleanup */
97   /* Return */
98 }
99 void GSSImportNameTest::testConstructorWithJSONObject()
100 {
101   /* Variables */
102   const char* input = "{\"method\": \"gss_import_name\", \
103     \"arguments\": {\"input_name\": \"http@localhost\", \
104     \"input_name_type\": \"{ 1 2 840 113554 1 2 1 4 }\"}}";
105   json_error_t jsonErr;
106   JSONObject json = JSONObject::load(input, 0, &jsonErr);
107   
108   GSSImportName cmd = GSSImportName(&json, &mock_import_name);
109   
110   /* Error checking */
111   /* Setup */
112   /* Main */
113   
114   CPPUNIT_ASSERT_EQUAL_MESSAGE(
115     "GSSImportName did not parse the input_name argument correctly",
116     std::string("http@localhost"),
117     cmd.getInputName().toString()
118   );
119   
120   CPPUNIT_ASSERT_EQUAL_MESSAGE(
121     "GSSImportName did not parse the input_name_type argument correctly",
122     std::string("{ 1 2 840 113554 1 2 1 4 }"),
123     cmd.getInputNameType().toString()
124   );
125   
126   /* Cleanup */
127   /* Return */
128 }
129 void GSSImportNameTest::testJSONMarshal()
130 {
131   /* Variables */
132   GSSImportName cmd = GSSImportName();
133   
134   /* Error checking */
135   /* Setup */
136   /* Main */
137   
138   /* Cleanup */
139   /* Return */
140 }
141