Skip to content

Commit

Permalink
8255548: Missing coverage for javax.xml.crypto.dom.DOMCryptoContext
Browse files Browse the repository at this point in the history
Reviewed-by: goetz
Backport-of: 76cda9f
  • Loading branch information
amosshi authored and GoeLin committed Oct 19, 2023
1 parent abeacbf commit 639afbe
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion test/jdk/javax/xml/crypto/dsig/GenerationTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,6 +30,8 @@
* java.base/sun.security.x509
* java.xml.crypto/org.jcp.xml.dsig.internal.dom
* jdk.httpserver/com.sun.net.httpserver
* @library /test/lib
* @build jdk.test.lib.Asserts
* @compile -XDignore.symbol.file KeySelectors.java SignatureValidator.java
* X509KeySelector.java GenerationTests.java
* @run main/othervm/timeout=300 -Dsun.net.httpserver.nodelay=true GenerationTests
Expand Down Expand Up @@ -92,6 +94,8 @@
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.*;

import jdk.test.lib.Asserts;

/**
* Test that recreates merlin-xmldsig-twenty-three test vectors (and more)
* but with different keys and X.509 data.
Expand Down Expand Up @@ -286,6 +290,7 @@ private static enum KeyInfoType {

public static void main(String args[]) throws Exception {
setup();
test_context_iterator();
test_create_signature_enveloped_dsa(1024);
test_create_signature_enveloped_dsa(2048);
test_create_signature_enveloping_b64_dsa();
Expand Down Expand Up @@ -1863,6 +1868,48 @@ static boolean test_create_detached_signature0(String canonicalizationMethod,
return true;
}

static boolean test_context_iterator() throws Exception {
System.out.println("Testing context iterator() method.");

Reference ref = fac.newReference("#object",
fac.newDigestMethod(DigestMethod.SHA512, null));
SignedInfo si = fac.newSignedInfo(withoutComments, rsaSha512,
Collections.singletonList(ref));

Document doc = db.newDocument();
XMLObject obj = fac.newXMLObject(Collections.singletonList(
new DOMStructure(doc.createTextNode("test text"))), "object",
null, null);

DOMSignContext dsc = new DOMSignContext(signingKey, doc);
Asserts.assertNotNull(dsc.iterator());
Asserts.assertFalse(dsc.iterator().hasNext());

String namespaceURI = "https://example.com/ns";
String idAttrValue = "id1";
String elementQualifiedName = "test:data";

Element elm = doc.createElementNS(namespaceURI, elementQualifiedName);
elm.setAttributeNS(namespaceURI, "test:id", idAttrValue);
dsc.setIdAttributeNS(elm, namespaceURI, "id");

Iterator<Map.Entry<String, Element>> iter = dsc.iterator();
Asserts.assertTrue(dsc.iterator().hasNext());

Map.Entry<String, Element> element = iter.next();
Asserts.assertEquals(element.getKey(), idAttrValue);
Asserts.assertEquals(element.getValue().getNodeName(), elementQualifiedName);

try {
iter.remove();
throw new RuntimeException(
"The expected UnsupportedOperationException was not thrown.");
} catch (UnsupportedOperationException exc) {
// this is expected
}
return true;
}

private static Key[] getCachedKeys(String signatureMethod) {
return cachedKeys.computeIfAbsent(signatureMethod, sm -> {
try {
Expand Down

0 comments on commit 639afbe

Please sign in to comment.