* FYI: Throwpoint checks for java.lang.reflect.AccessibleObject
@ 2006-06-21 10:04 Gary Benson
2006-06-26 9:38 ` FYI: Tweaked throwpoint checks for java.io.FileInputStream Gary Benson
0 siblings, 1 reply; 2+ messages in thread
From: Gary Benson @ 2006-06-21 10:04 UTC (permalink / raw)
To: mauve-patches
[-- Attachment #1: Type: text/plain, Size: 147 bytes --]
Hi again,
This commit adds checks for java.lang.reflect.AccessibleObject's
throwpoints. This is the last testcase for java.lang :)
Cheers,
Gary
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 5173 bytes --]
Index: ChangeLog
===================================================================
RCS file: /cvs/mauve/mauve/ChangeLog,v
retrieving revision 1.1714
diff -u -r1.1714 ChangeLog
--- ChangeLog 21 Jun 2006 08:13:03 -0000 1.1714
+++ ChangeLog 21 Jun 2006 09:59:27 -0000
@@ -1,3 +1,7 @@
+ 2006-06-21 Gary Benson <gbenson@redhat.com>
+
+ * gnu/testlet/java/lang/reflect/AccessibleObject/security.java: New test.
+
2006-06-21 Gary Benson <gbenson@redhat.com>
* gnu/testlet/java/awt/Graphics2D/security.java: New test.
Index: gnu/testlet/java/lang/reflect/AccessibleObject/security.java
===================================================================
RCS file: gnu/testlet/java/lang/reflect/AccessibleObject/security.java
diff -N gnu/testlet/java/lang/reflect/AccessibleObject/security.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/lang/reflect/AccessibleObject/security.java 21 Jun 2006 09:59:27 -0000
@@ -0,0 +1,136 @@
+// 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.lang.reflect.AccessibleObject;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ReflectPermission;
+import java.security.Permission;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+import gnu.testlet.TestSecurityManager2;
+
+public class security implements Testlet
+{
+ public void test(TestHarness harness)
+ {
+ try {
+ harness.checkPoint("constructor");
+ Constructor constructor =
+ ClassLoader.class.getDeclaredConstructor(new Class[0]);
+ int mods = constructor.getModifiers();
+ harness.check(Modifier.isPrivate(mods) || Modifier.isProtected(mods));
+ try {
+ constructor.newInstance(new Object[0]);
+ harness.check(false);
+ }
+ catch (IllegalAccessException ex) {
+ harness.check(true);
+ }
+
+ harness.checkPoint("field");
+ Field field = String.class.getDeclaredField("serialVersionUID");
+ mods = field.getModifiers();
+ harness.check(Modifier.isPrivate(mods) || Modifier.isProtected(mods));
+ try {
+ field.get("");
+ harness.check(false);
+ }
+ catch (IllegalAccessException ex) {
+ harness.check(true);
+ }
+
+ harness.checkPoint("method");
+ Method method =
+ ClassLoader.class.getDeclaredMethod("getPackages", new Class[0]);
+ mods = method.getModifiers();
+ harness.check(Modifier.isPrivate(mods) || Modifier.isProtected(mods));
+ try {
+ method.invoke(getClass().getClassLoader(), new Object[0]);
+ harness.check(false);
+ }
+ catch (IllegalAccessException ex) {
+ harness.check(true);
+ }
+
+ AccessibleObject[] objects =
+ new AccessibleObject[] {constructor, field, method};
+
+ AccessibleObject class_constructor =
+ Class.class.getDeclaredConstructors()[0];
+
+ Permission[] suppressAccessChecks = new Permission[] {
+ new ReflectPermission("suppressAccessChecks")};
+
+ TestSecurityManager2 sm = new TestSecurityManager2(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(harness);
+ }
+ 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(harness);
+ }
+
+ // throwpoint: java.lang.reflect.AccessibleObject-setAccessible(AccessibleObject[], boolean)
+ harness.checkPoint("setAccessible (array)");
+ try {
+ sm.prepareChecks(suppressAccessChecks);
+ AccessibleObject.setAccessible(objects, true);
+ sm.checkAllChecked(harness);
+ }
+ catch (SecurityException ex) {
+ harness.debug(ex);
+ harness.check(false, "unexpected check");
+ }
+ }
+ finally {
+ sm.uninstall();
+ }
+ }
+ catch (Throwable ex) {
+ harness.debug(ex);
+ harness.check(false, "Unexpected exception");
+ }
+ }
+}
^ permalink raw reply [flat|nested] 2+ messages in thread
* FYI: Tweaked throwpoint checks for java.io.FileInputStream
2006-06-21 10:04 FYI: Throwpoint checks for java.lang.reflect.AccessibleObject Gary Benson
@ 2006-06-26 9:38 ` Gary Benson
0 siblings, 0 replies; 2+ messages in thread
From: Gary Benson @ 2006-06-26 9:38 UTC (permalink / raw)
To: mauve-patches
[-- Attachment #1: Type: text/plain, Size: 275 bytes --]
Morning all,
This commit makes some small changes to the throwpoint checks for
java.io.FileInputStream. Hardly worth bothering with except that
it's the testcase I point people at who want a simple one to base
things on, so it makes sense to have it perfect.
Cheers,
Gary
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 2537 bytes --]
Index: ChangeLog
===================================================================
RCS file: /cvs/mauve/mauve/ChangeLog,v
retrieving revision 1.1732
diff -u -r1.1732 ChangeLog
--- ChangeLog 25 Jun 2006 16:55:59 -0000 1.1732
+++ ChangeLog 26 Jun 2006 09:32:53 -0000
@@ -1,3 +1,7 @@
+2006-06-26 Gary Benson <gbenson@redhat.com>
+
+ * gnu/testlet/java/io/FileInputStream/security.java: Minor tweaks.
+
2006-06-25 Mark Wielaard <mark@klomp.org>
* gnu/testlet/java/lang/Class/newInstance.java: Add checks for
Index: gnu/testlet/java/io/FileInputStream/security.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/io/FileInputStream/security.java,v
retrieving revision 1.5
diff -u -r1.5 security.java
--- gnu/testlet/java/io/FileInputStream/security.java 3 Feb 2006 10:21:46 -0000 1.5
+++ gnu/testlet/java/io/FileInputStream/security.java 26 Jun 2006 09:32:53 -0000
@@ -1,4 +1,4 @@
-// Copyright (C) 2005 Red Hat, Inc.
+// Copyright (C) 2005, 2006 Red Hat, Inc.
// Written by Gary Benson <gbenson@redhat.com>
// This file is part of Mauve.
@@ -37,18 +37,19 @@
File file = new File(harness.getSourceDirectory(), "ChangeLog");
String path = file.getPath();
- Permission perm = new FilePermission(path, "read");
- Permission fdPerm = new RuntimePermission("readFileDescriptor");
+ Permission[] perm = new Permission[] {
+ new FilePermission(path, "read")};
+ Permission[] fdPerm = new Permission[] {
+ new RuntimePermission("readFileDescriptor")};
TestSecurityManager2 sm = new TestSecurityManager2(harness);
-
try {
sm.install();
// throwpoint: java.io.FileInputStream-FileInputStream(File)
harness.checkPoint("File constructor");
try {
- sm.prepareChecks(new Permission[] {perm});
+ sm.prepareChecks(perm);
new FileInputStream(file);
sm.checkAllChecked(harness);
}
@@ -60,7 +61,7 @@
// throwpoint: java.io.FileInputStream-FileInputStream(String)
harness.checkPoint("String constructor");
try {
- sm.prepareChecks(new Permission[] {perm});
+ sm.prepareChecks(perm);
new FileInputStream(path);
sm.checkAllChecked(harness);
}
@@ -72,7 +73,7 @@
// throwpoint: java.io.FileInputStream-FileInputStream(FileDescriptor)
harness.checkPoint("FileDescriptor constructor");
try {
- sm.prepareChecks(new Permission[] {fdPerm});
+ sm.prepareChecks(fdPerm);
new FileInputStream(FileDescriptor.in);
sm.checkAllChecked(harness);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-06-26 9:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-21 10:04 FYI: Throwpoint checks for java.lang.reflect.AccessibleObject Gary Benson
2006-06-26 9:38 ` FYI: Tweaked throwpoint checks for java.io.FileInputStream 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).