Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.batik.bridge
Class ExternalResourcesTest  view ExternalResourcesTest download ExternalResourcesTest.java

java.lang.Object
  extended byorg.apache.batik.test.AbstractTest
      extended byorg.apache.batik.bridge.ExternalResourcesTest
All Implemented Interfaces:
ErrorConstants, org.apache.batik.test.Test

public class ExternalResourcesTest
extends org.apache.batik.test.AbstractTest
implements ErrorConstants

This test validates that SecurityExceptions are generated when the user is trying the access external resources and the UserAgent disallows that. In the following, 'unsecure' means an external resource coming from a different location than the file referencing it. This test works with an SVG file containing an unsecure stylesheet and a set of unsecure elements of all kinds, such as <image> <use> or <feImage>. All these elements are defined in a defs section. The test tries to load the document and validates that a SecurityException is thrown (because of the unsecure stylesheet). Then, the test iterates over the various unsecure elements, inserting them into the document outside the defs section, which should result in a SecurityException in each case. There is a property (secure) to have the test work the opposite way and check that no SecurityException is thrown if access to external resources is allowed.

Version:
$Id: ExternalResourcesTest.java,v 1.6 2004/08/18 07:16:38 vhardy Exp $

Nested Class Summary
protected static interface ExternalResourcesTest.MyUserAgent
           
(package private)  class ExternalResourcesTest.MyUserAgentAdapter
           
(package private)  class ExternalResourcesTest.RelaxedUserAgent
           
(package private)  class ExternalResourcesTest.SecureUserAgent
           
 
Field Summary
static java.lang.String ENTRY_KEY_ERROR_DESCRIPTION
          Entry describing the error
static java.lang.String ENTRY_KEY_EXPECTED_EXCEPTION_ON
           
static java.lang.String ENTRY_KEY_INSERTION_POINT_ID
           
static java.lang.String ENTRY_KEY_TARGET_ID
           
static java.lang.String ENTRY_KEY_UNEXPECTED_EXCEPTION_ON
           
static java.lang.String ERROR_CANNOT_LOAD_SVG_DOCUMENT
          Error when the input file cannot be loaded into a Document object {0} = IOException message
static java.lang.String ERROR_NO_ID_LIST
          Error when the test could not find a list of ids for testing
static java.lang.String ERROR_NO_INSERTION_POINT_IN_DOCUMENT
          Error when the insertion point cannot be found in the test document {0} = insertion point id
static java.lang.String ERROR_TARGET_ID_NOT_FOUND
          Error when one of the target id cannot be found {0} = id which was not found
static java.lang.String ERROR_THROWN_SECURITY_EXCEPTIONS
          Error: an unexpected exception was thrown {0} = List of ids for which an exception was thrown
static java.lang.String ERROR_UNTHROWN_SECURITY_EXCEPTIONS
          Error: an expected exception was not thrown {0} = List of ids for which the exception was not thrown
static java.lang.String ERROR_WHILE_PROCESSING_SVG_DOCUMENT
          Error while processing the document {0} = BridgeException message
static java.lang.String EXTERNAL_STYLESHEET_ID
          Pseudo id for the external stylesheet test
static java.lang.String FILE_DIR
          Location of test files in filesystem.
static java.lang.String INSERTION_POINT_ID
          Id of the element where unsecure content is inserted
protected  boolean secure
          Controls whether the test works in secure mode or not
(package private)  java.lang.String svgURL
           
static java.lang.String testNS
          Test Namespace
 
Fields inherited from class org.apache.batik.test.AbstractTest
id, name, parent
 
Fields inherited from interface org.apache.batik.bridge.ErrorConstants
ERR_ATTRIBUTE_MISSING, ERR_ATTRIBUTE_VALUE_MALFORMED, ERR_CSS_LENGTH_NEGATIVE, ERR_CSS_URI_BAD_TARGET, ERR_LENGTH_NEGATIVE, ERR_URI_BAD_TARGET, ERR_URI_IMAGE_INVALID, ERR_URI_IO, ERR_URI_MALFORMED, ERR_URI_REFERENCE_A_DOCUMENT, ERR_URI_UNSECURE, ERR_XLINK_HREF_CIRCULAR_DEPENDENCIES, MSG_BROKEN_LINK_TITLE
 
Constructor Summary
ExternalResourcesTest()
           
 
Method Summary
protected  ExternalResourcesTest.MyUserAgent buildUserAgent()
           
 java.lang.Boolean getSecure()
           
protected  java.lang.String resolveURL(java.lang.String url)
          Resolves the input string as follows.
 org.apache.batik.test.TestReport runImpl()
          This test uses a list of ids found in the test document.
 void setId(java.lang.String id)
          Set this Test's id.
 void setSecure(java.lang.Boolean secure)
           
 
Methods inherited from class org.apache.batik.test.AbstractTest
assertEquals, assertEquals, assertNull, assertTrue, error, getId, getName, getParent, getQualifiedId, reportError, reportException, reportSuccess, run, runImplBasic, setName, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_CANNOT_LOAD_SVG_DOCUMENT

public static final java.lang.String ERROR_CANNOT_LOAD_SVG_DOCUMENT
Error when the input file cannot be loaded into a Document object {0} = IOException message

See Also:
Constant Field Values

ERROR_WHILE_PROCESSING_SVG_DOCUMENT

public static final java.lang.String ERROR_WHILE_PROCESSING_SVG_DOCUMENT
Error while processing the document {0} = BridgeException message

See Also:
Constant Field Values

ERROR_UNTHROWN_SECURITY_EXCEPTIONS

public static final java.lang.String ERROR_UNTHROWN_SECURITY_EXCEPTIONS
Error: an expected exception was not thrown {0} = List of ids for which the exception was not thrown

See Also:
Constant Field Values

ERROR_THROWN_SECURITY_EXCEPTIONS

public static final java.lang.String ERROR_THROWN_SECURITY_EXCEPTIONS
Error: an unexpected exception was thrown {0} = List of ids for which an exception was thrown

See Also:
Constant Field Values

ERROR_NO_INSERTION_POINT_IN_DOCUMENT

public static final java.lang.String ERROR_NO_INSERTION_POINT_IN_DOCUMENT
Error when the insertion point cannot be found in the test document {0} = insertion point id

See Also:
Constant Field Values

ERROR_NO_ID_LIST

public static final java.lang.String ERROR_NO_ID_LIST
Error when the test could not find a list of ids for testing

See Also:
Constant Field Values

ERROR_TARGET_ID_NOT_FOUND

public static final java.lang.String ERROR_TARGET_ID_NOT_FOUND
Error when one of the target id cannot be found {0} = id which was not found

See Also:
Constant Field Values

ENTRY_KEY_ERROR_DESCRIPTION

public static final java.lang.String ENTRY_KEY_ERROR_DESCRIPTION
Entry describing the error

See Also:
Constant Field Values

ENTRY_KEY_INSERTION_POINT_ID

public static final java.lang.String ENTRY_KEY_INSERTION_POINT_ID
See Also:
Constant Field Values

ENTRY_KEY_TARGET_ID

public static final java.lang.String ENTRY_KEY_TARGET_ID
See Also:
Constant Field Values

ENTRY_KEY_EXPECTED_EXCEPTION_ON

public static final java.lang.String ENTRY_KEY_EXPECTED_EXCEPTION_ON
See Also:
Constant Field Values

ENTRY_KEY_UNEXPECTED_EXCEPTION_ON

public static final java.lang.String ENTRY_KEY_UNEXPECTED_EXCEPTION_ON
See Also:
Constant Field Values

EXTERNAL_STYLESHEET_ID

public static final java.lang.String EXTERNAL_STYLESHEET_ID
Pseudo id for the external stylesheet test

See Also:
Constant Field Values

testNS

public static final java.lang.String testNS
Test Namespace

See Also:
Constant Field Values

INSERTION_POINT_ID

public static final java.lang.String INSERTION_POINT_ID
Id of the element where unsecure content is inserted

See Also:
Constant Field Values

FILE_DIR

public static final java.lang.String FILE_DIR
Location of test files in filesystem.

See Also:
Constant Field Values

secure

protected boolean secure
Controls whether the test works in secure mode or not


svgURL

java.lang.String svgURL
Constructor Detail

ExternalResourcesTest

public ExternalResourcesTest()
Method Detail

setId

public void setId(java.lang.String id)
Description copied from class: org.apache.batik.test.AbstractTest
Set this Test's id. Null is not allowed.

Specified by:
setId in interface org.apache.batik.test.Test

getSecure

public java.lang.Boolean getSecure()

setSecure

public void setSecure(java.lang.Boolean secure)

resolveURL

protected java.lang.String resolveURL(java.lang.String url)
Resolves the input string as follows. + First, the string is interpreted as a file description. If the file exists, then the file name is turned into a URL. + Otherwise, the string is supposed to be a URL. If it is an invalid URL, an IllegalArgumentException is thrown.


runImpl

public org.apache.batik.test.TestReport runImpl()
                                         throws java.lang.Exception
This test uses a list of ids found in the test document. These ids reference elements found in a defs section. For each such element, the test will attempt to insert the target id at a given insertion point. That insertion should cause a SecurityException. If so, the test passes. Otherwise, the test will fail


buildUserAgent

protected ExternalResourcesTest.MyUserAgent buildUserAgent()