From: Scott Cantor Date: Wed, 9 Jun 2010 01:12:09 +0000 (+0000) Subject: Fix KeyVaue validator, add ECKeyValue test case. X-Git-Tag: 1.4RC1~60 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fcpp-xmltooling.git;a=commitdiff_plain;h=17abb8d893134fc5b4bb2613cbacb8dafad01b9f Fix KeyVaue validator, add ECKeyValue test case. --- diff --git a/xmltooling/signature/impl/KeyInfoSchemaValidators.cpp b/xmltooling/signature/impl/KeyInfoSchemaValidators.cpp index 23bfdb1..6b80265 100644 --- a/xmltooling/signature/impl/KeyInfoSchemaValidators.cpp +++ b/xmltooling/signature/impl/KeyInfoSchemaValidators.cpp @@ -32,6 +32,19 @@ using namespace std; using xmlconstants::XMLSIG_NS; using xmlconstants::XMLSIG11_NS; +#define XMLOBJECTVALIDATOR_ONLYONEOF4(cname,proper1,proper2,proper3,proper4) \ + int c##proper1##proper2##proper3##proper4=0; \ + if (ptr->get##proper1()!=nullptr) \ + c##proper1##proper2##proper3##proper4++; \ + if (ptr->get##proper2()!=nullptr) \ + c##proper1##proper2##proper3##proper4++; \ + if (ptr->get##proper3()!=nullptr) \ + c##proper1##proper2##proper3##proper4++; \ + if (ptr->get##proper4()!=nullptr) \ + c##proper1##proper2##proper3##proper4++; \ + if (c##proper1##proper2##proper3##proper4 != 1) \ + throw xmltooling::ValidationException(#cname" must have only one of "#proper1", "#proper2", "#proper3", or "#proper4".") + namespace xmlsignature { XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,KeyName); @@ -72,7 +85,7 @@ namespace xmlsignature { END_XMLOBJECTVALIDATOR; BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,KeyValue); - XMLOBJECTVALIDATOR_ONLYONEOF3(KeyValue,DSAKeyValue,RSAKeyValue,UnknownXMLObject); + XMLOBJECTVALIDATOR_ONLYONEOF4(KeyValue,DSAKeyValue,RSAKeyValue,ECKeyValue,UnknownXMLObject); END_XMLOBJECTVALIDATOR; BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,Transform); diff --git a/xmltoolingtest/KeyInfoTest.h b/xmltoolingtest/KeyInfoTest.h index 3ebae4c..26b8579 100644 --- a/xmltoolingtest/KeyInfoTest.h +++ b/xmltoolingtest/KeyInfoTest.h @@ -92,4 +92,25 @@ public: TS_ASSERT(kiObject.get()!=nullptr); TS_ASSERT_THROWS(SchemaValidators.validate(kiObject.get()),ValidationException); } + + void testKeyInfo4() { + string path=data_path + "KeyInfo4.xml"; + ifstream fs(path.c_str()); + DOMDocument* doc=XMLToolingConfig::getConfig().getValidatingParser().parse(fs); + TS_ASSERT(doc!=nullptr); + + const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement()); + TS_ASSERT(b!=nullptr); + + auto_ptr kiObject(dynamic_cast(b->buildFromDocument(doc))); + TS_ASSERT(kiObject.get()!=nullptr); + TSM_ASSERT_EQUALS("Number of child elements was not expected value", + 1, kiObject->getKeyValues().size()); + ECKeyValue* kv = kiObject->getKeyValues().front()->getECKeyValue(); + TSM_ASSERT("Missing ECKeyValue", kv!=nullptr); + TSM_ASSERT("Missing NamedCurve", kv->getNamedCurve()!=nullptr); + TSM_ASSERT("Missing PublicKey", kv->getPublicKey()!=nullptr); + + SchemaValidators.validate(kiObject.get()); + } }; diff --git a/xmltoolingtest/data/KeyInfo4.xml b/xmltoolingtest/data/KeyInfo4.xml new file mode 100644 index 0000000..90b011e --- /dev/null +++ b/xmltoolingtest/data/KeyInfo4.xml @@ -0,0 +1,11 @@ + + + + + + MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAER9z9tFObV/MdgFT0IDEUq6b8VZFL + sj+qeNjJMVgEIrioShi5HfJfZq/aLuTvt5DZEybsFNC1Fit5cYx7+0DN3g== + + + +