package test.at.gv.egovernment.moa.id.auth.builder; import java.io.FileInputStream; import java.io.RandomAccessFile; import org.w3c.dom.Element; import test.at.gv.egovernment.moa.id.auth.invoke.MOASPSSTestCase; import at.gv.egovernment.moa.id.auth.builder.VerifyXMLSignatureRequestBuilder; import at.gv.egovernment.moa.id.auth.data.CreateXMLSignatureResponse; import at.gv.egovernment.moa.id.auth.data.IdentityLink; import at.gv.egovernment.moa.id.auth.parser.CreateXMLSignatureResponseParser; import at.gv.egovernment.moa.id.auth.parser.InfoboxReadResponseParser; import at.gv.egovernment.moa.id.auth.invoke.SignatureVerificationInvoker; import at.gv.egovernment.moa.id.config.ConfigurationProvider; import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProvider; /** * Test case for the signature verification web service. * * This test requires a running SignatureVerification web service. * * @author Stefan Knirsch * @version $Id$ */ public class VerifyXMLSignatureRequestBuilderTest extends MOASPSSTestCase { private SignatureVerificationInvoker caller; public VerifyXMLSignatureRequestBuilderTest(String name) { super(name); } public void setUp() { System.setProperty( ConfigurationProvider.CONFIG_PROPERTY_NAME, "data/test/conf/ConfigurationTest.xml"); caller = new SignatureVerificationInvoker(); } public void testVerifyXMLSignatureRequestBuilderIdentityLink() throws Exception { RandomAccessFile infoBox = new RandomAccessFile( "data/test/xmldata/testperson1/InfoboxReadResponse.xml","r"); byte[] b = new byte[(int) infoBox.length()]; infoBox.read(b); infoBox.close(); String xmlInfoboxReadResponse = new String(b, "UTF-8"); RandomAccessFile vr = new RandomAccessFile( "data/test/xmldata/standard/VerifyXMLSignatureRequestIdentityLink.xml","r"); b = new byte[(int) vr.length()]; vr.read(b); vr.close(); String xmlResponse = new String(b, "UTF-8"); InfoboxReadResponseParser irrp = new InfoboxReadResponseParser(xmlInfoboxReadResponse); IdentityLink idl = irrp.parseIdentityLink(); VerifyXMLSignatureRequestBuilder vsrb = new VerifyXMLSignatureRequestBuilder(); AuthConfigurationProvider authConf = AuthConfigurationProvider.getInstance(); Element requestBuild = vsrb.build(idl, authConf.getMoaSpIdentityLinkTrustProfileID()); assertXmlEquals(requestBuild, xmlResponse); } public void testVerifyXMLSignature2() throws Exception { RandomAccessFile s = new RandomAccessFile("data/test/xmldata/standard/CreateXMLSignatureResponse.xml","r"); byte[] b = new byte[(int) s.length()]; s.read(b); s.close(); String xmlCreateXMLSignatureResponse = new String(b, "UTF-8"); CreateXMLSignatureResponseParser cXMLsrp = new CreateXMLSignatureResponseParser(xmlCreateXMLSignatureResponse); CreateXMLSignatureResponse csr = cXMLsrp.parseResponse(); VerifyXMLSignatureRequestBuilder vsrb = new VerifyXMLSignatureRequestBuilder(); AuthConfigurationProvider authConf = AuthConfigurationProvider.getInstance(); Element request = vsrb.build(csr, authConf.getMoaSpAuthBlockVerifyTransformsInfoIDs(), authConf.getMoaSpIdentityLinkTrustProfileID()); // check the result assertXmlEquals(request, new FileInputStream("data/test/xmldata/standard/VerifyXMLSignatureRequestCreateXML.xml")); } }