diff options
author | mcentner <mcentner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2010-01-26 16:27:04 +0000 |
---|---|---|
committer | mcentner <mcentner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2010-01-26 16:27:04 +0000 |
commit | 667af128d0adfeee2aa4748ab58411c91bc4905f (patch) | |
tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /mocca-1.2.11/utils/src/test/java | |
parent | d89f36b67ea1d838a78523538a24e044518f3587 (diff) | |
download | mocca-667af128d0adfeee2aa4748ab58411c91bc4905f.tar.gz mocca-667af128d0adfeee2aa4748ab58411c91bc4905f.tar.bz2 mocca-667af128d0adfeee2aa4748ab58411c91bc4905f.zip |
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/branches/mocca-1.2.11-sha2@600 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'mocca-1.2.11/utils/src/test/java')
8 files changed, 0 insertions, 918 deletions
diff --git a/mocca-1.2.11/utils/src/test/java/at/gv/egiz/bku/utils/HexDumpTest.java b/mocca-1.2.11/utils/src/test/java/at/gv/egiz/bku/utils/HexDumpTest.java deleted file mode 100644 index 5d1a0fcf..00000000 --- a/mocca-1.2.11/utils/src/test/java/at/gv/egiz/bku/utils/HexDumpTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package at.gv.egiz.bku.utils;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Random;
-
-import org.junit.Test;
-
-public class HexDumpTest {
-
- @Test
- public void testHexDump() throws IOException {
-
- byte[] bytes = new byte[734];
- int i = 0;
- for (; i < 256; i++) {
- bytes[i] = (byte) i;
- }
-
- Random random = new Random();
- for (; i < bytes.length; i++) {
- bytes[i] = (byte) random.nextInt();
- }
-
- PrintWriter writer = new PrintWriter(System.out);
- HexDump.hexDump(new ByteArrayInputStream(bytes), writer, 32);
- writer.flush();
-
- }
-
-
-}
diff --git a/mocca-1.2.11/utils/src/test/java/at/gv/egiz/bku/utils/URLEncodingOutputStreamTest.java b/mocca-1.2.11/utils/src/test/java/at/gv/egiz/bku/utils/URLEncodingOutputStreamTest.java deleted file mode 100644 index e92b9584..00000000 --- a/mocca-1.2.11/utils/src/test/java/at/gv/egiz/bku/utils/URLEncodingOutputStreamTest.java +++ /dev/null @@ -1,147 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package at.gv.egiz.bku.utils;
-
-import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.StringWriter; -import java.io.Writer; -import java.net.URLEncoder; -import java.nio.charset.Charset; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -
-public class URLEncodingOutputStreamTest {
- - private static String buf; - - private static Charset UTF_8 = Charset.forName("UTF-8"); - - @BeforeClass - public static void setUpClass() throws IOException { - - ClassLoader cl = URLEncodingOutputStreamTest.class.getClassLoader(); - InputStream is = cl.getResourceAsStream("BigRequest.xml"); - - assertNotNull(is); - - InputStreamReader reader = new InputStreamReader(is, UTF_8); - - StringBuilder sb = new StringBuilder(); - - char[] b = new char[512]; - for (int l; (l = reader.read(b)) != -1;) { - sb.append(b, 0, l); - } - - buf = sb.toString(); - - } - - @Test - public void testCompareResults() throws IOException { - - String out1; - String out2; - - // new - StringWriter writer = new StringWriter(); - URLEncodingOutputStream urlEnc = new URLEncodingOutputStream(writer); - OutputStreamWriter streamWriter = new OutputStreamWriter(urlEnc, UTF_8); - streamWriter.append(buf); - streamWriter.flush(); - out1 = writer.toString(); - - // URLEncoder - out2 = URLEncoder.encode(buf, UTF_8.name()); - - for (int i = 0; i < out1.length(); i++) { - if (out1.charAt(i) != out2.charAt(i)) { - System.out.println(i + ": " + out1.substring(i)); - System.out.println(i + ": " + out2.substring(i)); - } - } - - assertEquals(out1, out2); - - } -
- @Ignore - @Test - public void testURLEncodingOutputStream() throws IOException {
- - NullWriter writer = new NullWriter(); - - URLEncodingOutputStream urlEnc = new URLEncodingOutputStream(writer); - OutputStreamWriter streamWriter = new OutputStreamWriter(urlEnc, UTF_8); - - long t0, t1, dt = 0; - for (int run = 0; run < 1000; run++) { - t0 = System.currentTimeMillis(); - streamWriter.append(buf); - t1 = System.currentTimeMillis(); - if (run > 1) { - dt += t1 - t0; - } - }
- System.out.println("Time " + dt + "ms"); -
- }
- - @Ignore - @Test - public void testURLEncodingNaive() throws IOException { - - String in = new String(buf); - - long t0, t1, dt = 0; - for (int run = 0; run < 1000; run++) { - t0 = System.currentTimeMillis(); - URLEncoder.encode(in, "UTF-8"); - t1 = System.currentTimeMillis(); - if (run > 1) { - dt += t1 - t0; - } - } - System.out.println("Time (naive) " + dt + "ms"); - - } - - public class NullWriter extends Writer { - - @Override - public void close() throws IOException { - } - - @Override - public void flush() throws IOException { - } - - @Override - public void write(char[] cbuf, int off, int len) throws IOException { - } - - }
-
-}
diff --git a/mocca-1.2.11/utils/src/test/java/at/gv/egiz/idlink/CompressIdentityLink.java b/mocca-1.2.11/utils/src/test/java/at/gv/egiz/idlink/CompressIdentityLink.java deleted file mode 100644 index e040d7e8..00000000 --- a/mocca-1.2.11/utils/src/test/java/at/gv/egiz/idlink/CompressIdentityLink.java +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package at.gv.egiz.idlink;
-
-import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -import javax.xml.bind.JAXBException; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; - -import at.buergerkarte.namespaces.personenbindung._20020506_.CompressedIdentityLinkType; -import at.gv.egiz.idlink.ans1.IdentityLink; -
-public class CompressIdentityLink {
-
- /**
- * @param args
- * @throws JAXBException
- * @throws IOException
- */
- public static void main(String[] args) throws JAXBException, IOException {
-
- FileInputStream fis = new FileInputStream(args[0]);
- Source source = new StreamSource(fis);
-
- CompressedIdentityLinkFactory factory = CompressedIdentityLinkFactory.getInstance();
-
- CompressedIdentityLinkType compressedIdentity = factory.unmarshallCompressedIdentityLink(source);
-
- IdentityLink idLink = factory.createIdLink(compressedIdentity);
-
- FileOutputStream outputStream = new FileOutputStream("idlink.bin");
- outputStream.write(idLink.toByteArray());
- outputStream.close();
-
- }
-
-}
diff --git a/mocca-1.2.11/utils/src/test/java/at/gv/egiz/idlink/IdentityLink.java b/mocca-1.2.11/utils/src/test/java/at/gv/egiz/idlink/IdentityLink.java deleted file mode 100644 index a97a468e..00000000 --- a/mocca-1.2.11/utils/src/test/java/at/gv/egiz/idlink/IdentityLink.java +++ /dev/null @@ -1,153 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package at.gv.egiz.idlink; - -import iaik.xml.crypto.XSecProvider; - -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.InvalidAlgorithmParameterException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.security.spec.InvalidKeySpecException; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Enumeration; -import java.util.List; - -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.crypto.MarshalException; -import javax.xml.crypto.dsig.XMLSignatureException; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import oasis.names.tc.saml._1_0.assertion.AssertionType; -import oasis.names.tc.saml._1_0.assertion.AttributeStatementType; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.w3c.dom.Document; - -import at.gv.egiz.xmldsig.KeyTypeNotSupportedException; - -public class IdentityLink { - - private static String keyStoreType = "PKCS12"; - - private static String keyStoreFile = "at/gv/egiz/idlink/IdentityLinkTest.p12"; - - private static String keyStorePassword = "mocca"; - - private static String[] certificateFiles = new String [] { - "at/gv/egiz/idlink/certified.cer", - "at/gv/egiz/idlink/secure.cer" - }; - - private static PublicKey[] publicKeys; - - private static X509Certificate signerCert; - - private static PrivateKey signerKey; - - @BeforeClass - public static void setupClass() throws NoSuchAlgorithmException, IOException, - InvalidKeySpecException, KeyStoreException, CertificateException, - UnrecoverableKeyException { - - XSecProvider.addAsProvider(false); - - ClassLoader classLoader = IdentityLink.class.getClassLoader(); - - CertificateFactory certificateFactory = CertificateFactory.getInstance("X509"); - - List<PublicKey> keys = new ArrayList<PublicKey>(); - for (String certificateFile : certificateFiles) { - - InputStream certStream = classLoader.getResourceAsStream(certificateFile); - X509Certificate cert = (X509Certificate) certificateFactory.generateCertificate(certStream); - keys.add(cert.getPublicKey()); - - } - - publicKeys = keys.toArray(new PublicKey[0]); - - KeyStore keyStore = KeyStore.getInstance(keyStoreType); - keyStore.load(classLoader.getResourceAsStream(keyStoreFile), keyStorePassword.toCharArray()); - - Enumeration<String> aliases = keyStore.aliases(); - while (aliases.hasMoreElements()) { - String alias = (String) aliases.nextElement(); - if (keyStore.isKeyEntry(alias)) { - signerKey = (PrivateKey) keyStore.getKey(alias, keyStorePassword.toCharArray()); - signerCert = (X509Certificate) keyStore.getCertificate(alias); - } - } - - - } - - @Test - public void testCreateIdentityLink() throws KeyTypeNotSupportedException, ParserConfigurationException, JAXBException, TransformerException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, XMLSignatureException, MarshalException, FileNotFoundException { - - IdentityLinkFactory factory = IdentityLinkFactory.getInstance(); - - AttributeStatementType attributeStatement = factory.createAttributeStatement( - "3utiDdA4KaodrJOeMqu9PA==", - "urn:publicid:gv.at:baseid", - "Max Moritz", - "Mustermann-Fall", - "1900-01-01", - publicKeys - ); - - Calendar calendar = Calendar.getInstance(); - calendar.clear(); - calendar.set(2007, 8, 29, 18, 0, 0); - - JAXBElement<AssertionType> assertion = factory.createAssertion( - "bka.gv.at-2007-08-29T16.41.17.442", - calendar.getTime(), - "http://www.bka.gv.at/datenschutz/Stammzahlenregisterbehoerde", - 1L, - 0L, - attributeStatement); - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - Document doc = dbf.newDocumentBuilder().newDocument(); - - factory.marshallIdentityLink(assertion, doc, null); - - factory.signIdentityLink(doc.getDocumentElement(), signerCert, signerKey); - - } - -} diff --git a/mocca-1.2.11/utils/src/test/java/at/gv/egiz/slbinding/RedirectTest.java b/mocca-1.2.11/utils/src/test/java/at/gv/egiz/slbinding/RedirectTest.java deleted file mode 100644 index 7c8c206a..00000000 --- a/mocca-1.2.11/utils/src/test/java/at/gv/egiz/slbinding/RedirectTest.java +++ /dev/null @@ -1,219 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package at.gv.egiz.slbinding; - -import at.buergerkarte.namespaces.securitylayer._1.Base64XMLLocRefOptRefContentType; -import javax.xml.bind.JAXBException; - -import org.junit.Before; -import org.junit.Test; - -import at.buergerkarte.namespaces.securitylayer._1.CreateXMLSignatureRequestType; -import at.buergerkarte.namespaces.securitylayer._1.DataObjectAssociationType; -import at.buergerkarte.namespaces.securitylayer._1.DataObjectInfoType; -import at.buergerkarte.namespaces.securitylayer._1.MetaInfoType; -import at.buergerkarte.namespaces.securitylayer._1.SignatureInfoCreationType; -import at.buergerkarte.namespaces.securitylayer._1.TransformsInfoType; -import at.gv.egiz.slbinding.impl.SignatureLocationType; -import at.gv.egiz.slbinding.impl.XMLContentType; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Iterator; -import java.util.List; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.namespace.NamespaceContext; -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLInputFactory; - -import static org.junit.Assert.*; -import org.w3._2000._09.xmldsig_.TransformType; -import org.w3._2000._09.xmldsig_.TransformsType; - -/** - * - * @author clemens - */ -public class RedirectTest { - - public static final String FILENAME_REQ = "src/test/requests/CreateXMLSignatureRequest02.xml"; - public static final String FILENAME_REQ_SCHEMA = "src/main/schema/Core-1.2.xsd"; - - /** - * Context path for unmarshaller (colon separated list of generated packages) - */ - @Before - public void setUp() throws JAXBException { - } - - @Test - public void testRedirect() { - try { - String slPkg = at.buergerkarte.namespaces.securitylayer._1.ObjectFactory.class.getPackage().getName(); - String dsigPkg = org.w3._2000._09.xmldsig_.ObjectFactory.class.getPackage().getName(); - - JAXBContext jaxbContext = JAXBContext.newInstance(slPkg + ":" + dsigPkg); - Unmarshaller um = jaxbContext.createUnmarshaller(); - -// SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); -// File schemaFile = new File(FILENAME_REQ_SCHEMA); -// Schema TestRequestLaxSchema = schemaFactory.newSchema(schemaFile); -// // validate request -// um.setSchema(TestRequestLaxSchema); - - - FileInputStream fis = new FileInputStream(FILENAME_REQ); - InputStream is = new BufferedInputStream(fis); - - XMLInputFactory inputFactory = XMLInputFactory.newInstance(); - XMLEventReader reader = inputFactory.createXMLEventReader(is); - final RedirectEventFilter contentFilter = new RedirectEventFilter(); - XMLEventReader filteredReader = inputFactory.createFilteredReader(reader, contentFilter); - - um.setListener(new RedirectUnmarshallerListener(contentFilter)); - -// List<Class> redirectTriggers = Arrays.asList(new Class[]{XMLContentType.class, TransformsType.class}); -// Set<Class<? extends RedirectCallback>> redirectTriggers = new HashSet<Class<? extends RedirectCallback>>(); //{XMLContentType.class, TransformsType.class -// redirectTriggers.add(XMLContentType.class); -// redirectTriggers.add(TransformsType.class); -// ByteArrayRedirectCallback.registerRedirectTriggers(redirectTriggers); -// -// Set<Class<? extends RedirectCallback>> preserveNSContextTriggers = new HashSet<Class<? extends RedirectCallback>>(); -//// preserveNSContextTriggers.add(TransformsType.class); -// preserveNSContextTriggers.add(SignatureInfoCreationType.SignatureLocation.class); -// ByteArrayRedirectCallback.registerPreserveContextTriggers(preserveNSContextTriggers); - - JAXBElement<CreateXMLSignatureRequestType> req = (JAXBElement<CreateXMLSignatureRequestType>) um.unmarshal(filteredReader); - is.close(); - - FileOutputStream fos = new FileOutputStream(FILENAME_REQ + "_redirect.txt"); - OutputStream os = new BufferedOutputStream(fos); - - CreateXMLSignatureRequestType request = req.getValue(); - List<DataObjectInfoType> dataObjectInfos = request.getDataObjectInfo(); - Iterator<DataObjectInfoType> doiIt = dataObjectInfos.iterator(); - while (doiIt.hasNext()) { - DataObjectInfoType doi = doiIt.next(); - Base64XMLLocRefOptRefContentType dataObj = doi.getDataObject(); - XMLContentType dataObjXML = (XMLContentType) dataObj.getXMLContent(); - if (dataObjXML != null) { - System.out.println("found at.gv.egiz.slbinding.impl.XMLContentType DataObject"); - ByteArrayOutputStream xmlContent = dataObjXML.getRedirectedStream(); - assertNotNull(xmlContent); - os.write(xmlContent.toByteArray()); - os.write("\n\n\n".getBytes()); - } - - List<TransformsInfoType> transformsInfos = doi.getTransformsInfo(); - Iterator<TransformsInfoType> tiIt = transformsInfos.iterator(); - while (tiIt.hasNext()) { - at.gv.egiz.slbinding.impl.TransformsInfoType ti = (at.gv.egiz.slbinding.impl.TransformsInfoType) tiIt.next(); -// TransformsInfoType ti = tiIt.next(); - assertNotNull(ti); - System.out.println("found sl:TransformsInfo: " + ti.getClass().getName()); //at.gv.egiz.slbinding.impl.TransformsInfoType TransformsInfo"); -// TransformsType ts = ti.getTransforms(); -// assertNotNull(ts); -// System.out.println("found dsig:Transforms " + ts.getClass().getName()); //org.w3._2000._09.xmldsig_.TransformsType dsig:Transforms"); -// List<TransformType> tL = ts.getTransform(); -// assertNotNull(tL); -// System.out.println("found " + tL.size() + " org.w3._2000._09.xmldsig_.TransformType dsig:Transform"); -// for (TransformType t : tL) { -// if (t instanceof at.gv.egiz.slbinding.impl.TransformType) { -// System.out.println("found at.gv.egiz.slbinding.impl.TransformType"); -// byte[] redirectedBytes = ((at.gv.egiz.slbinding.impl.TransformType) t).getRedirectedStream().toByteArray(); -// if (redirectedBytes != null && redirectedBytes.length > 0) { -// System.out.println("reading redirected stream..."); -// os.write("--- redirected Transform ---".getBytes()); -// os.write(redirectedBytes); -// os.write("\n".getBytes()); -// } else { -// System.out.println("no redirected stream"); -// } -// } -// } - - ByteArrayOutputStream dsigTransforms = ti.getRedirectedStream(); - os.write("--- redirected TransformsInfo content ---".getBytes()); - os.write(dsigTransforms.toByteArray()); - os.write("\n---".getBytes()); - - MetaInfoType mi = ti.getFinalDataMetaInfo(); - assertNotNull(mi); - assertNull(ti.getTransforms()); - - } - List<DataObjectAssociationType> supplements = doi.getSupplement(); - if (supplements != null) { - Iterator<DataObjectAssociationType> doaIt = supplements.iterator(); - while (doaIt.hasNext()) { - System.out.println("found Supplement"); - } - } - } - SignatureInfoCreationType si = request.getSignatureInfo(); - if (si != null) { -// Base64XMLOptRefContentType sigEnv = si.getSignatureEnvironment(); -// XMLContentType sigEnvXML = sigEnv.getXMLContent(); -// if (sigEnvXML != null) { -// System.out.println("found SignatureEnvironment XMLContent"); -// ByteArrayOutputStream xmlContent = sigEnvXML.getRedirectedStream(); -// os.write(xmlContent.toByteArray()); -// os.write("\n".getBytes()); -// } -// -// SignatureInfoCreationType.SignatureLocation sigLocation = si.getSignatureLocation(); - SignatureLocationType sigLocation = (SignatureLocationType) si.getSignatureLocation(); - assertNotNull(sigLocation); - System.out.println("found at.gv.egiz.slbinding.impl.SignatureLocationType SignatureLocation"); - - NamespaceContext ctx = sigLocation.getNamespaceContext(); - assertNotNull(ctx); - String samlNS = ctx.getNamespaceURI("saml"); - assertEquals(samlNS, "urn:oasis:names:tc:SAML:2.0:assertion"); - System.out.println("found preserved namespace xmlns:saml " + samlNS); - - } - os.flush(); - os.close(); - - fos = new FileOutputStream(FILENAME_REQ + "_bound.xml"); - os = new BufferedOutputStream(fos); - - Marshaller m = jaxbContext.createMarshaller(); - m.marshal(req, os); - - os.flush(); - os.close(); - - } catch (Exception ex) { - ex.printStackTrace(); - } - - - } -} diff --git a/mocca-1.2.11/utils/src/test/java/at/gv/egiz/urldereferencer/FormDataTest.java b/mocca-1.2.11/utils/src/test/java/at/gv/egiz/urldereferencer/FormDataTest.java deleted file mode 100644 index ecd4c8f7..00000000 --- a/mocca-1.2.11/utils/src/test/java/at/gv/egiz/urldereferencer/FormDataTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package at.gv.egiz.urldereferencer;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-
-import org.junit.Before;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-import at.gv.egiz.bku.utils.StreamUtil;
-import at.gv.egiz.bku.utils.urldereferencer.FormDataURLSupplier;
-import at.gv.egiz.bku.utils.urldereferencer.SimpleFormDataContextImpl;
-import at.gv.egiz.bku.utils.urldereferencer.StreamData;
-import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer;
-import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerContext;
-
-public class FormDataTest implements FormDataURLSupplier {
-
- protected URLDereferencerContext urlCtx;
- protected InputStream testStream = null;
- protected String contentType = null;
- protected String paramName = "";
-
- @Override
- public InputStream getFormData(String parameterName) {
- if (paramName.equals(parameterName)) {
- return testStream;
- } else {
- return null;
- }
- }
-
- @Override
- public String getFormDataContentType(String parameterName) {
- if (paramName.equals(parameterName)) {
- return contentType;
- } else {
- return null;
- }
- }
-
- @Before
- public void setUp() {
- urlCtx = new SimpleFormDataContextImpl(this);
- }
-
- @Test(expected = MalformedURLException.class)
- public void testInvalidFormdataUrl() throws IOException {
- String url = "abs://whatknowi";
- StreamData sd = URLDereferencer.getInstance().dereference(url, urlCtx);
- assertNull(sd);
- url = ":://whatknowi";
- sd = URLDereferencer.getInstance().dereference(url, urlCtx);
- assertNull(sd);
- url = "";
- sd = URLDereferencer.getInstance().dereference(url, urlCtx);
- }
-
- @Test
- public void testFormData() throws IOException {
- paramName = "Müllcontainer";
- testStream = new ByteArrayInputStream("HelloWorld".getBytes("UTF-8"));
- String url = "formdata:"+paramName;
- StreamData sd = URLDereferencer.getInstance().dereference(url, urlCtx);
- assertNotNull(sd);
- String result = StreamUtil.asString(sd.getStream(), "UTF-8");
- assertEquals("HelloWorld", result);
- } - - @Test(expected=IOException.class) - public void testFormDataNotFound() throws IOException { - paramName = "Müllcontainer"; - testStream = new ByteArrayInputStream("HelloWorld".getBytes("UTF-8")); - String url = "formdata:"+paramName+"2"; - StreamData sd = URLDereferencer.getInstance().dereference(url, urlCtx); - } -
-}
diff --git a/mocca-1.2.11/utils/src/test/java/cardchannel/UnmarshalTest.java b/mocca-1.2.11/utils/src/test/java/cardchannel/UnmarshalTest.java deleted file mode 100644 index 998dd9e6..00000000 --- a/mocca-1.2.11/utils/src/test/java/cardchannel/UnmarshalTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package cardchannel; - -import at.buergerkarte.namespaces.cardchannel.ObjectFactory; -import at.buergerkarte.namespaces.cardchannel.ResetType; -import at.buergerkarte.namespaces.cardchannel.ScriptType; -import java.io.File; -import java.io.FileNotFoundException; -import java.util.List; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import org.junit.Ignore; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at> - */ -public class UnmarshalTest { - - @Test - public void unmarshalScript() throws FileNotFoundException, JAXBException { - JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class); - Unmarshaller um = ctx.createUnmarshaller(); - - JAXBElement<ScriptType> script = (JAXBElement<ScriptType>) um.unmarshal(new File("src/test/cardchannel/script.xml")); - - ScriptType scriptT = script.getValue(); - System.out.println("script " + scriptT.getClass()); - List<Object> resetOrCommandAPDUOrVerifyAPDU = scriptT.getResetOrCommandAPDUOrVerifyAPDU(); -// assertEquals(3, resetOrCommandAPDUOrVerifyAPDU.size()); - for (Object object : resetOrCommandAPDUOrVerifyAPDU) { - System.out.println("script contains: " + object.getClass()); - } - } - - @Test - @Ignore - public void marshalScript() throws JAXBException { - JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class); - Marshaller m = ctx.createMarshaller(); - - ObjectFactory of = new ObjectFactory(); - ResetType r = of.createResetType(); - ScriptType s = of.createScriptType(); - s.getResetOrCommandAPDUOrVerifyAPDU().add(r); - JAXBElement<ScriptType> script = of.createScript(s); - - m.marshal(script, new File("src/test/cardchannel/marshalled.xml")); - - } -} diff --git a/mocca-1.2.11/utils/src/test/java/saml/KeyValueAttributeTypeTest.java b/mocca-1.2.11/utils/src/test/java/saml/KeyValueAttributeTypeTest.java deleted file mode 100644 index 2df04ce6..00000000 --- a/mocca-1.2.11/utils/src/test/java/saml/KeyValueAttributeTypeTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package saml; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.util.List; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.namespace.QName; -import oasis.names.tc.saml._1_0.assertion.AnyType; -import oasis.names.tc.saml._1_0.assertion.AssertionType; -import oasis.names.tc.saml._1_0.assertion.AttributeStatementType; -import oasis.names.tc.saml._1_0.assertion.AttributeType; -import oasis.names.tc.saml._1_0.assertion.NameIdentifierType; -import oasis.names.tc.saml._1_0.assertion.ObjectFactory; -import oasis.names.tc.saml._1_0.assertion.StatementAbstractType; -import oasis.names.tc.saml._1_0.assertion.SubjectType; -import org.junit.Ignore; -import org.junit.Test; -import org.w3._2000._09.xmldsig_.KeyValueType; -import org.w3._2000._09.xmldsig_.RSAKeyValueType; -import org.w3c.dom.Element; - -/** - * - * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at> - */ -@Ignore -public class KeyValueAttributeTypeTest { - - @Test - public void testAttrStatement() throws FileNotFoundException, JAXBException { - JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class, org.w3._2000._09.xmldsig_.ObjectFactory.class); - Unmarshaller um = ctx.createUnmarshaller(); - - JAXBElement<AssertionType> assertion = (JAXBElement<AssertionType>) um.unmarshal(new File("/home/clemens/workspace/schema-base/src/main/schema/test/saml10.xml")); - List<StatementAbstractType> statements = assertion.getValue().getStatementOrSubjectStatementOrAuthenticationStatement(); - for (StatementAbstractType stmt : statements) { - if (stmt instanceof AttributeStatementType) { - System.out.println("AttributeStatement"); - List<AttributeType> attrs = ((AttributeStatementType) stmt).getAttribute(); - for (AttributeType attr : attrs) { - List<AnyType> attrValue = attr.getAttributeValue(); - System.out.println(attrValue.size() + " AttributeValue(s)"); - for (AnyType attrValueT : attrValue) { - List<Object> attrValueContent = attrValueT.getContent(); - System.out.println(" AttributeValue: " + attrValueContent.size() + " child nodes"); - for (Object node : attrValueContent) { - if (node instanceof String) { - System.out.println(" - CDATA: " + node); - } else if (node instanceof Element) { - System.out.println(" - DOM Element: " + ((Element)node).getTagName()); - } else { - System.out.println(" - " + node.getClass()); - } - } - } - - } - } - } - } - - @Test - public void testAttributeStatement() throws JAXBException { - - org.w3._2000._09.xmldsig_.ObjectFactory dsOF = new org.w3._2000._09.xmldsig_.ObjectFactory(); - RSAKeyValueType rsaKeyValueType = dsOF.createRSAKeyValueType(); - rsaKeyValueType.setExponent("1234".getBytes()); - rsaKeyValueType.setModulus("5678".getBytes()); - - JAXBElement<RSAKeyValueType> rsaKeyValue = dsOF.createRSAKeyValue(rsaKeyValueType); - - -// KeyValueType kvT = dsOF.createKeyValueType(); -// kvT.getContent().add(rsaKeyValue); -// JAXBElement<KeyValueType> kv = dsOF.createKeyValue(kvT); - - ObjectFactory saml10OF = new ObjectFactory(); - AssertionType assertionT = saml10OF.createAssertionType(); - - AttributeStatementType attrStatementT = saml10OF.createAttributeStatementType(); - NameIdentifierType nameIdT = saml10OF.createNameIdentifierType(); - nameIdT.setFormat("format"); - nameIdT.setNameQualifier("qualifier"); - nameIdT.setValue("value"); - JAXBElement<NameIdentifierType> subjNameId = saml10OF.createNameIdentifier(nameIdT); - SubjectType subjT = saml10OF.createSubjectType(); - subjT.getContent().add(subjNameId); - attrStatementT.setSubject(subjT); - - - AttributeType attrT = saml10OF.createAttributeType(); -// QName keyVal = new QName("testNS", "keyVal"); - attrT.setAttributeName("RSAkeyvalue"); - attrT.setAttributeNamespace("lskdfjlk"); - AnyType attrValueT = saml10OF.createAnyType(); - attrValueT.getContent().add(rsaKeyValue); - attrT.getAttributeValue().add(attrValueT); //kv); //keyValue); //new JAXBElement(keyVal, declaredType, attrT)) - attrStatementT.getAttribute().add(attrT); - assertionT.getStatementOrSubjectStatementOrAuthenticationStatement().add(attrStatementT); - JAXBElement<AssertionType> assertion = saml10OF.createAssertion(assertionT); - - JAXBContext ctx = JAXBContext.newInstance(saml10OF.getClass()); - Marshaller m = ctx.createMarshaller(); - m.marshal(assertion, System.out); - } -} |