public inbox for mauve-patches@sourceware.org
 help / color / mirror / Atom feed
* FYI: Test security manager new feature
@ 2006-02-16 10:33 Gary Benson
  0 siblings, 0 replies; 2+ messages in thread
From: Gary Benson @ 2006-02-16 10:33 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 295 bytes --]

Hi all,

A while ago I added a bit to the test security manager to make it
throw an exception when the expected permission is checked (to allow
testing access checks on things you don't actually want to happen).
This commit allows that bit of logic to test multiple access checks.

Cheers,
Gary

[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 1838 bytes --]

Index: ChangeLog
===================================================================
RCS file: /cvs/mauve/mauve/ChangeLog,v
retrieving revision 1.1477
diff -u -r1.1477 ChangeLog
--- ChangeLog	15 Feb 2006 15:12:45 -0000	1.1477
+++ ChangeLog	16 Feb 2006 10:28:27 -0000
@@ -1,3 +1,9 @@
+2006-01-27  Gary Benson <gbenson@redhat.com>
+
+	* gnu/testlet/TestSecurityManager2.java: Added the ability to
+	test for multiple permisson checks when in the mode that aborts
+	the test after the permissions have been checked.
+
 2006-02-15  David Gilbert  <david.gilbert@object-refinery.com>
 
 	* gnu/testlet/javax/swing/JSpinner/NumberEditor/constructors.java: New test,
Index: gnu/testlet/TestSecurityManager2.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/TestSecurityManager2.java,v
retrieving revision 1.6
diff -u -r1.6 TestSecurityManager2.java
--- gnu/testlet/TestSecurityManager2.java	31 Jan 2006 15:00:54 -0000	1.6
+++ gnu/testlet/TestSecurityManager2.java	16 Feb 2006 10:28:27 -0000
@@ -100,8 +100,6 @@
     this.mustCheck = mustCheck;
     this.checked = new boolean[mustCheck.length];
     this.throwOnSuccess = throwOnSuccess;
-    if (throwOnSuccess && mustCheck.length != 1)
-      throw new IllegalArgumentException();
   }
 
   public void checkAllChecked(TestHarness harness) {
@@ -135,9 +133,16 @@
       }
     }
 
-    if (matched && throwOnSuccess)
-      throw new SecurityException(successMessage);
-    
+    if (throwOnSuccess) {
+      boolean allChecked = true;
+      for (int i = 0; i < checked.length; i++) {
+	if (!checked[i])
+	  allChecked = false;
+      }
+      if (allChecked)
+	throw new SecurityException(successMessage);
+    }
+
     expectedPerms.append(" May check:");
     if (!matched) {
       for (int i = 0; i < mayCheck.length; i++) {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* FYI: Test security manager new feature
@ 2006-01-27 11:58 Gary Benson
  0 siblings, 0 replies; 2+ messages in thread
From: Gary Benson @ 2006-01-27 11:58 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 273 bytes --]

Hi all,

This commit adds a new way to run throwpoint checks to the test
security manager.  You can now make it throw an exception when the
expected permission is checked, which allows you to test things you
don't actually want to do, such as exiting the VM.

Cheers,
Gary

[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 2391 bytes --]

Index: ChangeLog
===================================================================
RCS file: /cvs/mauve/mauve/ChangeLog,v
retrieving revision 1.1377
diff -u -r1.1377 ChangeLog
--- ChangeLog	26 Jan 2006 19:29:36 -0000	1.1377
+++ ChangeLog	27 Jan 2006 11:54:49 -0000
@@ -1,3 +1,9 @@
+2006-01-27  Gary Benson <gbenson@redhat.com>
+
+	* gnu/testlet/TestSecurityManager2.java: Added the ability to
+	abort tests when the permission is checked, to allow us to test
+	things that we don't actually want doing.
+
 2006-01-27  Raif S. Naffah  <raif@swiftdsl.com.au>
 
 	* gnu/testlet/javax/crypto/jce/TestOfPR25981.java: New test.
Index: gnu/testlet/TestSecurityManager2.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/TestSecurityManager2.java,v
retrieving revision 1.4
diff -u -r1.4 TestSecurityManager2.java
--- gnu/testlet/TestSecurityManager2.java	16 Jan 2006 11:17:41 -0000	1.4
+++ gnu/testlet/TestSecurityManager2.java	27 Jan 2006 11:54:49 -0000
@@ -35,6 +35,10 @@
 		     new PropertyPermission("*", "read")};
   private boolean[] checked = new boolean[0];
 
+  private boolean throwOnSuccess = false;
+
+  public static final String successMessage = "Test complete, aborting";
+
   private final TestHarness harness;
 
   public TestSecurityManager2(TestHarness harness) {
@@ -56,6 +60,7 @@
 
   public void uninstall()
   {
+    throwOnSuccess = false;
     mayCheck = new Permission[]{new RuntimePermission("setSecurityManager")};
     System.setSecurityManager(oldManager);
   }
@@ -75,9 +80,18 @@
   }
 
   public void prepareChecks(Permission[] mustCheck, Permission[] mayCheck) {
+    prepareChecks(mustCheck, mayCheck, false);
+  }
+      
+  public void prepareChecks(Permission[] mustCheck,
+			    Permission[] mayCheck,
+			    boolean throwOnSuccess) {
     this.mayCheck = mayCheck;
     this.mustCheck = mustCheck;
     this.checked = new boolean[mustCheck.length];
+    this.throwOnSuccess = throwOnSuccess;
+    if (throwOnSuccess && mustCheck.length != 1)
+      throw new IllegalArgumentException();
   }
 
   public void checkAllChecked(TestHarness harness) {
@@ -111,6 +125,9 @@
       }
     }
 
+    if (matched && throwOnSuccess)
+      throw new SecurityException(successMessage);
+    
     expectedPerms.append(" May check:");
     if (!matched) {
       for (int i = 0; i < mayCheck.length; i++) {

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-02-16 10:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-16 10:33 FYI: Test security manager new feature Gary Benson
  -- strict thread matches above, loose matches on Subject: below --
2006-01-27 11:58 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).