001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.midp.security;
028:
029: import com.sun.midp.i3test.*;
030:
031: /**
032: * Unit tests for the Permissions class.
033: */
034: public class TestPermissions extends TestCase {
035:
036: /**
037: */
038: void setUp() {
039: }
040:
041: /**
042: */
043: void tearDown() {
044: }
045:
046: /**
047: * Runs all tests.
048: */
049: public void runTests() throws Throwable {
050: setUp();
051: declare("testSetPermissionGroupRuntime");
052: testSetPermissionGroupRuntime();
053: declare("testSetPermissionGroupAppSettings");
054: testSetPermissionGroupAppSettings();
055: declare("testCheckPushInterruptLevel");
056: testCheckPushInterruptLevel();
057: tearDown();
058: }
059:
060: /**
061: * Tests the method setPermissionGroup for the correct grouping for
062: * the runtime dialog.
063: */
064: void testSetPermissionGroupRuntime() {
065: byte[][] temp = Permissions
066: .forDomain(Permissions.UNIDENTIFIED_DOMAIN_BINDING);
067: int push = temp[Permissions.CUR_LEVELS][Permissions.PUSH];
068:
069: assertFalse(
070: "default permission level for HTTPS is ONESHOT",
071: Permissions.ONESHOT != temp[Permissions.CUR_LEVELS][Permissions.HTTPS]);
072:
073: Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
074: Permissions.HTTP, Permissions.SESSION);
075:
076: assertEquals(
077: "changed HTTP permissions, HTTPS permissions must also change",
078: Permissions.SESSION,
079: temp[Permissions.CUR_LEVELS][Permissions.HTTPS]);
080:
081: assertEquals("but PUSH permissions must not change", push,
082: temp[Permissions.CUR_LEVELS][Permissions.PUSH]);
083: }
084:
085: /**
086: * Tests the method setPermissionGroup used by app settings to ensure
087: * that mutally exclusive permission combinations using the Third Party
088: * Indentified domain do not occur.
089: */
090: void testSetPermissionGroupAppSettings() {
091: boolean securityExceptionThrown;
092: byte[][] temp = Permissions
093: .forDomain(Permissions.IDENTIFIED_DOMAIN_BINDING);
094:
095: Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
096: (byte) 0, Permissions.NET_ACCESS_GROUP,
097: Permissions.BLANKET_GRANTED);
098: try {
099: securityExceptionThrown = false;
100: Permissions.setPermissionGroup(
101: temp[Permissions.CUR_LEVELS], (byte) 0,
102: Permissions.MULTIMEDIA_GROUP,
103: Permissions.BLANKET_GRANTED);
104: } catch (SecurityException se) {
105: securityExceptionThrown = true;
106: }
107:
108: assertTrue(securityExceptionThrown);
109:
110: try {
111: securityExceptionThrown = false;
112: Permissions.setPermissionGroup(
113: temp[Permissions.CUR_LEVELS], (byte) 0,
114: Permissions.READ_USER_DATA_GROUP,
115: Permissions.BLANKET_GRANTED);
116: } catch (SecurityException se) {
117: securityExceptionThrown = true;
118: }
119:
120: Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
121: (byte) 0, Permissions.NET_ACCESS_GROUP,
122: Permissions.SESSION);
123: Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
124: (byte) 0, Permissions.MULTIMEDIA_GROUP,
125: Permissions.BLANKET_GRANTED);
126:
127: try {
128: Permissions.setPermissionGroup(
129: temp[Permissions.CUR_LEVELS], (byte) 0,
130: Permissions.NET_ACCESS_GROUP,
131: Permissions.BLANKET_GRANTED);
132: } catch (SecurityException se) {
133: securityExceptionThrown = true;
134: }
135:
136: assertTrue(securityExceptionThrown);
137:
138: Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
139: (byte) 0, Permissions.MULTIMEDIA_GROUP,
140: Permissions.SESSION);
141: Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
142: (byte) 0, Permissions.READ_USER_DATA_GROUP,
143: Permissions.BLANKET_GRANTED);
144: try {
145: Permissions.setPermissionGroup(
146: temp[Permissions.CUR_LEVELS], (byte) 0,
147: Permissions.NET_ACCESS_GROUP,
148: Permissions.BLANKET_GRANTED);
149: } catch (SecurityException se) {
150: securityExceptionThrown = true;
151: }
152:
153: assertTrue(securityExceptionThrown);
154:
155: try {
156: securityExceptionThrown = false;
157: Permissions.setPermissionGroup(
158: temp[Permissions.CUR_LEVELS],
159: Permissions.BLANKET_GRANTED,
160: Permissions.NET_ACCESS_GROUP,
161: Permissions.BLANKET_GRANTED);
162: } catch (SecurityException se) {
163: securityExceptionThrown = true;
164: }
165:
166: assertTrue(securityExceptionThrown);
167: }
168:
169: /** Test the checkPushInterruptLevel method. */
170: void testCheckPushInterruptLevel() {
171: boolean securityExceptionThrown;
172: byte[][] temp = Permissions
173: .forDomain(Permissions.IDENTIFIED_DOMAIN_BINDING);
174:
175: Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
176: (byte) 0, Permissions.NET_ACCESS_GROUP,
177: Permissions.BLANKET_GRANTED);
178:
179: try {
180: securityExceptionThrown = false;
181: Permissions.checkPushInterruptLevel(
182: temp[Permissions.CUR_LEVELS],
183: Permissions.BLANKET_GRANTED);
184: } catch (SecurityException se) {
185: securityExceptionThrown = true;
186: }
187:
188: assertTrue(securityExceptionThrown);
189: }
190: }
|