* FYI: Throwpoint checks for java.net.DatagramSocket
@ 2006-11-17 15:22 Gary Benson
0 siblings, 0 replies; only message in thread
From: Gary Benson @ 2006-11-17 15:22 UTC (permalink / raw)
To: mauve-patches
[-- Attachment #1: Type: text/plain, Size: 155 bytes --]
Hi all,
This commit adds throwpoint checks for java.net.DatagramSocket.
Note that (with GCJ at least) the check in receive does not happen.
Cheers,
Gary
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 9192 bytes --]
Index: ChangeLog
===================================================================
RCS file: /cvs/mauve/mauve/ChangeLog,v
retrieving revision 1.1993
diff -u -r1.1993 ChangeLog
--- ChangeLog 16 Nov 2006 09:32:50 -0000 1.1993
+++ ChangeLog 17 Nov 2006 15:17:00 -0000
@@ -1,3 +1,7 @@
+2006-11-17 Gary Benson <gbenson@redhat.com>
+
+ * gnu/testlet/java/net/DatagramSocket/security.java: New test.
+
2006-11-16 David Gilbert <david.gilbert@object-refinery.com>
* gnu/testlet/java/beans/beancontext/BeanContextSupport/getChildBeanContextMembershipListener.java: New test,
Index: gnu/testlet/java/net/DatagramSocket/security.java
===================================================================
RCS file: gnu/testlet/java/net/DatagramSocket/security.java
diff -N gnu/testlet/java/net/DatagramSocket/security.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/net/DatagramSocket/security.java 17 Nov 2006 15:17:00 -0000
@@ -0,0 +1,281 @@
+// Copyright (C) 2006 Red Hat, Inc.
+// Written by Gary Benson <gbenson@redhat.com>
+
+// This file is part of Mauve.
+
+// Mauve is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// Mauve is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Mauve; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.java.net.DatagramSocket;
+
+import java.net.BindException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.net.SocketPermission;
+import java.security.Permission;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+import gnu.testlet.TestSecurityManager;
+
+public class security implements Testlet
+{
+ public void test(TestHarness harness)
+ {
+ try {
+ harness.checkPoint("setup");
+
+ InetAddress inetaddr = InetAddress.getByName(null);
+ String hostaddr = inetaddr.getHostAddress();
+
+ DatagramSocket socket1 = new DatagramSocket(0, inetaddr);
+ DatagramSocket socket2 = new DatagramSocket(0, inetaddr);
+ DatagramSocket socket3 = new DatagramSocket(0, inetaddr);
+ DatagramSocket socket4 = new DatagramSocket(0, inetaddr);
+
+ SocketAddress sock1addr = socket1.getLocalSocketAddress();
+ InetAddress sock2addr = socket2.getLocalAddress();
+
+ byte[] sendbuf = new byte[16];
+ DatagramPacket sendpack = new DatagramPacket(
+ sendbuf, sendbuf.length, socket3.getLocalSocketAddress());
+
+ byte[] recvbuf = new byte[sendbuf.length];
+ DatagramPacket recvpack = new DatagramPacket(recvbuf, recvbuf.length);
+
+ Permission[] checkResolve = new Permission[] {
+ new SocketPermission(hostaddr, "resolve")};
+
+ Permission[] checkListen80 = new Permission[] {
+ new SocketPermission("localhost:80", "listen")};
+
+ Permission[] checkListen1024plus = new Permission[] {
+ new SocketPermission("localhost:1024-", "listen")};
+
+ Permission[] checkConnect1 = new Permission[] {
+ new SocketPermission(
+ hostaddr + ":" + socket1.getLocalPort(), "connect")};
+
+ Permission[] checkAccept1 = new Permission[] {
+ new SocketPermission(
+ hostaddr + ":" + socket1.getLocalPort(), "accept")};
+
+ Permission[] checkConnect2 = new Permission[] {
+ new SocketPermission(
+ hostaddr + ":" + socket2.getLocalPort(), "connect")};
+
+ Permission[] checkAccept2 = new Permission[] {
+ new SocketPermission(
+ hostaddr + ":" + socket2.getLocalPort(), "accept")};
+
+ Permission[] checkConnect3 = new Permission[] {
+ new SocketPermission(
+ hostaddr + ":" + socket3.getLocalPort(), "connect")};
+
+ Permission[] checkAccept4 = new Permission[] {
+ new SocketPermission(
+ 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");
+ }
+ }
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-11-17 15:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-17 15:22 FYI: Throwpoint checks for java.net.DatagramSocket Gary Benson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).