Package gnu.testlet

Examples of gnu.testlet.TestSecurityManager


  new PropertyPermission(not_a_property, "write")};

      Permission[] setSecurityManager = new Permission[] {
  new RuntimePermission("setSecurityManager")};
     
      TestSecurityManager sm = new TestSecurityManager(harness);
      try {
  sm.install();

  // throwpoint: java.lang.System-exit
  harness.checkPoint("exit");
  try {
    sm.prepareHaltingChecks(exitVM);
    System.exit(0);
    harness.check(false);   
  }
  catch (TestSecurityManager.SuccessException ex) {
    harness.check(true);
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
 
  // throwpoint: java.lang.System-runFinalizersOnExit
  harness.checkPoint("runFinalizersOnExit");
  try {
    sm.prepareChecks(exitVM);
    System.runFinalizersOnExit(false);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.System-load
  harness.checkPoint("load");
  try {
    sm.prepareHaltingChecks(loadLibrary_name);
    System.load(library_name);
    harness.check(false);   
  }
  catch (TestSecurityManager.SuccessException ex) {
    harness.check(true);
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.System-loadLibrary
  harness.checkPoint("loadLibrary");
  try {
    sm.prepareHaltingChecks(loadLibrary_path);
    System.loadLibrary(library_path);
    harness.check(false);   
  }
  catch (TestSecurityManager.SuccessException ex) {
    harness.check(true);
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: TODO: java.lang.System-getenv()

  // throwpoint: java.lang.System-getenv(String)
  harness.checkPoint("getenv(String)");
  try {
    sm.prepareChecks(readVariable);
    System.getenv(a_variable);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(readNonVariable);
    System.getenv(not_a_variable);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.System-getProperties
  harness.checkPoint("getProperties");
  try {
    sm.prepareChecks(readWriteAllProperties);
    System.getProperties();
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.System-setProperties
  harness.checkPoint("setProperties");
  try {
    sm.prepareChecks(readWriteAllProperties);
    System.setProperties(properties);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.System-getProperty(String)
  harness.checkPoint("getProperty(String)");
  try {
    sm.prepareChecks(readProperty);
    System.getProperty(a_property);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(readNonProperty);
    System.getProperty(not_a_property);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.System-getProperty(String, String)
  harness.checkPoint("getProperty(String, String)");
  try {
    sm.prepareChecks(readProperty);
    System.getProperty(a_property, "quadrant");
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(readNonProperty);
    System.getProperty(not_a_property, "blade");
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.System-setIn
  harness.checkPoint("setIn");
  try {
    sm.prepareChecks(setIO);
    System.setIn(System.in);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.System-setOut
  harness.checkPoint("setOut");
  try {
    sm.prepareChecks(setIO);
    System.setOut(System.out);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.System-setErr
  harness.checkPoint("setErr");
  try {
    sm.prepareChecks(setIO);
    System.setErr(System.err);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.System-setProperty
  harness.checkPoint("setProperty");
  try {
    sm.prepareChecks(writeProperty);
    System.setProperty(a_property, properties.getProperty(a_property));
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(writeNonProperty);
    System.setProperty(not_a_property, "hello mum");
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: TODO: java.lang.System-clearProperty

  // throwpoint: java.lang.System-setSecurityManager
  harness.checkPoint("setSecurityManager");
  try {
    sm.prepareChecks(setSecurityManager);
    System.setSecurityManager(sm);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
      }
      finally {
  sm.uninstall();
      }
    }
    catch (Exception ex) {
      harness.debug(ex);
      harness.check(false, "Unexpected exception");
View Full Code Here


      Permission[] loadLibrary_name = new Permission[] {
  new RuntimePermission("loadLibrary." + library_name)};
      Permission[] loadLibrary_path = new Permission[] {
  new RuntimePermission("loadLibrary." + library_path)};

      TestSecurityManager sm = new TestSecurityManager(harness);
      try {
  sm.install();

  // throwpoint: java.lang.Runtime-exec(String)
  harness.checkPoint("exec(String)");
  try {
    sm.prepareChecks(executeCommand, modifyThreadOrGroup);
    runtime.exec(sCommand).waitFor();
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.Runtime-exec(String, String[])
  harness.checkPoint("exec(String, String[])");
  try {
    sm.prepareChecks(executeCommand, modifyThreadOrGroup);
    runtime.exec(sCommand, null).waitFor();
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.Runtime-exec(String, String[], File)
  harness.checkPoint("exec(String, String[], File)");
  try {
    sm.prepareChecks(executeCommand, modifyThreadOrGroup);
    runtime.exec(sCommand, null, null).waitFor();
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.Runtime-exec(String[])
  harness.checkPoint("exec(String[])");
  try {
    sm.prepareChecks(executeCommand, modifyThreadOrGroup);
    runtime.exec(aCommand).waitFor();
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.Runtime-exec(String[], String[])
  harness.checkPoint("exec(String[], String[])");
  try {
    sm.prepareChecks(executeCommand, modifyThreadOrGroup);
    runtime.exec(aCommand, null).waitFor();
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.Runtime-exec(String[], String[], File)
  harness.checkPoint("exec(String[], String[], File)");
  try {
    sm.prepareChecks(executeCommand, modifyThreadOrGroup);
    runtime.exec(aCommand, null, null).waitFor();
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.Runtime-exit
  harness.checkPoint("exit");
  try {
    sm.prepareHaltingChecks(exitVM);
    runtime.exit(0);
    harness.check(false);   
  }
  catch (TestSecurityManager.SuccessException ex) {
    harness.check(true);
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.Runtime-runFinalizersOnExit
  harness.checkPoint("runFinalizersOnExit");
  try {
    sm.prepareChecks(exitVM);
    Runtime.runFinalizersOnExit(false);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.Runtime-addShutdownHook
  harness.checkPoint("addShutdownHook");
  try {
    sm.prepareChecks(shutdownHooks);
    runtime.addShutdownHook(thread);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
 
  // throwpoint: java.lang.Runtime-removeShutdownHook
  harness.checkPoint("removeShutdownHook");
  try {
    sm.prepareChecks(shutdownHooks);
    runtime.removeShutdownHook(thread);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.Runtime-load
  harness.checkPoint("load");
  try {
    sm.prepareHaltingChecks(loadLibrary_name);
    runtime.load(library_name);
    harness.check(false);   
  }
  catch (TestSecurityManager.SuccessException ex) {
    harness.check(true);
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.lang.Runtime-loadLibrary
  harness.checkPoint("loadLibrary");
  try {
    sm.prepareHaltingChecks(loadLibrary_path);
    runtime.loadLibrary(library_path);
    harness.check(false);   
  }
  catch (TestSecurityManager.SuccessException ex) {
    harness.check(true);
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
      }
      finally {
  sm.uninstall();
      }
    }
    catch (Exception ex) {
      harness.debug(ex);
      harness.check(false, "Unexpected exception");
View Full Code Here

  Class.class.getDeclaredConstructors()[0];

      Permission[] suppressAccessChecks = new Permission[] {
   new ReflectPermission("suppressAccessChecks")};

      TestSecurityManager sm = new TestSecurityManager(harness);
      try {
  sm.install();

  // throwpoint: java.lang.reflect.AccessibleObject-setAccessible(boolean)
  harness.checkPoint("setAccessible (per-object)");
  for (int i = 0; i < objects.length; i++) {
    try {
      sm.prepareChecks(suppressAccessChecks);
      objects[i].setAccessible(true);
      sm.checkAllChecked();
    }
    catch (SecurityException ex) {
      harness.debug(ex);
      harness.check(false, "unexpected check");
    }
  }

  harness.checkPoint("setAccessible (class constructor)");
  try {
    sm.prepareChecks(suppressAccessChecks);
    class_constructor.setAccessible(true);
    harness.check(false);
  }
  catch (SecurityException ex) {
    sm.checkAllChecked();
  }

  // throwpoint: java.lang.reflect.AccessibleObject-setAccessible(AccessibleObject[], boolean)
  harness.checkPoint("setAccessible (array)");
  try {
    sm.prepareChecks(suppressAccessChecks);
    AccessibleObject.setAccessible(objects, true);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
      }
      finally {
  sm.uninstall();
      }
    }
    catch (Exception ex) {
      harness.debug(ex);
      harness.check(false, "Unexpected exception");
View Full Code Here

    Permission[] perm = new Permission[] {
  new FilePermission(path, "read")};
    Permission[] fdPerm = new Permission[] {
  new RuntimePermission("readFileDescriptor")};
   
    TestSecurityManager sm = new TestSecurityManager(harness);
    try {
      sm.install();
 
      // throwpoint: java.io.FileInputStream-FileInputStream(File)
      harness.checkPoint("File constructor");
      try {
  sm.prepareChecks(perm);
  new FileInputStream(file);
  sm.checkAllChecked();
      }
      catch (SecurityException ex) {
  harness.debug(ex);
  harness.check(false, "Unexpected check");
      }
     
      // throwpoint: java.io.FileInputStream-FileInputStream(String)
      harness.checkPoint("String constructor");
      try {
  sm.prepareChecks(perm);
  new FileInputStream(path);
  sm.checkAllChecked();
      }
      catch (SecurityException ex) {
  harness.debug(ex);
  harness.check(false, "Unexpected check");
      }
     
      // throwpoint: java.io.FileInputStream-FileInputStream(FileDescriptor)
      harness.checkPoint("FileDescriptor constructor");
      try {
  sm.prepareChecks(fdPerm);
  new FileInputStream(FileDescriptor.in);
  sm.checkAllChecked();
      }
      catch (SecurityException ex) {
  harness.debug(ex);
  harness.check(false, "Unexpected check");
      }
    }
    catch (Exception ex) {
      harness.debug(ex);
      harness.check(false, "Unexpected exception");
    }
    finally {
  sm.uninstall();
    }
  }
View Full Code Here

    Permission rfdperm = new RuntimePermission("readFileDescriptor");
    Permission wfdperm = new RuntimePermission("writeFileDescriptor");

    String[] modes = new String[] {"r", "rw", "rws", "rwd"};
   
    TestSecurityManager sm = new TestSecurityManager(harness);
    try {
      sm.install();

      for (int i = 0; i < modes.length; i++) {
  String mode = modes[i];

  Permission[] mustCheck, mayCheck;
  if (mode.equals("r")) {
    mustCheck = new Permission[] {rperm};
    mayCheck = new Permission[] {rfdperm};
  }
  else {
    mustCheck = new Permission[] {rperm, wperm};
    mayCheck = new Permission[] {rfdperm, wfdperm};
  }

  RandomAccessFile raf;

  // throwpoint: java.io.RandomAccessFile-RandomAccessFile(File, String)
  harness.checkPoint("File constructor, mode = \"" + mode + "\"");
  try {
    sm.prepareChecks(mustCheck, mayCheck);
    raf = new RandomAccessFile(file, mode);
    sm.checkAllChecked();
    if (mode == "r")
      ensureUnwritable(harness, raf);
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.io.RandomAccessFile-RandomAccessFile(String, String)
  harness.checkPoint("String constructor, mode = \"" + mode + "\"");
  try {
    sm.prepareChecks(mustCheck, mayCheck);
    raf = new RandomAccessFile(path, mode);
    sm.checkAllChecked();
    if (mode == "r")
      ensureUnwritable(harness, raf);
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
      }
    }
    catch (Exception ex) {
      harness.debug(ex);
      harness.check(false, "Unexpected exception");
    }
    finally {
  sm.uninstall();

  file.delete();
  dir.delete();
    }
  }
View Full Code Here

    Permission rperm = new FilePermission(path, "read");
    Permission wperm = new FilePermission(path, "write");
    Permission fdPerm = new RuntimePermission("writeFileDescriptor");
   
    TestSecurityManager sm = new TestSecurityManager(harness);
    try {
      sm.install();
 
      // throwpoint: java.io.FileOutputStream-FileOutputStream(File)
      harness.checkPoint("File constructor");
      try {
  sm.prepareChecks(new Permission[] {wperm}, new Permission[] {rperm});
  new FileOutputStream(file);
  sm.checkAllChecked();
      }
      catch (SecurityException ex) {
  harness.debug(ex);
  harness.check(false, "Unexpected check");
      }

      // throwpoint: java.io.FileOutputStream-FileOutputStream(File, boolean)
      harness.checkPoint("File, boolean constructor");
      for (int i = 0; i <= 1; i++) {
  try {
    sm.prepareChecks(new Permission[] {wperm}, new Permission[] {rperm});
    new FileOutputStream(file, i == 1);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "Unexpected check");
  }
      }

      // throwpoint: java.io.FileOutputStream-FileOutputStream(String)
      harness.checkPoint("String constructor");
      try {
  sm.prepareChecks(new Permission[] {wperm}, new Permission[] {rperm});
  new FileOutputStream(path);
  sm.checkAllChecked();
      }
      catch (SecurityException ex) {
  harness.debug(ex);
  harness.check(false, "Unexpected check");
      }

      // throwpoint: java.io.FileOutputStream-FileOutputStream(String, boolean)
      harness.checkPoint("String, boolean constructor");
      for (int i = 0; i <= 1; i++) {
  try {
    sm.prepareChecks(new Permission[] {wperm}, new Permission[] {rperm});
    new FileOutputStream(path, i == 1);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "Unexpected check");
  }
      }

      // throwpoint: java.io.FileOutputStream-FileOutputStream(FileDescriptor)
      harness.checkPoint("FileDescriptor constructor");
      try {
  sm.prepareChecks(new Permission[] {fdPerm});
  new FileOutputStream(FileDescriptor.out);
  sm.checkAllChecked();
      }
      catch (SecurityException ex) {
  harness.debug(ex);
  harness.check(false, "Unexpected check");
      }
    }
    catch (Exception ex) {
      harness.debug(ex);
      harness.check(false, "Unexpected exception");
    }
    finally {
  sm.uninstall();

  file.delete();
  dir.delete();
    }
  }
View Full Code Here

      Permission[] enableSubstitution = new Permission[] {
  new SerializablePermission("enableSubstitution")};

      Permission[] noPerms = new Permission[] {};

      TestSecurityManager sm = new TestSecurityManager(harness);
      try {
  sm.install();

  // throwpoint: java.io.ObjectInputStream-ObjectInputStream
  harness.checkPoint("constructor");
  try {
    sm.prepareChecks(enableSubclassImplementation);
    new TestObjectInputStream();
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.io.ObjectInputStream-enableResolveObject
  harness.checkPoint("enableResolveObject");
  try {
    sm.prepareChecks(noPerms);
    teststream.testEnableResolveObject(false);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(enableSubstitution);
    teststream.testEnableResolveObject(true);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
      }
      finally {
  sm.uninstall();
      }
    }
    catch (Exception ex) {
      harness.debug(ex);
      harness.check(false, "Unexpected exception");
View Full Code Here

TOP

Related Classes of gnu.testlet.TestSecurityManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.