Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 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, 2021, 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 @@ -31,6 +31,7 @@
* 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 @@ -93,6 +94,7 @@
import org.w3c.dom.*;

import jdk.test.lib.security.SecurityUtils;
import jdk.test.lib.Asserts;

/**
* Test that recreates merlin-xmldsig-twenty-three test vectors (and more)
Expand Down Expand Up @@ -292,6 +294,7 @@ public static void main(String args[]) throws Exception {
SecurityUtils.removeAlgsFromDSigPolicy("sha1");

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 @@ -1886,6 +1889,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