cefc580df44cc92ce0ba23bce04c134e219be6b3
[gssweb.git] / json_gssapi / test / NameCacheTest.cpp
1 /*
2  * Copyright (c) 2014 <copyright holder> <email>
3  *
4  * For license details, see the LICENSE file in the root of this project.
5  *
6  */
7
8 #include <string>
9 #include <iostream>
10
11 #include "NameCacheTest.h"
12 #include "cache/GSSNameCache.h"
13 #include "datamodel/GSSName.h"
14 #include <GSSImportName.h>
15
16 CPPUNIT_TEST_SUITE_REGISTRATION( NameCacheTest );
17
18 void NameCacheTest::setUp()
19 {
20
21 }
22
23 void NameCacheTest::tearDown()
24 {
25
26 }
27
28 void NameCacheTest::testStore()
29 {
30   /* Variables      */
31   gss_name_t src;
32   std::string  key;
33   GSSName      source, target;
34   OM_uint32 major, minor;
35   
36   /* Error checking */
37   /* Setup          */
38   major = gss_import_name(&minor, GSSBuffer((char *)"HTTP@localhost").toGss(), GSS_C_NT_HOSTBASED_SERVICE, &src);
39   if (GSS_ERROR(major))
40   {
41     OM_uint32 min, context;
42     gss_buffer_desc buf;
43     
44     std::cout << "Error in importing name." << std::endl;
45     gss_display_status(&min, major, GSS_C_GSS_CODE, GSS_C_NT_HOSTBASED_SERVICE, &context, &buf);
46     std::cout << "  message: " << (char *)buf.value << std::endl;
47   }
48   CPPUNIT_ASSERT_MESSAGE(
49     "Could not generate a name to test storing into the cache.",
50     !GSS_ERROR(major)
51   );
52   source.setValue(src);
53   
54   /* Main           */
55   
56   // Store the data
57   key = GSSNameCache::instance()->store(source);
58   
59   // verify that the data can be retrieved.
60   target = GSSNameCache::instance()->retrieve(key);
61   
62   CPPUNIT_ASSERT_EQUAL_MESSAGE(
63     "The name cache did not store and retrieve the same data",
64     source.toString(),
65     target.toString()
66   );
67
68   /* Cleanup        */
69   /* Return         */
70   
71 }
72
73
74
75   /* Variables      */
76   /* Error checking */
77   /* Setup          */
78   /* Main           */
79   /* Cleanup        */
80   /* Return         */