Path: blob/master/test/jdk/javax/xml/crypto/dsig/BadXPointer.java
66646 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import jdk.test.lib.Asserts;24import jdk.test.lib.Utils;25import jdk.test.lib.security.XMLUtils;2627import javax.xml.crypto.URIReferenceException;28import javax.xml.crypto.dsig.XMLSignatureException;29import java.security.KeyPair;30import java.security.KeyPairGenerator;31import java.security.spec.ECGenParameterSpec;3233/**34* @test35* @bug 827818636* @summary reject malformed xpointer(id('a')) gracefully37* @library /test/lib38* @modules java.xml.crypto39*/40public class BadXPointer {4142public static void main(String[] args) throws Exception {4344KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");45kpg.initialize(new ECGenParameterSpec("secp256r1"));46KeyPair kp = kpg.generateKeyPair();4748var signer = XMLUtils.signer(kp.getPrivate(), kp.getPublic());49var doc = XMLUtils.string2doc("<root/>");5051// No enclosing ' for id52Utils.runAndCheckException(53() -> signer.signEnveloping(doc, "a", "#xpointer(id('a))"),54ex -> Asserts.assertTrue(ex instanceof XMLSignatureException55&& ex.getCause() instanceof URIReferenceException56&& ex.getMessage().contains("Could not find a resolver"),57ex.toString()));58}59}606162