< prev index next >
test/javax/xml/jaxp/unittest/validation/Bug6483188.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,61 ****
* questions.
*/
package validation;
import java.net.URL;
import javax.xml.XMLConstants;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.xml.sax.SAXParseException;
/*
* @bug 6483188
* @summary Test Schema Validator can handle element with having large maxOccurs, but doesn't accept sequence with having large maxOccurs in FEATURE_SECURE_PROCESSING mode.
*/
public class Bug6483188 {
- 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");
- }
- }
-
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
! @Test
! public void testLargeElementNoSecurity() {
! if (_isSecureMode)
return; // jaxp secure feature can not be turned off when security
// manager is present
try {
sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.FALSE);
URL url = getClass().getResource("test-element.xsd");
--- 21,68 ----
* questions.
*/
package validation;
+ import java.io.FilePermission;
import java.net.URL;
import javax.xml.XMLConstants;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
+ import jaxp.library.JAXPTestUtilities;
+
import org.testng.Assert;
import org.testng.annotations.Test;
import org.xml.sax.SAXParseException;
/*
* @bug 6483188
* @summary Test Schema Validator can handle element with having large maxOccurs, but doesn't accept sequence with having large maxOccurs in FEATURE_SECURE_PROCESSING mode.
*/
+ @Test(singleThreaded = true)
public class Bug6483188 {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
! public void runWithSecurityManager() throws Exception {
! JAXPTestUtilities.tryRunWithPolicyManager(() -> {
! testLargeElementNoSecurity();
! testLargeElementWithSecurity();
! testLargeSequenceWithSecurity();
! }, new FilePermission(System.getProperty("test.src") + "/-", "read"));
! }
!
! public void runWithoutSecurityManager() throws Exception {
! testLargeElementNoSecurity();
! testLargeElementWithSecurity();
! testLargeSequenceWithSecurity();
! }
!
! private void testLargeElementNoSecurity() {
! if (System.getSecurityManager() != null)
return; // jaxp secure feature can not be turned off when security
// manager is present
try {
sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.FALSE);
URL url = getClass().getResource("test-element.xsd");
*** 64,87 ****
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
! @Test
! public void testLargeElementWithSecurity() {
try {
sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
URL url = getClass().getResource("test-element.xsd");
Schema s = sf.newSchema(url);
Validator v = s.newValidator();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
! @Test
! public void testLargeSequenceWithSecurity() {
try {
sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
URL url = getClass().getResource("test-sequence.xsd");
Schema s = sf.newSchema(url);
Validator v = s.newValidator();
--- 71,92 ----
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
! private void testLargeElementWithSecurity() {
try {
sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
URL url = getClass().getResource("test-element.xsd");
Schema s = sf.newSchema(url);
Validator v = s.newValidator();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
! private void testLargeSequenceWithSecurity() {
try {
sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
URL url = getClass().getResource("test-sequence.xsd");
Schema s = sf.newSchema(url);
Validator v = s.newValidator();
< prev index next >