1 package com.p6r.kmipserverlib;
5 import javax.security.auth.x500.X500Principal;
6 import java.io.ByteArrayInputStream;
7 import java.io.InputStream;
8 import java.nio.charset.Charset;
9 import java.security.cert.CertificateFactory;
10 import java.security.cert.X509Certificate;
12 import static org.junit.Assert.assertEquals;
28 System.out.println(
"@BeforeClass - oneTimeSetUp");
34 System.out.println(
"@AfterClass - oneTimeTearDown");
40 System.out.println(
"@Before - setUp");
46 System.out.println(
"@After - tearDown");
56 System.out.println(
"@Test - JNICall-DeleteAttributeKMIP");
58 P6KMIPServerLib sl =
new P6KMIPServerLib();
61 byte[] testMessage = {
62 0x42, 0x00, 0x78, 0x01, 0x00, 0x00, 0x00, (byte) 0xc0, 0x42, 0x00, 0x77, 0x01, 0x00, 0x00, 0x00, 0x58, 0x42, 0x00, 0x69, 0x01, 0x00, 0x00, 0x00, 0x20, 0x42, 0x00, 0x6a, 0x02, 0x00, 0x00, 0x00, 0x04,
63 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x6b, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x50, 0x02, 0x00, 0x00, 0x00, 0x04,
64 0x00, 0x00, 0x27, 0x10, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, (byte) 0x92, 0x09, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x5a, 0x29, (byte) 0xcf, (byte) 0xe7, 0x42, 0x00, 0x0d, 0x02, 0x00, 0x00, 0x00, 0x04,
65 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x58, 0x42, 0x00, 0x5c, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
66 0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x40, 0x42, 0x00, (byte) 0x94, 0x07, 0x00, 0x00, 0x00, 0x14, 0x41, 0x57, 0x41, 0x78, 0x77, 0x36, 0x47, 0x6b, 0x6f, 0x45, 0x67, 0x45, 0x36, 0x79, 0x65, 0x6b,
67 0x35, 0x61, 0x4c, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x13, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x63, 0x74, 0x20, 0x49, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74,
68 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00
72 String testMessage20_1 =
"<RequestMessage>\n" +
74 " <ProtocolVersion>\n" +
75 " <ProtocolVersionMajor type=\"Integer\" value=\"2\"/>\n" +
76 " <ProtocolVersionMinor type=\"Integer\" value=\"0\"/>\n" +
77 " </ProtocolVersion>\n" +
78 " <BatchCount type=\"Integer\" value=\"1\"/>\n" +
79 "</RequestHeader>\n" +
81 " <Operation type=\"Enumeration\" value=\"DeleteAttribute\"/>\n" +
82 " <RequestPayload>\n" +
83 " <UniqueIdentifier type=\"TextString\" value=\"e82a80f0-fe20-4cbb-a1b6-00e3a81a7e9f\"/>\n" +
84 " <CurrentAttribute>\n" +
86 " <NameValue type=\"TextString\" value=\"Fake-Modify-test-23\"/>\n" +
87 " <NameType type=\"Enumeration\" value=\"UninterpretedTextString\"/>\n" +
89 " </CurrentAttribute>\n" +
90 " </RequestPayload>\n" +
94 String testMessage20_2 =
"<RequestMessage>\n" +
96 " <ProtocolVersion>\n" +
97 " <ProtocolVersionMajor type=\"Integer\" value=\"2\"/>\n" +
98 " <ProtocolVersionMinor type=\"Integer\" value=\"0\"/>\n" +
99 " </ProtocolVersion>\n" +
100 " <BatchCount type=\"Integer\" value=\"1\"/>\n" +
101 "</RequestHeader>\n" +
103 " <Operation type=\"Enumeration\" value=\"DeleteAttribute\"/>\n" +
104 " <RequestPayload>\n" +
105 " <UniqueIdentifier type=\"TextString\" value=\"e82a80f0-fe20-4cbb-a1b6-00e3a81a7e9f\"/>\n" +
106 " <AttributeReference type=\"Enumeration\" value=\"AlternativeName\"/>\n" +
107 " </RequestPayload>\n" +
111 String testMessage20_3 =
"<RequestMessage>\n" +
112 "<RequestHeader>\n" +
113 " <ProtocolVersion>\n" +
114 " <ProtocolVersionMajor type=\"Integer\" value=\"2\"/>\n" +
115 " <ProtocolVersionMinor type=\"Integer\" value=\"0\"/>\n" +
116 " </ProtocolVersion>\n" +
117 " <BatchCount type=\"Integer\" value=\"1\"/>\n" +
118 "</RequestHeader>\n" +
120 " <Operation type=\"Enumeration\" value=\"DeleteAttribute\"/>\n" +
121 " <RequestPayload>\n" +
122 " <UniqueIdentifier type=\"TextString\" value=\"e82a80f0-fe20-4cbb-a1b6-00e3a81a7e9f\"/>\n" +
123 " <AttributeReference><VendorIdentification type=\"TextString\" value=\"P6R\"/><AttributeName type=\"TextString\" value=\"SKC-client\" /></AttributeReference>\n" +
124 " </RequestPayload>\n" +
130 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
132 String libVersion = sl.getLibraryVersion();
133 System.out.println(libVersion);
138 sl.setMessageBuffer(testMessage, KMIPConstants.FORMAT_TTLV);
141 RequestHeader rh = sl.getRequestHeader();
142 assertEquals(
"1.0", rh.getProtocolVersion());
146 for (
int i = 0; i < rh.getBatchCount(); i++) {
148 BatchItem bi = sl.getBatchItem(i + 1);
149 if (bi instanceof DeleteAttributeBatchItem) {
150 DeleteAttributeBatchItem rb = (DeleteAttributeBatchItem) bi;
152 assertEquals(null, rb.getUniqueBatchId());
154 String uniqueId = rb.getUniqueId();
155 assertEquals(
"AWAxw6GkoEgE6yek5aLj", uniqueId);
157 String attribName = rb.getAttributeName();
158 assertEquals(
"Contact Information", attribName);
160 int index = rb.getIndex();
161 assertEquals(0, index);
167 sl.setMessageBuffer(testMessage20_1.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGXML);
168 rh = sl.getRequestHeader();
169 assertEquals(
"2.0", rh.getProtocolVersion());
171 for (
int i = 0; i < rh.getBatchCount(); i++) {
173 BatchItem bi = sl.getBatchItem(i + 1);
174 if (bi instanceof DeleteAttribute2BatchItem) {
175 DeleteAttribute2BatchItem rb = (DeleteAttribute2BatchItem) bi;
177 String uniqueId = rb.getUniqueId();
178 assertEquals(
"e82a80f0-fe20-4cbb-a1b6-00e3a81a7e9f", uniqueId);
180 String currentAttribute = rb.getCurrentAttribute();
181 assertEquals(
"Name: Fake-Modify-test-23 - text_string", currentAttribute);
183 String attributeReference = rb.getAttributeReference();
184 assertEquals(null, attributeReference);
189 sl.setMessageBuffer(testMessage20_2.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGXML);
190 rh = sl.getRequestHeader();
191 assertEquals(
"2.0", rh.getProtocolVersion());
193 for (
int i = 0; i < rh.getBatchCount(); i++) {
195 BatchItem bi = sl.getBatchItem(i + 1);
196 if (bi instanceof DeleteAttribute2BatchItem) {
197 DeleteAttribute2BatchItem rb = (DeleteAttribute2BatchItem) bi;
199 String uniqueId = rb.getUniqueId();
200 assertEquals(
"e82a80f0-fe20-4cbb-a1b6-00e3a81a7e9f", uniqueId);
202 String currentAttribute = rb.getCurrentAttribute();
203 assertEquals(null, currentAttribute);
205 String attributeReference = rb.getAttributeReference();
206 assertEquals(
"Alternative Name", attributeReference);
211 sl.setMessageBuffer(testMessage20_3.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGXML);
212 rh = sl.getRequestHeader();
213 assertEquals(
"2.0", rh.getProtocolVersion());
215 for (
int i = 0; i < rh.getBatchCount(); i++) {
217 BatchItem bi = sl.getBatchItem(i + 1);
218 if (bi instanceof DeleteAttribute2BatchItem) {
219 DeleteAttribute2BatchItem rb = (DeleteAttribute2BatchItem) bi;
221 String uniqueId = rb.getUniqueId();
222 assertEquals(
"e82a80f0-fe20-4cbb-a1b6-00e3a81a7e9f", uniqueId);
224 String currentAttribute = rb.getCurrentAttribute();
225 assertEquals(null, currentAttribute);
227 String attributeReference = rb.getAttributeReference();
228 assertEquals(
"P6R-SKC-client", attributeReference);
234 }
catch (Exception e) {
236 System.out.println(e.toString());
void JNICall_DeleteAttributeKMIP()
Test: Verify parser can parse an incoming delete attribute request for both KMIP versions 1...
static void oneTimeTearDown()
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.
static void oneTimeSetUp()