|
1 | 1 | /* |
2 | | - * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
30 | 30 | * java.base/sun.security.x509 |
31 | 31 | * java.xml.crypto/org.jcp.xml.dsig.internal.dom |
32 | 32 | * jdk.httpserver/com.sun.net.httpserver |
| 33 | + * @library /test/lib |
| 34 | + * @build jdk.test.lib.Asserts |
33 | 35 | * @compile -XDignore.symbol.file KeySelectors.java SignatureValidator.java |
34 | 36 | * X509KeySelector.java GenerationTests.java |
35 | 37 | * @run main/othervm/timeout=300 -Dsun.net.httpserver.nodelay=true GenerationTests |
|
92 | 94 | import javax.xml.transform.stream.StreamResult; |
93 | 95 | import org.w3c.dom.*; |
94 | 96 |
|
| 97 | +import jdk.test.lib.Asserts; |
| 98 | + |
95 | 99 | /** |
96 | 100 | * Test that recreates merlin-xmldsig-twenty-three test vectors (and more) |
97 | 101 | * but with different keys and X.509 data. |
@@ -286,6 +290,7 @@ private static enum KeyInfoType { |
286 | 290 |
|
287 | 291 | public static void main(String args[]) throws Exception { |
288 | 292 | setup(); |
| 293 | + test_context_iterator(); |
289 | 294 | test_create_signature_enveloped_dsa(1024); |
290 | 295 | test_create_signature_enveloped_dsa(2048); |
291 | 296 | test_create_signature_enveloping_b64_dsa(); |
@@ -1863,6 +1868,48 @@ static boolean test_create_detached_signature0(String canonicalizationMethod, |
1863 | 1868 | return true; |
1864 | 1869 | } |
1865 | 1870 |
|
| 1871 | + static boolean test_context_iterator() throws Exception { |
| 1872 | + System.out.println("Testing context iterator() method."); |
| 1873 | + |
| 1874 | + Reference ref = fac.newReference("#object", |
| 1875 | + fac.newDigestMethod(DigestMethod.SHA512, null)); |
| 1876 | + SignedInfo si = fac.newSignedInfo(withoutComments, rsaSha512, |
| 1877 | + Collections.singletonList(ref)); |
| 1878 | + |
| 1879 | + Document doc = db.newDocument(); |
| 1880 | + XMLObject obj = fac.newXMLObject(Collections.singletonList( |
| 1881 | + new DOMStructure(doc.createTextNode("test text"))), "object", |
| 1882 | + null, null); |
| 1883 | + |
| 1884 | + DOMSignContext dsc = new DOMSignContext(signingKey, doc); |
| 1885 | + Asserts.assertNotNull(dsc.iterator()); |
| 1886 | + Asserts.assertFalse(dsc.iterator().hasNext()); |
| 1887 | + |
| 1888 | + String namespaceURI = "https://example.com/ns"; |
| 1889 | + String idAttrValue = "id1"; |
| 1890 | + String elementQualifiedName = "test:data"; |
| 1891 | + |
| 1892 | + Element elm = doc.createElementNS(namespaceURI, elementQualifiedName); |
| 1893 | + elm.setAttributeNS(namespaceURI, "test:id", idAttrValue); |
| 1894 | + dsc.setIdAttributeNS(elm, namespaceURI, "id"); |
| 1895 | + |
| 1896 | + Iterator<Map.Entry<String, Element>> iter = dsc.iterator(); |
| 1897 | + Asserts.assertTrue(dsc.iterator().hasNext()); |
| 1898 | + |
| 1899 | + Map.Entry<String, Element> element = iter.next(); |
| 1900 | + Asserts.assertEquals(element.getKey(), idAttrValue); |
| 1901 | + Asserts.assertEquals(element.getValue().getNodeName(), elementQualifiedName); |
| 1902 | + |
| 1903 | + try { |
| 1904 | + iter.remove(); |
| 1905 | + throw new RuntimeException( |
| 1906 | + "The expected UnsupportedOperationException was not thrown."); |
| 1907 | + } catch (UnsupportedOperationException exc) { |
| 1908 | + // this is expected |
| 1909 | + } |
| 1910 | + return true; |
| 1911 | + } |
| 1912 | + |
1866 | 1913 | private static Key[] getCachedKeys(String signatureMethod) { |
1867 | 1914 | return cachedKeys.computeIfAbsent(signatureMethod, sm -> { |
1868 | 1915 | try { |
|
0 commit comments