Skip to content

Commit 639afbe

Browse files
amosshiGoeLin
authored andcommitted
8255548: Missing coverage for javax.xml.crypto.dom.DOMCryptoContext
Reviewed-by: goetz Backport-of: 76cda9f44a80b1979e6e1b7a21431ef631f80782
1 parent abeacbf commit 639afbe

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

test/jdk/javax/xml/crypto/dsig/GenerationTests.java

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,8 @@
3030
* java.base/sun.security.x509
3131
* java.xml.crypto/org.jcp.xml.dsig.internal.dom
3232
* jdk.httpserver/com.sun.net.httpserver
33+
* @library /test/lib
34+
* @build jdk.test.lib.Asserts
3335
* @compile -XDignore.symbol.file KeySelectors.java SignatureValidator.java
3436
* X509KeySelector.java GenerationTests.java
3537
* @run main/othervm/timeout=300 -Dsun.net.httpserver.nodelay=true GenerationTests
@@ -92,6 +94,8 @@
9294
import javax.xml.transform.stream.StreamResult;
9395
import org.w3c.dom.*;
9496

97+
import jdk.test.lib.Asserts;
98+
9599
/**
96100
* Test that recreates merlin-xmldsig-twenty-three test vectors (and more)
97101
* but with different keys and X.509 data.
@@ -286,6 +290,7 @@ private static enum KeyInfoType {
286290

287291
public static void main(String args[]) throws Exception {
288292
setup();
293+
test_context_iterator();
289294
test_create_signature_enveloped_dsa(1024);
290295
test_create_signature_enveloped_dsa(2048);
291296
test_create_signature_enveloping_b64_dsa();
@@ -1863,6 +1868,48 @@ static boolean test_create_detached_signature0(String canonicalizationMethod,
18631868
return true;
18641869
}
18651870

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+
18661913
private static Key[] getCachedKeys(String signatureMethod) {
18671914
return cachedKeys.computeIfAbsent(signatureMethod, sm -> {
18681915
try {

0 commit comments

Comments
 (0)