< prev index next >
test/javax/xml/jaxp/unittest/transform/SecureProcessingTest.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2014, 2015, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2014, 2016, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 21,69 ****
* questions.
*/
package transform;
! import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import javax.xml.XMLConstants;
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.testng.Assert;
import org.testng.annotations.Test;
- import org.w3c.dom.Document;
- import org.xml.sax.SAXException;
/*
* @summary Test XSLT shall report TransformerException for unsafe xsl when FEATURE_SECURE_PROCESSING is true.
*/
public class SecureProcessingTest {
! static boolean _isSecureMode = false;
! static {
! if (System.getSecurityManager() != null) {
! _isSecureMode = true;
! System.out.println("Security Manager is present");
! } else {
! System.out.println("Security Manager is NOT present");
! }
}
!
! @Test
! public final void testSecureProcessing() {
!
// SECURE_PROCESSING == false
// the style sheet
InputStream xslStream = this.getClass().getResourceAsStream("SecureProcessingTest.xsl");
StreamSource xslSource = new StreamSource(xslStream);
--- 21,63 ----
* questions.
*/
package transform;
! import java.io.FilePermission;
import java.io.InputStream;
import java.io.StringWriter;
import javax.xml.XMLConstants;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+ import jaxp.library.JAXPTestUtilities;
+
import org.testng.Assert;
import org.testng.annotations.Test;
/*
* @summary Test XSLT shall report TransformerException for unsafe xsl when FEATURE_SECURE_PROCESSING is true.
*/
+ @Test(singleThreaded = true)
public class SecureProcessingTest {
! public void runWithSecurityManager() throws Exception {
! JAXPTestUtilities.tryRunWithPolicyManager(() -> testSecureProcessing(),
! new FilePermission(System.getProperty("test.src") + "/-", "read"));
}
+ public void runWithoutSecurityManager() throws Exception {
+ testSecureProcessing();
+ }
! private final void testSecureProcessing() {
! boolean _isSecureMode = System.getSecurityManager() != null;
// SECURE_PROCESSING == false
// the style sheet
InputStream xslStream = this.getClass().getResourceAsStream("SecureProcessingTest.xsl");
StreamSource xslSource = new StreamSource(xslStream);
< prev index next >