Package gnu.testlet

Examples of gnu.testlet.TestSecurityManager


  new AWTPermission("createRobot")};

      Permission[] readProperty = new Permission[] {
  new PropertyPermission("*", "read")};

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

  // throwpoint: java.awt.Robot-Robot()
  harness.checkPoint("0-arg constructor");
  try {
    sm.prepareChecks(createRobot, readProperty);
    new Robot();
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.awt.Robot-Robot(GraphicsDevice)
  harness.checkPoint("1-arg constructor");
  try {
    sm.prepareChecks(createRobot, readProperty);
    new Robot(gd);
    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


    hostaddr + ":" + socket4.getLocalPort(), "accept")};
     
      Permission[] checkSetFactory = new Permission[] {
   new RuntimePermission("setFactory")};

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

   // throwpoint: java.net.DatagramSocket-DatagramSocket()
  harness.checkPoint("DatagramSocket()");
  try {
    sm.prepareChecks(checkListen1024plus);
    new DatagramSocket().close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

   // throwpoint: java.net.DatagramSocket-DatagramSocket(SocketAddress)
  harness.checkPoint("DatagramSocket(SocketAddress)");
  try {
    sm.prepareChecks(checkListen80);
    try {
      new DatagramSocket(new InetSocketAddress(inetaddr, 80)).close();
    }
    catch (BindException e) {
    }     
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(checkListen1024plus);
    new DatagramSocket(new InetSocketAddress(inetaddr, 0)).close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

   // throwpoint: java.net.DatagramSocket-DatagramSocket(int)
  harness.checkPoint("DatagramSocket(int)");
  try {
    sm.prepareChecks(checkListen80);
    try {
      new DatagramSocket(80).close();
    }
    catch (BindException e) {
    }
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(checkListen1024plus);
    new DatagramSocket(0).close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

   // throwpoint: java.net.DatagramSocket-DatagramSocket(int, InetAddress)
  harness.checkPoint("DatagramSocket(int, InetAddress)");
  try {
    sm.prepareChecks(checkListen80);
    try {
      new DatagramSocket(80, inetaddr).close();
    }
    catch (BindException e) {
    }
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(checkListen1024plus);
    new DatagramSocket(0, inetaddr).close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
 
   // throwpoint: java.net.DatagramSocket-connect
  harness.checkPoint("connect");
  try {
    sm.prepareChecks(checkConnect1, checkAccept1);
    socket2.connect(sock1addr);
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(checkConnect2, checkAccept2);
    socket1.connect(sock2addr, socket2.getLocalPort());
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

   // throwpoint: java.net.DatagramSocket-send
  harness.checkPoint("send");
  try {
    sm.prepareChecks(checkConnect3);
    socket4.send(sendpack);
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
 
   // throwpoint: java.net.DatagramSocket-receive
  harness.checkPoint("receive");
  try {
    sm.prepareChecks(checkAccept4);
    socket3.receive(recvpack);
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
 
   // throwpoint: java.net.DatagramSocket-getLocalAddress
  harness.checkPoint("getLocalAddress");
  try {
    sm.prepareChecks(checkResolve);
    socket1.getLocalAddress();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
 
   // throwpoint: java.net.DatagramSocket-getLocalSocketAddress
  harness.checkPoint("getLocalSocketAddress");
  try {
    sm.prepareChecks(checkResolve);
    socket1.getLocalSocketAddress();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.net.Socket-setDatagramSocketImplFactory
  harness.checkPoint("setDatagramSocketImplFactory");
  try {
    sm.prepareHaltingChecks(checkSetFactory);
    DatagramSocket.setDatagramSocketImplFactory(null);
    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 e) {
      harness.debug(e);
      harness.check(false, "Unexpected exception");
View Full Code Here

  new RuntimePermission("selectorProvider")};

      Permission[] checkSetFactory = new Permission[] {
  new RuntimePermission("setFactory")};

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

   // throwpoint: java.net.Socket-Socket(InetAddress, int)
  harness.checkPoint("Socket(InetAddress, int)");
  try {
    sm.prepareChecks(checkConnect, checkSelectorProvider);
    new Socket(inetaddr, hostport).close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

   // throwpoint: java.net.Socket-Socket(String, int)
  harness.checkPoint("Socket(String, int)");
  try {
    sm.prepareChecks(checkConnect, checkSelectorProvider);
    new Socket(hostaddr, hostport).close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(checkResolveConnect, checkSelectorProvider);
    new Socket(hostname, hostport).close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.net.Socket-Socket(InetAddress, int, boolean)
  harness.checkPoint("Socket(InetAddress, int, boolean)");
  for (int i = 0; i < 2; i++) { 
    try {
      sm.prepareChecks(checkConnect, checkSelectorProvider);
      new Socket(inetaddr, hostport, i == 0).close();
      sm.checkAllChecked();
    }
    catch (SecurityException e) {
      harness.debug(e);
      harness.check(false, "unexpected check");
    }
  }

  // throwpoint: java.net.Socket-Socket(String, int, boolean)
  harness.checkPoint("Socket(String, int, boolean)");
  for (int i = 0; i < 2; i++) { 
    try {
      sm.prepareChecks(checkConnect, checkSelectorProvider);
      new Socket(hostaddr, hostport, i == 0).close();
      sm.checkAllChecked();
    }
    catch (SecurityException e) {
      harness.debug(e);
      harness.check(false, "unexpected check");
    }
    try {
      sm.prepareChecks(checkResolveConnect, checkSelectorProvider);
      new Socket(hostname, hostport, i == 0).close();
      sm.checkAllChecked();
    }
    catch (SecurityException e) {
      harness.debug(e);
      harness.check(false, "unexpected check");
    }
  }

  // throwpoint: java.net.Socket-Socket(InetAddress,int,InetAddress,int)
  harness.checkPoint("Socket(InetAddress, int, InetAddress, int)");
  try {
    sm.prepareChecks(checkConnect, checkSelectorProvider);
    new Socket(inetaddr, hostport, inetaddr, 0).close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

   // throwpoint: java.net.Socket-Socket(String, int, InetAddress, int)
  harness.checkPoint("Socket(String, int, InetAddress, int)");
  try {
    sm.prepareChecks(checkConnect, checkSelectorProvider);
    new Socket(hostaddr, hostport, inetaddr, 0).close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(checkResolveConnect, checkSelectorProvider);
    new Socket(hostname, hostport, inetaddr, 0).close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

  // throwpoint: TODO: java.net.Socket-Socket(Proxy) 

  // throwpoint: java.net.Socket-setSocketImplFactory
  harness.checkPoint("setSocketImplFactory");
  try {
    sm.prepareHaltingChecks(checkSetFactory);
    Socket.setSocketImplFactory(null);
    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 e) {
      harness.debug(e);
      harness.check(false, "Unexpected exception");
View Full Code Here

  new RuntimePermission("selectorProvider")};

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

  // throwpoint: java.net.ServerSocket-ServerSocket(int)
  harness.checkPoint("ServerSocket(int)");
  try {
    sm.prepareChecks(checkListen80, checkSelectorProvider);
    try {
      new ServerSocket(80).close();
    }
    catch (BindException e) {
    }
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(checkListen1024plus, checkSelectorProvider);
    new ServerSocket(0).close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.net.ServerSocket-ServerSocket(int, int)
  harness.checkPoint("ServerSocket(int, int)");
  try {
    sm.prepareChecks(checkListen80, checkSelectorProvider);
    try {
      new ServerSocket(80, 50).close();
    }
    catch (BindException e) {
    }
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(checkListen1024plus, checkSelectorProvider);
    new ServerSocket(0, 50).close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.net.ServerSocket-ServerSocket(int, int,InetAddress)
  harness.checkPoint("ServerSocket(int, int, InetAddress)");
  try {
    sm.prepareChecks(checkListen80, checkSelectorProvider);
    try {
      new ServerSocket(80, 50, inetaddr).close();
    }
    catch (BindException e) {
    }
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }
  try {
    sm.prepareChecks(checkListen1024plus, checkSelectorProvider);
    new ServerSocket(0, 50, inetaddr).close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.net.ServerSocket-accept
  harness.checkPoint("accept");
  try {
    sm.prepareChecks(checkAccept, checkSelectorProvider);
    ssocket.accept().close();
    sm.checkAllChecked();
  }
  catch (SecurityException e) {
    harness.debug(e);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.net.ServerSocket-setSocketFactory
  harness.checkPoint("setSocketFactory");
  try {
    sm.prepareHaltingChecks(checkSetFactory);
    ServerSocket.setSocketFactory(null);
    harness.check(false);
  }
  catch (TestSecurityManager.SuccessException ex) {
    harness.check(true);
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
      }
      finally {
  sm.uninstall();
  csocket.close();
  ssocket.close();
      }
    }
    catch (Exception e) {
View Full Code Here

      byte[] hostaddr = localhost.getAddress();

      Permission[] checkConnect = new Permission[] {
  new SocketPermission(hostname, "resolve")};
     
      TestSecurityManager sm = new TestSecurityManager(harness);
      try {
  sm.install();

   // throwpoint: java.net.InetAddress-getHostName
  harness.checkPoint("getHostName");
  try {
    sm.prepareChecks(checkConnect);
    InetAddress.getByAddress(hostaddr).getHostName();
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

   // throwpoint: java.net.InetAddress-getCanonicalHostName
  harness.checkPoint("getCanonicalHostName");
  try {
    sm.prepareChecks(checkConnect);
    InetAddress.getByAddress(hostaddr).getCanonicalHostName();
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

   // throwpoint: java.net.InetAddress-getByName
  harness.checkPoint("getByName");
  try {
    sm.prepareChecks(checkConnect);
    InetAddress.getByName(hostname);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.net.InetAddress-getAllByName
  harness.checkPoint("getAllByName");
  try {
    sm.prepareChecks(checkConnect);
    InetAddress.getAllByName(hostname);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.net.InetAddress-getLocalHost
  harness.checkPoint("getLocalHost");
  try {
    sm.prepareChecks(checkConnect);
    InetAddress.getLocalHost();
    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

      for (int i = 0; i < list.size(); i++) {
  InetAddress addr = (InetAddress) list.get(i);
  checks[i] = new SocketPermission(addr.getHostAddress(), "resolve");
      }

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

   // throwpoint: java.net.NetworkInterface-getInetAddresses
  harness.checkPoint("getInetAddresses");
  try {
    sm.prepareChecks(checks);
    for (Enumeration e = NetworkInterface.getNetworkInterfaces();
         e.hasMoreElements(); ) {
      NetworkInterface nif = (NetworkInterface) e.nextElement();
      nif.getInetAddresses();
    }
    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

  new NetPermission("specifyStreamHandler")};

      Permission[] checkSetFactory = new Permission[] {
  new RuntimePermission("setFactory")};

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

  // throwpoint: java.net.URL-URL(String, String, int, String, URLStreamHandler)
  harness.checkPoint("URL(String, String, int, String, URLStreamHandler)");
  try {
    sm.prepareChecks(specifyStreamHandler);
    new URL("redhat", "redhat.com", 23, "/red/hat/", handler);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.net.URL-URL(URL, String, URLStreamHandler)
  harness.checkPoint("URL(String, String, int, String, URLStreamHandler)");
  try {
    sm.prepareChecks(specifyStreamHandler);
    new URL(context, "/red/hat/", handler);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.net.URL-setURLStreamHandlerFactory
  harness.checkPoint("setURLStreamHandlerFactory");
  try {
    sm.prepareHaltingChecks(checkSetFactory);
    URL.setURLStreamHandlerFactory(null);
    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

      URLStreamHandlerFactory ushf = new TestUSHFactory();
     
      Permission[] createClassLoader = new Permission[] {
  new RuntimePermission("createClassLoader")};

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

  // throwpoint: java.net.URLClassLoader-URLClassLoader(URL[])
  harness.checkPoint("Constructor (1 arg)");
  try {
    sm.prepareChecks(createClassLoader);
    new URLClassLoader(new URL[0]);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.net.URLClassLoader-URLClassLoader(URL[], ClassLoader)
  harness.checkPoint("Constructor (2 arg)");
  try {
    sm.prepareChecks(createClassLoader);
    new URLClassLoader(new URL[0], loader);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.net.URLClassLoader-URLClassLoader(URL[], ClassLoader, URLStreamHandlerFactory)
  harness.checkPoint("Constructor (3 arg)");
  try {
    sm.prepareChecks(createClassLoader);
    new URLClassLoader(new URL[0], loader, ushf);
    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

      GraphicsConfiguration gc = window.getGraphicsConfiguration();

      Permission[] showWindowWithoutWarningBanner = new Permission[] {
  new AWTPermission("showWindowWithoutWarningBanner")};

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

  // throwpoint: java.awt.Window-Window(Frame)
  harness.checkPoint("Window(Frame)");
  try {
    sm.prepareChecks(showWindowWithoutWarningBanner);
    new Window(frame);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.awt.Window-Window(Window)
  harness.checkPoint("Window(Window)");
  try {
    sm.prepareChecks(showWindowWithoutWarningBanner);
    new Window(window);
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }

  // throwpoint: java.awt.Window-Window(Window, GraphicsConfiguration)
  harness.checkPoint("Window(Window, GraphicsConfiguration)");
  try {
    sm.prepareChecks(showWindowWithoutWarningBanner);
    new Window(window, gc);
    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

      Composite composite = new TestComposite();

      Permission[] readDisplayPixels = new Permission[] {
  new AWTPermission("readDisplayPixels")};

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

  // throwpoint: java.awt.Graphics2D-setComposite
  harness.checkPoint("setComposite");
  try {
    sm.prepareChecks(readDisplayPixels);
    try {
      graphics2d.setComposite(composite);
    }
    catch (UnsupportedOperationException ex) {
    }
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
    harness.check(false, "unexpected check");
  }
      }
      finally {
  sm.uninstall();
      }

      window.setVisible(false);
      window.dispose();
    }
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.