FileDocCategorySizeDatePackage
TestPermissions.javaAPI DocphoneME MR2 API (J2ME)7440Wed May 02 18:00:26 BST 2007com.sun.midp.security

TestPermissions

public class TestPermissions extends TestCase
Unit tests for the Permissions class.

Fields Summary
Constructors Summary
Methods Summary
public voidrunTests()
Runs all tests.

        setUp();
        declare("testSetPermissionGroupRuntime");
        testSetPermissionGroupRuntime();
        declare("testSetPermissionGroupAppSettings");
        testSetPermissionGroupAppSettings();
        declare("testCheckPushInterruptLevel");
        testCheckPushInterruptLevel();
        tearDown();
    
voidsetUp()

    
voidtearDown()

    
voidtestCheckPushInterruptLevel()
Test the checkPushInterruptLevel method.

        boolean securityExceptionThrown;
        byte [][] temp =
            Permissions.forDomain(Permissions.IDENTIFIED_DOMAIN_BINDING);

        Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
                                       (byte)0,
                                       Permissions.NET_ACCESS_GROUP,
                                       Permissions.BLANKET_GRANTED);

        try {
            securityExceptionThrown = false;
            Permissions.checkPushInterruptLevel(temp[Permissions.CUR_LEVELS],
                                    Permissions.BLANKET_GRANTED);
        } catch (SecurityException se) {
            securityExceptionThrown = true;
        }

        assertTrue(securityExceptionThrown);
    
voidtestSetPermissionGroupAppSettings()
Tests the method setPermissionGroup used by app settings to ensure that mutally exclusive permission combinations using the Third Party Indentified domain do not occur.

        boolean securityExceptionThrown;
        byte [][] temp =
            Permissions.forDomain(Permissions.IDENTIFIED_DOMAIN_BINDING);

        Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS], (byte)0,
                                       Permissions.NET_ACCESS_GROUP,
                                       Permissions.BLANKET_GRANTED);
        try {
            securityExceptionThrown = false;
            Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
                                           (byte)0,
                                           Permissions.MULTIMEDIA_GROUP,
                                           Permissions.BLANKET_GRANTED);
        } catch (SecurityException se) {
            securityExceptionThrown = true;
        }

        assertTrue(securityExceptionThrown);

        try {
            securityExceptionThrown = false;
            Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
                                           (byte)0,
                                           Permissions.READ_USER_DATA_GROUP,
                                           Permissions.BLANKET_GRANTED);
        } catch (SecurityException se) {
            securityExceptionThrown = true;
        }

        Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS], (byte)0,
                                       Permissions.NET_ACCESS_GROUP,
                                       Permissions.SESSION);
        Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
                                       (byte)0,
                                       Permissions.MULTIMEDIA_GROUP,
                                       Permissions.BLANKET_GRANTED);

        try {
            Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
                                           (byte)0,
                                           Permissions.NET_ACCESS_GROUP,
                                           Permissions.BLANKET_GRANTED);
        } catch (SecurityException se) {
            securityExceptionThrown = true;
        }

        assertTrue(securityExceptionThrown);

        Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
                                       (byte)0,
                                       Permissions.MULTIMEDIA_GROUP,
                                       Permissions.SESSION);
        Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
                                       (byte)0,
                                       Permissions.READ_USER_DATA_GROUP,
                                       Permissions.BLANKET_GRANTED);
        try {
            Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
                                           (byte)0,
                                           Permissions.NET_ACCESS_GROUP,
                                           Permissions.BLANKET_GRANTED);
        } catch (SecurityException se) {
            securityExceptionThrown = true;
        }

        assertTrue(securityExceptionThrown);

        try {
            securityExceptionThrown = false;
            Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
                                           Permissions.BLANKET_GRANTED,
                                           Permissions.NET_ACCESS_GROUP,
                                           Permissions.BLANKET_GRANTED);
        } catch (SecurityException se) {
            securityExceptionThrown = true;
        }

        assertTrue(securityExceptionThrown);
    
voidtestSetPermissionGroupRuntime()
Tests the method setPermissionGroup for the correct grouping for the runtime dialog.

        byte [][] temp =
              Permissions.forDomain(Permissions.UNIDENTIFIED_DOMAIN_BINDING);
        int push = temp[Permissions.CUR_LEVELS][Permissions.PUSH];

        assertFalse("default permission level for HTTPS is ONESHOT",
                    Permissions.ONESHOT !=
                    temp[Permissions.CUR_LEVELS][Permissions.HTTPS]);

        Permissions.setPermissionGroup(temp[Permissions.CUR_LEVELS],
                                       Permissions.HTTP,
                                       Permissions.SESSION);

        assertEquals("changed HTTP permissions, HTTPS permissions must also change",
                     Permissions.SESSION,
                     temp[Permissions.CUR_LEVELS][Permissions.HTTPS]);

        assertEquals("but PUSH permissions must not change",
                     push,
                     temp[Permissions.CUR_LEVELS][Permissions.PUSH]);