javacommons/security/tsrc/javasrc/com/nokia/mj/impl/security/midp/common/SecurityDescriptorAttributesTests.java
branchRCL_3
changeset 83 26b2b12093af
parent 71 d5e927d5853b
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
    37 /**
    37 /**
    38  * SecurityDescriptorAttributes unit tests.
    38  * SecurityDescriptorAttributes unit tests.
    39  */
    39  */
    40 public class SecurityDescriptorAttributesTests extends TestCase implements InstallerMain
    40 public class SecurityDescriptorAttributesTests extends TestCase implements InstallerMain
    41 {
    41 {
    42     int assertTrace = 0;
       
    43 
    42 
    44     /**
    43     /**
    45      * Hashtable holding all the attributes. Tests populate this hashtable
    44      * Hashtable holding all the attributes. Tests populate this hashtable
    46      * prior to being executed
    45      * prior to being executed
    47      */
    46      */
    77         midp2PermissionTargets.put(INTERNAL_SOCKET_PERMISSION, "socket://*");
    76         midp2PermissionTargets.put(INTERNAL_SOCKET_PERMISSION, "socket://*");
    78         midp2PermissionTargets.put(INTERNAL_HTTP_PERMISSION, "http://*");
    77         midp2PermissionTargets.put(INTERNAL_HTTP_PERMISSION, "http://*");
    79         midp2PermissionTargets.put(INTERNAL_HTTPS_PERMISSION, "https://*");
    78         midp2PermissionTargets.put(INTERNAL_HTTPS_PERMISSION, "https://*");
    80         midp2PermissionTargets.put(INTERNAL_SSL_PERMISSION, "ssl://*");
    79         midp2PermissionTargets.put(INTERNAL_SSL_PERMISSION, "ssl://*");
    81         midp2PermissionTargets.put(INTERNAL_DATAGRAM_PERMISSION,"datagram://*");
    80         midp2PermissionTargets.put(INTERNAL_DATAGRAM_PERMISSION,"datagram://*");
    82         midp2PermissionTargets.put(INTERNAL_COMM_PERMISSION, "comm:*");
    81         midp2PermissionTargets.put(INTERNAL_COMM_PERMISSION, "comm://*");
    83         midp2PermissionTargets.put(INTERNAL_PUSH_REGISTRY_PERMISSION, "*");
    82         midp2PermissionTargets.put(INTERNAL_PUSH_REGISTRY_PERMISSION, "*");
    84     }
    83     }
    85 
    84 
    86     // data being tested
    85     // data being tested
    87     protected SecurityAttributes securityAttributes;
    86     protected SecurityAttributes securityAttributes;
   163     protected void testAuthenticationAttributes()
   162     protected void testAuthenticationAttributes()
   164     {
   163     {
   165         // no attributes
   164         // no attributes
   166         allAttributes.clear();
   165         allAttributes.clear();
   167         authAttributes = securityAttributes.getAuthenticationAttributes();
   166         authAttributes = securityAttributes.getAuthenticationAttributes();
   168         assertWithTrace((authAttributes == null) || (authAttributes.length == 0));
   167         assertTrue((authAttributes == null) || (authAttributes.length == 0));
   169         // empty certificate attribute
   168         // empty certificate attribute
   170         try
   169         try
   171         {
   170         {
   172             allAttributes.clear();
   171             allAttributes.clear();
   173             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("", ""));
   172             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("", ""));
   174             securityAttributes = new SecurityAttributes();
   173             securityAttributes = new SecurityAttributes();
   175             securityAttributes.addDescriptorAttributes(allAttributes);
   174             securityAttributes.addDescriptorAttributes(allAttributes);
   176             assertWithTrace(false);
   175             assertTrue(EMPTY_CERTIFICATE_MSG, false);
   177         }
   176         }
   178         catch (InvalidAttributeException e)
   177         catch (InvalidAttributeException e)
   179         {
   178         {
   180             assertWithTrace(
   179             assertTrue(EMPTY_CERTIFICATE_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   181                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   180                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   182                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   181                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   183                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   182                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   184                                                         new String[] {AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1"})));
   183                                                         new String[] {AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1"})));
   185         }
   184         }
   188         {
   187         {
   189             allAttributes.clear();
   188             allAttributes.clear();
   190             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","?%cert"));
   189             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","?%cert"));
   191             securityAttributes = new SecurityAttributes();
   190             securityAttributes = new SecurityAttributes();
   192             securityAttributes.addDescriptorAttributes(allAttributes);
   191             securityAttributes.addDescriptorAttributes(allAttributes);
   193             assertWithTrace(false);
   192             assertTrue(INVALID_CERTIFICATE_MSG, false);
   194         }
   193         }
   195         catch (InvalidAttributeException e)
   194         catch (InvalidAttributeException e)
   196         {
   195         {
   197             assertWithTrace(
   196             assertTrue(INVALID_CERTIFICATE_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   198                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   197                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   199                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   198                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   200                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   199                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   201                                                         new String[] {AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1"})));
   200                                                         new String[] {AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1"})));
   202         }
   201         }
   203         // missing signature attribute
   202         // missing signature attribute
   204         allAttributes.clear();
   203         allAttributes.clear();
   205         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   204         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   206         securityAttributes = new SecurityAttributes();
   205         securityAttributes = new SecurityAttributes();
   207         securityAttributes.addDescriptorAttributes(allAttributes);
   206         securityAttributes.addDescriptorAttributes(allAttributes);
   208         assertWithTrace(securityAttributes.getAuthenticationAttributes() == null);
   207         assertTrue(securityAttributes.getAuthenticationAttributes() == null);
   209         // missing certificate attribute
   208         // missing certificate attribute
   210         try
   209         try
   211         {
   210         {
   212             allAttributes.clear();
   211             allAttributes.clear();
   213             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   212             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   214             securityAttributes = new SecurityAttributes();
   213             securityAttributes = new SecurityAttributes();
   215             securityAttributes.addDescriptorAttributes(allAttributes);
   214             securityAttributes.addDescriptorAttributes(allAttributes);
   216             assertWithTrace(false);
   215             assertTrue(MISSING_CERTIFICATE_ATTRIBUTE_MSG, false);
   217         }
   216         }
   218         catch (InvalidAttributeException e)
   217         catch (InvalidAttributeException e)
   219         {
   218         {
   220             assertWithTrace(
   219             assertTrue(MISSING_CERTIFICATE_ATTRIBUTE_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   221                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   220                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   222                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   221                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   223                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_MISSING,
   222                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_MISSING,
   224                                                         new String[] {AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1"})));
   223                                                         new String[] {AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1"})));
   225         }
   224         }
   229             allAttributes.clear();
   228             allAttributes.clear();
   230             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   229             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   231             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","?signature"));
   230             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","?signature"));
   232             securityAttributes = new SecurityAttributes();
   231             securityAttributes = new SecurityAttributes();
   233             securityAttributes.addDescriptorAttributes(allAttributes);
   232             securityAttributes.addDescriptorAttributes(allAttributes);
   234             assertWithTrace(false);
   233             assertTrue(INVALID_CERTIFICATE_SIGNATURE_MSG, false);
   235         }
   234         }
   236         catch (InvalidAttributeException e)
   235         catch (InvalidAttributeException e)
   237         {
   236         {
   238             assertWithTrace(
   237             assertTrue(INVALID_CERTIFICATE_SIGNATURE_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   239                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   238                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   240                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   239                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   241                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   240                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   242                                                         new String[] {AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME})));
   241                                                         new String[] {AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME})));
   243         }
   242         }
   248             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   247             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   249             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   248             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   250             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1", new Attribute("","?signature"));
   249             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1", new Attribute("","?signature"));
   251             securityAttributes = new SecurityAttributes();
   250             securityAttributes = new SecurityAttributes();
   252             securityAttributes.addDescriptorAttributes(allAttributes);
   251             securityAttributes.addDescriptorAttributes(allAttributes);
   253             assertWithTrace(false);
   252             assertTrue(INVALID_CERTIFICATE_SIGNATURE_MSG, false);
   254         }
   253         }
   255         catch (InvalidAttributeException e)
   254         catch (InvalidAttributeException e)
   256         {
   255         {
   257             assertWithTrace(
   256             assertTrue(INVALID_CERTIFICATE_SIGNATURE_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   258                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   257                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   259                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   258                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   260                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   259                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   261                                                         new String[] {AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1"})));
   260                                                         new String[] {AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1"})));
   262         }
   261         }
   267             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   266             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   268             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   267             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   269             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "2", new Attribute("","signature"));
   268             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "2", new Attribute("","signature"));
   270             securityAttributes = new SecurityAttributes();
   269             securityAttributes = new SecurityAttributes();
   271             securityAttributes.addDescriptorAttributes(allAttributes);
   270             securityAttributes.addDescriptorAttributes(allAttributes);
   272             assertWithTrace(false);
   271             assertTrue(MISSING_CERTIFICATE_ATTRIBUTE_MSG, false);
   273         }
   272         }
   274         catch (InvalidAttributeException e)
   273         catch (InvalidAttributeException e)
   275         {
   274         {
   276             assertWithTrace(
   275             assertTrue(MISSING_CERTIFICATE_ATTRIBUTE_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   277                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   276                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   278                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   277                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   279                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_MISSING,
   278                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_MISSING,
   280                                                         new String[] {AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "2-1"})));
   279                                                         new String[] {AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "2-1"})));
   281         }
   280         }
   285             allAttributes.clear();
   284             allAttributes.clear();
   286             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   285             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   287             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1", new Attribute("","signature"));
   286             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1", new Attribute("","signature"));
   288             securityAttributes = new SecurityAttributes();
   287             securityAttributes = new SecurityAttributes();
   289             securityAttributes.addDescriptorAttributes(allAttributes);
   288             securityAttributes.addDescriptorAttributes(allAttributes);
   290             assertWithTrace(false);
   289             assertTrue(MIDP3_ATTRIBUTE_NOT_ALLOWED_MSG, false);
   291         }
   290         }
   292         catch (InvalidAttributeException e)
   291         catch (InvalidAttributeException e)
   293         {
   292         {
   294             assertWithTrace(
   293             assertTrue(MIDP3_ATTRIBUTE_NOT_ALLOWED_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   295                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   294                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   296                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   295                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   297                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   296                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   298                                                         new String[] {AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1"})));
   297                                                         new String[] {AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1"})));
   299         }
   298         }
   304             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   303             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   305             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   304             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   306             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   305             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   307             securityAttributes = new SecurityAttributes();
   306             securityAttributes = new SecurityAttributes();
   308             securityAttributes.addDescriptorAttributes(allAttributes);
   307             securityAttributes.addDescriptorAttributes(allAttributes);
   309             assertWithTrace(false);
   308             assertTrue(MIDP2_SIGNATURE_NOT_ALLOWED_MSG, false);
   310         }
   309         }
   311         catch (InvalidAttributeException e)
   310         catch (InvalidAttributeException e)
   312         {
   311         {
   313             assertWithTrace(
   312             assertTrue(MIDP2_SIGNATURE_NOT_ALLOWED_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   314                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   313                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   315                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   314                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   316                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   315                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   317                                                         new String[] {AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME})));
   316                                                         new String[] {AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME})));
   318         }
   317         }
   325             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   324             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert"));
   326             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1", new Attribute("","signature"));
   325             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1", new Attribute("","signature"));
   327             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   326             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   328             securityAttributes = new SecurityAttributes();
   327             securityAttributes = new SecurityAttributes();
   329             securityAttributes.addDescriptorAttributes(allAttributes);
   328             securityAttributes.addDescriptorAttributes(allAttributes);
   330             assertWithTrace(false);
   329             assertTrue(MIDP2_SIGNATURE_NOT_ALLOWED_MSG, false);
   331         }
   330         }
   332         catch (InvalidAttributeException e)
   331         catch (InvalidAttributeException e)
   333         {
   332         {
   334             assertWithTrace(
   333             assertTrue(MIDP2_SIGNATURE_NOT_ALLOWED_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   335                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   334                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   336                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   335                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   337                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   336                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   338                                                         new String[] {AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME})));
   337                                                         new String[] {AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME})));
   339         }
   338         }
   343         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   342         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   344         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   343         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   345         securityAttributes = new SecurityAttributes();
   344         securityAttributes = new SecurityAttributes();
   346         securityAttributes.addDescriptorAttributes(allAttributes);
   345         securityAttributes.addDescriptorAttributes(allAttributes);
   347         authAttributes = securityAttributes.getAuthenticationAttributes();
   346         authAttributes = securityAttributes.getAuthenticationAttributes();
   348         assertWithTrace(authAttributes != null
   347         assertTrue(authAttributes != null
   349                    && authAttributes.length == 1
   348                    && authAttributes.length == 1
   350                    && checkChainsAndSignatures(authAttributes,
   349                    && checkChainsAndSignatures(authAttributes,
   351                                                new String[] {"cert1", "cert2"},
   350                                                new String[] {"cert1", "cert2"},
   352                                                new String[] {"signature"}));
   351                                                new String[] {"signature"}));
   353         // 2 identical certificate chains and 1 signature -> only one chain and signature returned (duplicates ignored)
   352         // 2 identical certificate chains and 1 signature -> only one chain and signature returned (duplicates ignored)
   359         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "2-2", new Attribute("","cert2"));
   358         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "2-2", new Attribute("","cert2"));
   360         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   359         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   361         securityAttributes = new SecurityAttributes();
   360         securityAttributes = new SecurityAttributes();
   362         securityAttributes.addDescriptorAttributes(allAttributes);
   361         securityAttributes.addDescriptorAttributes(allAttributes);
   363         authAttributes = securityAttributes.getAuthenticationAttributes();
   362         authAttributes = securityAttributes.getAuthenticationAttributes();
   364         assertWithTrace(authAttributes != null
   363         assertTrue(authAttributes != null
   365                    && authAttributes.length == 1
   364                    && authAttributes.length == 1
   366                    && checkChainsAndSignatures(authAttributes,
   365                    && checkChainsAndSignatures(authAttributes,
   367                                                new String[] {"cert1", "cert2"},
   366                                                new String[] {"cert1", "cert2"},
   368                                                new String[] {"signature"}));
   367                                                new String[] {"signature"}));
   369         // 2 identical certificate chains and 2 signatures -> only one chain and signature returned (duplicates ignored)
   368         // 2 identical certificate chains and 2 signatures -> only one chain and signature returned (duplicates ignored)
   376         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "2-2", new Attribute("","cert2"));
   375         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "2-2", new Attribute("","cert2"));
   377         allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "2", new Attribute("","signature"));
   376         allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "2", new Attribute("","signature"));
   378         securityAttributes = new SecurityAttributes();
   377         securityAttributes = new SecurityAttributes();
   379         securityAttributes.addDescriptorAttributes(allAttributes);
   378         securityAttributes.addDescriptorAttributes(allAttributes);
   380         authAttributes = securityAttributes.getAuthenticationAttributes();
   379         authAttributes = securityAttributes.getAuthenticationAttributes();
   381         assertWithTrace(authAttributes != null
   380         assertTrue(authAttributes != null
   382                    && authAttributes.length == 1
   381                    && authAttributes.length == 1
   383                    && checkChainsAndSignatures(authAttributes,
   382                    && checkChainsAndSignatures(authAttributes,
   384                                                new String[] {"cert1", "cert2"},
   383                                                new String[] {"cert1", "cert2"},
   385                                                new String[] {"signature"}));
   384                                                new String[] {"signature"}));
   386         // one certificate chain with 2 certificates and signature
   385         // one certificate chain with 2 certificates and signature
   390         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-4", new Attribute("","cert4"));
   389         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-4", new Attribute("","cert4"));
   391         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   390         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   392         securityAttributes = new SecurityAttributes();
   391         securityAttributes = new SecurityAttributes();
   393         securityAttributes.addDescriptorAttributes(allAttributes);
   392         securityAttributes.addDescriptorAttributes(allAttributes);
   394         authAttributes = securityAttributes.getAuthenticationAttributes();
   393         authAttributes = securityAttributes.getAuthenticationAttributes();
   395         assertWithTrace(authAttributes != null
   394         assertTrue(authAttributes != null
   396                    && authAttributes.length == 1
   395                    && authAttributes.length == 1
   397                    && checkChainsAndSignatures(authAttributes,
   396                    && checkChainsAndSignatures(authAttributes,
   398                                                new String[] {"cert1", "cert2"},
   397                                                new String[] {"cert1", "cert2"},
   399                                                new String[] {"signature"}));
   398                                                new String[] {"signature"}));
   400         // two certificate chains with missing one signature -> pick up the valid certificate and ignore the invalid one
   399         // two certificate chains with missing one signature -> pick up the valid certificate and ignore the invalid one
   409         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "4-2", new Attribute("","cert42"));
   408         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "4-2", new Attribute("","cert42"));
   410         allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1" , new Attribute("","signature1"));
   409         allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1" , new Attribute("","signature1"));
   411         securityAttributes = new SecurityAttributes();
   410         securityAttributes = new SecurityAttributes();
   412         securityAttributes.addDescriptorAttributes(allAttributes);
   411         securityAttributes.addDescriptorAttributes(allAttributes);
   413         authAttributes = securityAttributes.getAuthenticationAttributes();
   412         authAttributes = securityAttributes.getAuthenticationAttributes();
   414         assertWithTrace(authAttributes != null
   413         assertTrue(authAttributes != null
   415                    && authAttributes.length == 1
   414                    && authAttributes.length == 1
   416                    && checkChainsAndSignatures(authAttributes,
   415                    && checkChainsAndSignatures(authAttributes,
   417                                                new String[] {"cert11", "cert12"},
   416                                                new String[] {"cert11", "cert12"},
   418                                                new String[] {"signature1"}));
   417                                                new String[] {"signature1"}));
   419         // two invalid certificate chains: first one with missing signature, the second one invalid certificate -> signal the invalid certificate
   418         // two invalid certificate chains: first one with missing signature, the second one invalid certificate -> signal the invalid certificate
   429             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "4-1", new Attribute("","cert41"));
   428             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "4-1", new Attribute("","cert41"));
   430             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "4-2", new Attribute("","cert42"));
   429             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "4-2", new Attribute("","cert42"));
   431             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "2" , new Attribute("","signature2"));
   430             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "2" , new Attribute("","signature2"));
   432             securityAttributes = new SecurityAttributes();
   431             securityAttributes = new SecurityAttributes();
   433             securityAttributes.addDescriptorAttributes(allAttributes);
   432             securityAttributes.addDescriptorAttributes(allAttributes);
   434             assertWithTrace(false);
   433             assertTrue(CERTIFICATE_WITHOUT_SIGNATURE_MSG, false);
   435         }
   434         }
   436         catch (InvalidAttributeException e)
   435         catch (InvalidAttributeException e)
   437         {
   436         {
   438             assertWithTrace(
   437             assertTrue(INVALID_CERTIFICATE_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   439                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   438                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   440                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   439                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   441                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   440                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   442                                                         new String[] {AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "2-2"})));
   441                                                         new String[] {AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "2-2"})));
   443         }
   442         }
   451             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert11"));
   450             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert11"));
   452             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","*cert12"));
   451             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","*cert12"));
   453             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1" , new Attribute("","signature1"));
   452             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "1" , new Attribute("","signature1"));
   454             securityAttributes = new SecurityAttributes();
   453             securityAttributes = new SecurityAttributes();
   455             securityAttributes.addDescriptorAttributes(allAttributes);
   454             securityAttributes.addDescriptorAttributes(allAttributes);
   456             assertWithTrace(false);
   455             assertTrue(INVALID_CERTIFICATE_MSG, false);
   457         }
   456         }
   458         catch (InvalidAttributeException e)
   457         catch (InvalidAttributeException e)
   459         {
   458         {
   460             assertWithTrace(
   459             assertTrue(INVALID_CERTIFICATE_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   461                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   460                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   462                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   461                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   463                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   462                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   464                                                         new String[] {AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2"})));
   463                                                         new String[] {AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2"})));
   465         }
   464         }
   478         allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "2" , new Attribute("","signature2"));
   477         allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "2" , new Attribute("","signature2"));
   479         allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "5" , new Attribute("","signature5"));
   478         allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + "5" , new Attribute("","signature5"));
   480         securityAttributes = new SecurityAttributes();
   479         securityAttributes = new SecurityAttributes();
   481         securityAttributes.addDescriptorAttributes(allAttributes);
   480         securityAttributes.addDescriptorAttributes(allAttributes);
   482         authAttributes = securityAttributes.getAuthenticationAttributes();
   481         authAttributes = securityAttributes.getAuthenticationAttributes();
   483         assertWithTrace(authAttributes != null
   482         assertTrue(authAttributes != null
   484                    && authAttributes.length == 2
   483                    && authAttributes.length == 2
   485                    && checkChainsAndSignatures(authAttributes,
   484                    && checkChainsAndSignatures(authAttributes,
   486                                                new String[] {"cert11", "cert12", "cert21", "cert22", "cert23"},
   485                                                new String[] {"cert11", "cert12", "cert21", "cert22", "cert23"},
   487                                                new String[] {"signature1", "signature2"}));
   486                                                new String[] {"signature1", "signature2"}));
   488         // 100 certificate chains (10 certificates each) with 100 signatures
   487         // 100 certificate chains (10 certificates each) with 100 signatures
   497             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + i , new Attribute("","signature" + i));
   496             allAttributes.put(AuthenticationAttribute.SECOND_ATTRIBUTE_PREFIX + i , new Attribute("","signature" + i));
   498         }
   497         }
   499         securityAttributes = new SecurityAttributes();
   498         securityAttributes = new SecurityAttributes();
   500         securityAttributes.addDescriptorAttributes(allAttributes);
   499         securityAttributes.addDescriptorAttributes(allAttributes);
   501         authAttributes = securityAttributes.getAuthenticationAttributes();
   500         authAttributes = securityAttributes.getAuthenticationAttributes();
   502         assertWithTrace(authAttributes != null && authAttributes.length == 100);
   501         assertTrue(authAttributes != null && authAttributes.length == 100);
   503         for (int i=0; i<100; i++)
   502         for (int i=0; i<100; i++)
   504         {
   503         {
   505             // make sure we have 10 certs in each chain and a corresponding signature
   504             // make sure we have 10 certs in each chain and a corresponding signature
   506             assertWithTrace(authAttributes[i].getCertChain() != null
   505             assertTrue(authAttributes[i].getCertChain() != null
   507                        && authAttributes[i].getSignature() != null
   506                        && authAttributes[i].getSignature() != null
   508                        && authAttributes[i].getCertChain().length == 10
   507                        && authAttributes[i].getCertChain().length == 10
   509                        && authAttributes[i].getSignature().equals("signature" + (i+1)));
   508                        && authAttributes[i].getSignature().equals("signature" + (i+1)));
   510             // check each chain
   509             // check each chain
   511             for (int j=0; j<10; j++)
   510             for (int j=0; j<10; j++)
   512             {
   511             {
   513                 assertWithTrace((authAttributes[i].getCertChain())[j]
   512                 assertTrue((authAttributes[i].getCertChain())[j]
   514                            .equals("cert" + (i+1) + "" + (j+1)));
   513                            .equals("cert" + (i+1) + "" + (j+1)));
   515             }
   514             }
   516         }
   515         }
   517     }
   516     }
   518 
   517 
   525             allAttributes.clear();
   524             allAttributes.clear();
   526             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   525             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   527             allAttributes.put(PermissionAttribute.MANDATORY_LEGACY_ATTRIBUTE_NAME, new Attribute("","Perm1, Perm2"));
   526             allAttributes.put(PermissionAttribute.MANDATORY_LEGACY_ATTRIBUTE_NAME, new Attribute("","Perm1, Perm2"));
   528             securityAttributes = new SecurityAttributes();
   527             securityAttributes = new SecurityAttributes();
   529             securityAttributes.addDescriptorAttributes(allAttributes);
   528             securityAttributes.addDescriptorAttributes(allAttributes);
   530             assertWithTrace(false);
   529             assertTrue(LEGACY_NOT_ALLOWED_MSG, false);
   531         }
   530         }
   532         catch (InvalidAttributeException e)
   531         catch (InvalidAttributeException e)
   533         {
   532         {
   534             assertWithTrace(
   533             assertTrue(LEGACY_NOT_ALLOWED_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   535                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   534                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   536                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   535                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   537                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   536                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   538                                                         new String[] {PermissionAttribute.MANDATORY_LEGACY_ATTRIBUTE_NAME})));
   537                                                         new String[] {PermissionAttribute.MANDATORY_LEGACY_ATTRIBUTE_NAME})));
   539         }
   538         }
   543             allAttributes.clear();
   542             allAttributes.clear();
   544             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   543             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   545             allAttributes.put(PermissionAttribute.OPTIONAL_LEGACY_ATTRIBUTE_NAME, new Attribute("","Perm1, Perm2"));
   544             allAttributes.put(PermissionAttribute.OPTIONAL_LEGACY_ATTRIBUTE_NAME, new Attribute("","Perm1, Perm2"));
   546             securityAttributes = new SecurityAttributes();
   545             securityAttributes = new SecurityAttributes();
   547             securityAttributes.addDescriptorAttributes(allAttributes);
   546             securityAttributes.addDescriptorAttributes(allAttributes);
   548             assertWithTrace(false);
   547             assertTrue(LEGACY_NOT_ALLOWED_MSG, false);
   549         }
   548         }
   550         catch (InvalidAttributeException e)
   549         catch (InvalidAttributeException e)
   551         {
   550         {
   552             assertWithTrace(
   551             assertTrue(LEGACY_NOT_ALLOWED_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   553                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   552                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   554                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   553                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   555                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   554                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   556                                                         new String[] {PermissionAttribute.OPTIONAL_LEGACY_ATTRIBUTE_NAME})));
   555                                                         new String[] {PermissionAttribute.OPTIONAL_LEGACY_ATTRIBUTE_NAME})));
   557         }
   556         }
   562             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP2));
   561             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP2));
   563             allAttributes.put(PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1",
   562             allAttributes.put(PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1",
   564                               new Attribute("","PermissionClassName TargetName ActionList"));
   563                               new Attribute("","PermissionClassName TargetName ActionList"));
   565             securityAttributes = new SecurityAttributes();
   564             securityAttributes = new SecurityAttributes();
   566             securityAttributes.addDescriptorAttributes(allAttributes);
   565             securityAttributes.addDescriptorAttributes(allAttributes);
   567             assertWithTrace(false);
   566             assertTrue(MIDP3_ATTRIBUTE_NOT_ALLOWED_MSG, false);
   568         }
   567         }
   569         catch (InvalidAttributeException e)
   568         catch (InvalidAttributeException e)
   570         {
   569         {
   571             assertWithTrace(
   570             assertTrue(MIDP3_ATTRIBUTE_NOT_ALLOWED_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   572                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   571                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   573                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   572                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   574                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   573                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   575                                                         new String[] {PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1"})));
   574                                                         new String[] {PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1"})));
   576         }
   575         }
   581             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP2));
   580             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP2));
   582             allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",
   581             allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",
   583                               new Attribute("","PermissionClassName TargetName ActionList"));
   582                               new Attribute("","PermissionClassName TargetName ActionList"));
   584             securityAttributes = new SecurityAttributes();
   583             securityAttributes = new SecurityAttributes();
   585             securityAttributes.addDescriptorAttributes(allAttributes);
   584             securityAttributes.addDescriptorAttributes(allAttributes);
   586             assertWithTrace(false);
   585             assertTrue(MIDP3_ATTRIBUTE_NOT_ALLOWED_MSG, false);
   587         }
   586         }
   588         catch (InvalidAttributeException e)
   587         catch (InvalidAttributeException e)
   589         {
   588         {
   590             assertWithTrace(
   589             assertTrue(MIDP3_ATTRIBUTE_NOT_ALLOWED_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   591                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   590                        e.getOtaStatusCode() == OtaStatusCode.INVALID_DESCRIPTOR
   592                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   591                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   593                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   592                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   594                                                         new String[] {PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1"})));
   593                                                         new String[] {PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1"})));
   595         }
   594         }
   600         allAttributes.put(PermissionAttribute.MANDATORY_LEGACY_ATTRIBUTE_NAME,
   599         allAttributes.put(PermissionAttribute.MANDATORY_LEGACY_ATTRIBUTE_NAME,
   601                           new Attribute("","PermissionClassName TargetName ActionList"));
   600                           new Attribute("","PermissionClassName TargetName ActionList"));
   602         securityAttributes = new SecurityAttributes();
   601         securityAttributes = new SecurityAttributes();
   603         securityAttributes.addDescriptorAttributes(allAttributes);
   602         securityAttributes.addDescriptorAttributes(allAttributes);
   604         permissionAttributes = securityAttributes.getPermissionAttributes();
   603         permissionAttributes = securityAttributes.getPermissionAttributes();
   605         assertWithTrace(permissionAttributes != null
   604         assertTrue(permissionAttributes != null
   606                    && permissionAttributes.length == 1
   605                    && permissionAttributes.length == 1
   607                    && permissionAttributes[0].isLegacyAttribute());
   606                    && permissionAttributes[0].isLegacyAttribute());
   608         // MIDP2 mandatory permissions handling - invalid permission value
   607         // MIDP2 mandatory permissions handling - invalid permission value
   609         try
   608         try
   610         {
   609         {
   615             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert1"));
   614             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert1"));
   616             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   615             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   617             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   616             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   618             securityAttributes = new SecurityAttributes();
   617             securityAttributes = new SecurityAttributes();
   619             securityAttributes.addDescriptorAttributes(allAttributes);
   618             securityAttributes.addDescriptorAttributes(allAttributes);
   620             assertWithTrace(false);
   619             assertTrue(UNKNOWN_PERMISSION_MSG, false);
   621         }
   620         }
   622         catch (InvalidAttributeException e)
   621         catch (InvalidAttributeException e)
   623         {
   622         {
   624             assertWithTrace(
   623             assertTrue(UNKNOWN_PERMISSION_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   625                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHORIZATION_FAILURE
   624                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHORIZATION_FAILURE
   626                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   625                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   627                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_UNSUPPORTED,
   626                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_UNSUPPORTED,
   628                                                         new String[] {PermissionAttribute.MANDATORY_LEGACY_ATTRIBUTE_NAME})));
   627                                                         new String[] {PermissionAttribute.MANDATORY_LEGACY_ATTRIBUTE_NAME})));
   629         }
   628         }
   639             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert1"));
   638             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert1"));
   640             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   639             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   641             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   640             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   642             securityAttributes = new SecurityAttributes();
   641             securityAttributes = new SecurityAttributes();
   643             securityAttributes.addDescriptorAttributes(allAttributes);
   642             securityAttributes.addDescriptorAttributes(allAttributes);
   644             assertWithTrace(false);
   643             assertTrue(UNKNOWN_PERMISSION_MSG, false);
   645         }
   644         }
   646         catch (InvalidAttributeException e)
   645         catch (InvalidAttributeException e)
   647         {
   646         {
   648             assertWithTrace(
   647             assertTrue(UNKNOWN_PERMISSION_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   649                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHORIZATION_FAILURE
   648                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHORIZATION_FAILURE
   650                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   649                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   651                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_UNSUPPORTED,
   650                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_UNSUPPORTED,
   652                                                         new String[] {PermissionAttribute.MANDATORY_LEGACY_ATTRIBUTE_NAME})));
   651                                                         new String[] {PermissionAttribute.MANDATORY_LEGACY_ATTRIBUTE_NAME})));
   653         }
   652         }
   662         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   661         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   663         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   662         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   664         securityAttributes = new SecurityAttributes();
   663         securityAttributes = new SecurityAttributes();
   665         securityAttributes.addDescriptorAttributes(allAttributes);
   664         securityAttributes.addDescriptorAttributes(allAttributes);
   666         permissionAttributes = securityAttributes.getPermissionAttributes();
   665         permissionAttributes = securityAttributes.getPermissionAttributes();
   667         assertWithTrace(permissionAttributes != null
   666         assertTrue(permissionAttributes != null
   668                    && permissionAttributes.length == 2
   667                    && permissionAttributes.length == 2
   669                    && checkImportance(permissionAttributes, 0, 2)
   668                    && checkImportance(permissionAttributes, 0, 2)
   670                    && checkNamesAndTargets(permissionAttributes,
   669                    && checkNamesAndTargets(permissionAttributes,
   671                                            new String[] {INTERNAL_SOCKET_PERMISSION, INTERNAL_HTTP_PERMISSION})
   670                                            new String[] {INTERNAL_SOCKET_PERMISSION, INTERNAL_HTTP_PERMISSION})
   672                    && checkActionLists(permissionAttributes));
   671                    && checkActionLists(permissionAttributes));
   680         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   679         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   681         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   680         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   682         securityAttributes = new SecurityAttributes();
   681         securityAttributes = new SecurityAttributes();
   683         securityAttributes.addDescriptorAttributes(allAttributes);
   682         securityAttributes.addDescriptorAttributes(allAttributes);
   684         permissionAttributes = securityAttributes.getPermissionAttributes();
   683         permissionAttributes = securityAttributes.getPermissionAttributes();
   685         assertWithTrace(permissionAttributes != null
   684         assertTrue(permissionAttributes != null
   686                    && permissionAttributes.length == 1
   685                    && permissionAttributes.length == 1
   687                    && checkImportance(permissionAttributes, 0, 1)
   686                    && checkImportance(permissionAttributes, 0, 1)
   688                    && checkNamesAndTargets(permissionAttributes,
   687                    && checkNamesAndTargets(permissionAttributes,
   689                                            new String[] {INTERNAL_SSL_PERMISSION})
   688                                            new String[] {INTERNAL_SSL_PERMISSION})
   690                    && checkActionLists(permissionAttributes));
   689                    && checkActionLists(permissionAttributes));
   697             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert1"));
   696             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert1"));
   698             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   697             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   699             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   698             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   700             securityAttributes = new SecurityAttributes();
   699             securityAttributes = new SecurityAttributes();
   701             securityAttributes.addDescriptorAttributes(allAttributes);
   700             securityAttributes.addDescriptorAttributes(allAttributes);
   702             assertWithTrace(true);
   701             assertTrue(UNKNOWN_PERMISSION_MSG, true);
   703         }
   702         }
   704         catch (InvalidAttributeException e)
   703         catch (InvalidAttributeException e)
   705         {
   704         {
   706             assertWithTrace(false);
   705             assertTrue(UNKNOWN_PERMISSION_MSG, false);
   707         }
   706         }
   708         // MIDP2 optional permissions handling - unknown permission value
   707         // MIDP2 optional permissions handling - unknown permission value
   709         try
   708         try
   710         {
   709         {
   711             allAttributes.clear();
   710             allAttributes.clear();
   715             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert1"));
   714             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-1", new Attribute("","cert1"));
   716             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   715             allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   717             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   716             allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   718             securityAttributes = new SecurityAttributes();
   717             securityAttributes = new SecurityAttributes();
   719             securityAttributes.addDescriptorAttributes(allAttributes);
   718             securityAttributes.addDescriptorAttributes(allAttributes);
   720             assertWithTrace(true);
   719             assertTrue(UNKNOWN_PERMISSION_MSG, true);
   721         }
   720         }
   722         catch (InvalidAttributeException e)
   721         catch (InvalidAttributeException e)
   723         {
   722         {
   724             assertWithTrace(false);
   723             assertTrue(UNKNOWN_PERMISSION_MSG, false);
   725         }
   724         }
   726         // MIDP2 optional permissions handling - known permission value
   725         // MIDP2 optional permissions handling - known permission value
   727         allAttributes.clear();
   726         allAttributes.clear();
   728         allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP2));
   727         allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP2));
   729         allAttributes.put(PermissionAttribute.OPTIONAL_LEGACY_ATTRIBUTE_NAME,
   728         allAttributes.put(PermissionAttribute.OPTIONAL_LEGACY_ATTRIBUTE_NAME,
   733         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   732         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   734         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   733         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   735         securityAttributes = new SecurityAttributes();
   734         securityAttributes = new SecurityAttributes();
   736         securityAttributes.addDescriptorAttributes(allAttributes);
   735         securityAttributes.addDescriptorAttributes(allAttributes);
   737         permissionAttributes = securityAttributes.getPermissionAttributes();
   736         permissionAttributes = securityAttributes.getPermissionAttributes();
   738         assertWithTrace(permissionAttributes != null
   737         assertTrue(permissionAttributes != null
   739                    && permissionAttributes.length == 2
   738                    && permissionAttributes.length == 2
   740                    && checkImportance(permissionAttributes, 2, 0)
   739                    && checkImportance(permissionAttributes, 2, 0)
   741                    && checkNamesAndTargets(permissionAttributes,
   740                    && checkNamesAndTargets(permissionAttributes,
   742                                            new String[]
   741                                            new String[]
   743                                            {
   742                                            {
   755         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   754         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   756         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   755         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   757         securityAttributes = new SecurityAttributes();
   756         securityAttributes = new SecurityAttributes();
   758         securityAttributes.addDescriptorAttributes(allAttributes);
   757         securityAttributes.addDescriptorAttributes(allAttributes);
   759         permissionAttributes = securityAttributes.getPermissionAttributes();
   758         permissionAttributes = securityAttributes.getPermissionAttributes();
   760         assertWithTrace(permissionAttributes != null
   759         assertTrue(permissionAttributes != null
   761                    && permissionAttributes.length == 1
   760                    && permissionAttributes.length == 1
   762                    && checkImportance(permissionAttributes, 1, 0)
   761                    && checkImportance(permissionAttributes, 1, 0)
   763                    && checkNamesAndTargets(permissionAttributes,
   762                    && checkNamesAndTargets(permissionAttributes,
   764                                            new String[] {INTERNAL_PUSH_REGISTRY_PERMISSION})
   763                                            new String[] {INTERNAL_PUSH_REGISTRY_PERMISSION})
   765                    && checkActionLists(permissionAttributes));
   764                    && checkActionLists(permissionAttributes));
   776         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   775         allAttributes.put(AuthenticationAttribute.MAIN_ATTRIBUTE_PREFIX + "1-2", new Attribute("","cert2"));
   777         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   776         allAttributes.put(AuthenticationAttribute.SECOND_LEGACY_ATTRIBUTE_NAME, new Attribute("","signature"));
   778         securityAttributes = new SecurityAttributes();
   777         securityAttributes = new SecurityAttributes();
   779         securityAttributes.addDescriptorAttributes(allAttributes);
   778         securityAttributes.addDescriptorAttributes(allAttributes);
   780         permissionAttributes = securityAttributes.getPermissionAttributes();
   779         permissionAttributes = securityAttributes.getPermissionAttributes();
   781         assertWithTrace(permissionAttributes != null
   780         assertTrue(permissionAttributes != null
   782                    && permissionAttributes.length == 4
   781                    && permissionAttributes.length == 4
   783                    && checkImportance(permissionAttributes, 2, 2)
   782                    && checkImportance(permissionAttributes, 2, 2)
   784                    && checkNamesAndTargets(permissionAttributes,
   783                    && checkNamesAndTargets(permissionAttributes,
   785                                            new String[]
   784                                            new String[]
   786                                            {
   785                                            {
   796         allAttributes.put(PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1",new Attribute("","MyMandatoryClass"));
   795         allAttributes.put(PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1",new Attribute("","MyMandatoryClass"));
   797         allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",new Attribute("","MyOptionalClass"));
   796         allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",new Attribute("","MyOptionalClass"));
   798         securityAttributes = new SecurityAttributes();
   797         securityAttributes = new SecurityAttributes();
   799         securityAttributes.addDescriptorAttributes(allAttributes);
   798         securityAttributes.addDescriptorAttributes(allAttributes);
   800         permissionAttributes = securityAttributes.getPermissionAttributes();
   799         permissionAttributes = securityAttributes.getPermissionAttributes();
   801         assertWithTrace(permissionAttributes != null
   800         assertTrue(permissionAttributes != null
   802                    && permissionAttributes.length == 2
   801                    && permissionAttributes.length == 2
   803                    && checkImportance(permissionAttributes, 1, 1)
   802                    && checkImportance(permissionAttributes, 1, 1)
   804                    && checkNamesAndTargets(permissionAttributes,
   803                    && checkNamesAndTargets(permissionAttributes,
   805                                            new String[] {"MyMandatoryClass", "MyOptionalClass"}, new String[] {null, null})
   804                                            new String[] {"MyMandatoryClass", "MyOptionalClass"}, new String[] {null, null})
   806                    && checkActionLists(permissionAttributes));
   805                    && checkActionLists(permissionAttributes));
   810         allAttributes.put(PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1",new Attribute("","MyMandatoryClass MyMandatoryTarget"));
   809         allAttributes.put(PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1",new Attribute("","MyMandatoryClass MyMandatoryTarget"));
   811         allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",new Attribute("","MyOptionalClass MyOptionalTarget"));
   810         allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",new Attribute("","MyOptionalClass MyOptionalTarget"));
   812         securityAttributes = new SecurityAttributes();
   811         securityAttributes = new SecurityAttributes();
   813         securityAttributes.addDescriptorAttributes(allAttributes);
   812         securityAttributes.addDescriptorAttributes(allAttributes);
   814         permissionAttributes = securityAttributes.getPermissionAttributes();
   813         permissionAttributes = securityAttributes.getPermissionAttributes();
   815         assertWithTrace(permissionAttributes != null
   814         assertTrue(permissionAttributes != null
   816                    && permissionAttributes.length == 2
   815                    && permissionAttributes.length == 2
   817                    && checkImportance(permissionAttributes, 1, 1)
   816                    && checkImportance(permissionAttributes, 1, 1)
   818                    && checkNamesAndTargets(permissionAttributes,
   817                    && checkNamesAndTargets(permissionAttributes,
   819                                            new String[] {"MyMandatoryClass", "MyOptionalClass"}, new String[] {"MyMandatoryTarget","MyOptionalTarget"})
   818                                            new String[] {"MyMandatoryClass", "MyOptionalClass"}, new String[] {"MyMandatoryTarget","MyOptionalTarget"})
   820                    && checkActionLists(permissionAttributes));
   819                    && checkActionLists(permissionAttributes));
   824         allAttributes.put(PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1",new Attribute("","MyMandatoryClass MyMandatoryTarget MyMandatoryAction1,MyMandatoryAction2,MyMandatoryAction3"));
   823         allAttributes.put(PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1",new Attribute("","MyMandatoryClass MyMandatoryTarget MyMandatoryAction1,MyMandatoryAction2,MyMandatoryAction3"));
   825         allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",new Attribute("","MyOptionalClass MyOptionalTarget MyOptionalAction"));
   824         allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",new Attribute("","MyOptionalClass MyOptionalTarget MyOptionalAction"));
   826         securityAttributes = new SecurityAttributes();
   825         securityAttributes = new SecurityAttributes();
   827         securityAttributes.addDescriptorAttributes(allAttributes);
   826         securityAttributes.addDescriptorAttributes(allAttributes);
   828         permissionAttributes = securityAttributes.getPermissionAttributes();
   827         permissionAttributes = securityAttributes.getPermissionAttributes();
   829         assertWithTrace(permissionAttributes != null
   828         assertTrue(permissionAttributes != null
   830                    && permissionAttributes.length == 2
   829                    && permissionAttributes.length == 2
   831                    && checkImportance(permissionAttributes, 1, 1)
   830                    && checkImportance(permissionAttributes, 1, 1)
   832                    && checkNamesAndTargets(permissionAttributes,
   831                    && checkNamesAndTargets(permissionAttributes,
   833                                            new String[] {"MyMandatoryClass", "MyOptionalClass"}, new String[] {"MyMandatoryTarget","MyOptionalTarget"})
   832                                            new String[] {"MyMandatoryClass", "MyOptionalClass"}, new String[] {"MyMandatoryTarget","MyOptionalTarget"})
   834                    && checkActionLists(permissionAttributes, new String[] {"MyMandatoryAction1,MyMandatoryAction2,MyMandatoryAction3", "MyOptionalAction"}));
   833                    && checkActionLists(permissionAttributes, new String[] {"MyMandatoryAction1,MyMandatoryAction2,MyMandatoryAction3", "MyOptionalAction"}));
   840         allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",new Attribute("","MyOptionalClass MyOptionalTarget MyOptionalAction"));
   839         allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",new Attribute("","MyOptionalClass MyOptionalTarget MyOptionalAction"));
   841         allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "2",new Attribute("","MyOptionalClass MyOptionalTarget MyOptionalAction"));
   840         allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "2",new Attribute("","MyOptionalClass MyOptionalTarget MyOptionalAction"));
   842         securityAttributes = new SecurityAttributes();
   841         securityAttributes = new SecurityAttributes();
   843         securityAttributes.addDescriptorAttributes(allAttributes);
   842         securityAttributes.addDescriptorAttributes(allAttributes);
   844         permissionAttributes = securityAttributes.getPermissionAttributes();
   843         permissionAttributes = securityAttributes.getPermissionAttributes();
   845         assertWithTrace(permissionAttributes != null
   844         assertTrue(permissionAttributes != null
   846                    && permissionAttributes.length == 2
   845                    && permissionAttributes.length == 2
   847                    && checkImportance(permissionAttributes, 1, 1)
   846                    && checkImportance(permissionAttributes, 1, 1)
   848                    && checkNamesAndTargets(permissionAttributes,
   847                    && checkNamesAndTargets(permissionAttributes,
   849                                            new String[] {"MyMandatoryClass", "MyOptionalClass"}, new String[] {"MyMandatoryTarget","MyOptionalTarget"})
   848                                            new String[] {"MyMandatoryClass", "MyOptionalClass"}, new String[] {"MyMandatoryTarget","MyOptionalTarget"})
   850                    && checkActionLists(permissionAttributes, new String[] {"MyMandatoryAction1,MyMandatoryAction2,MyMandatoryAction3", "MyOptionalAction"}));
   849                    && checkActionLists(permissionAttributes, new String[] {"MyMandatoryAction1,MyMandatoryAction2,MyMandatoryAction3", "MyOptionalAction"}));
   854             allAttributes.clear();
   853             allAttributes.clear();
   855             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   854             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   856             allAttributes.put(PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1",new Attribute("","MyMandatoryClass MyMandatoryTarget MyMandatoryAction1 MyMandatoryAction2"));
   855             allAttributes.put(PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1",new Attribute("","MyMandatoryClass MyMandatoryTarget MyMandatoryAction1 MyMandatoryAction2"));
   857             securityAttributes = new SecurityAttributes();
   856             securityAttributes = new SecurityAttributes();
   858             securityAttributes.addDescriptorAttributes(allAttributes);
   857             securityAttributes.addDescriptorAttributes(allAttributes);
   859             assertWithTrace(false);
   858             assertTrue(INVALID_PERMISSION_VALUE_MSG, false);
   860         }
   859         }
   861         catch (InvalidAttributeException e)
   860         catch (InvalidAttributeException e)
   862         {
   861         {
   863             assertWithTrace(
   862             assertTrue(INVALID_PERMISSION_VALUE_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   864                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   863                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   865                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   864                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   866                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   865                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   867                                                         new String[] {PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1"})));
   866                                                         new String[] {PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1"})));
   868         }
   867         }
   872             allAttributes.clear();
   871             allAttributes.clear();
   873             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   872             allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   874             allAttributes.put(PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1",new Attribute("","MyMandatoryClass   MyMandatoryTarget   MyMandatoryAction1 MyMandatoryAction2"));
   873             allAttributes.put(PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1",new Attribute("","MyMandatoryClass   MyMandatoryTarget   MyMandatoryAction1 MyMandatoryAction2"));
   875             securityAttributes = new SecurityAttributes();
   874             securityAttributes = new SecurityAttributes();
   876             securityAttributes.addDescriptorAttributes(allAttributes);
   875             securityAttributes.addDescriptorAttributes(allAttributes);
   877             assertWithTrace(false);
   876             assertTrue(INVALID_PERMISSION_VALUE_MSG, false);
   878         }
   877         }
   879         catch (InvalidAttributeException e)
   878         catch (InvalidAttributeException e)
   880         {
   879         {
   881             assertWithTrace(
   880             assertTrue(INVALID_PERMISSION_VALUE_MSG + e.getOtaStatusCode() + " " + e.getShortMessage() + "," + e.getDetailedMessage(),
   882                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   881                        e.getOtaStatusCode() == OtaStatusCode.APPLICATION_AUTHENTICATION_FAILURE
   883                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   882                        && e.getShortMessage().equals(errorMessage.get(InstallerErrorMessage.INST_CORRUPT_PKG, null))
   884                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   883                        && e.getDetailedMessage().equals(detailedErrorMessage.get(InstallerDetailedErrorMessage.ATTR_HANDLING_FAILED,
   885                                                         new String[] {PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1"})));
   884                                                         new String[] {PermissionAttribute.MANDATORY_ATTRIBUTE_PREFIX + "1"})));
   886         }
   885         }
   889         allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   888         allAttributes.put(MIDP_PROFILE_ATTRIBUTE_NAME,new Attribute("",MIDP3));
   890         allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",new Attribute("","    MyMandatoryClass            MyMandatoryTarget  MyMandatoryAction      "));
   889         allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",new Attribute("","    MyMandatoryClass            MyMandatoryTarget  MyMandatoryAction      "));
   891         securityAttributes = new SecurityAttributes();
   890         securityAttributes = new SecurityAttributes();
   892         securityAttributes.addDescriptorAttributes(allAttributes);
   891         securityAttributes.addDescriptorAttributes(allAttributes);
   893         permissionAttributes = securityAttributes.getPermissionAttributes();
   892         permissionAttributes = securityAttributes.getPermissionAttributes();
   894         assertWithTrace(permissionAttributes != null
   893         assertTrue(permissionAttributes != null
   895                    && permissionAttributes.length == 1
   894                    && permissionAttributes.length == 1
   896                    && checkImportance(permissionAttributes, 1, 0)
   895                    && checkImportance(permissionAttributes, 1, 0)
   897                    && checkNamesAndTargets(permissionAttributes,
   896                    && checkNamesAndTargets(permissionAttributes,
   898                                            new String[] {"MyMandatoryClass"}, new String[] {"MyMandatoryTarget"})
   897                                            new String[] {"MyMandatoryClass"}, new String[] {"MyMandatoryTarget"})
   899                    && checkActionLists(permissionAttributes, new String[] {"MyMandatoryAction"}));
   898                    && checkActionLists(permissionAttributes, new String[] {"MyMandatoryAction"}));
   931             try
   930             try
   932             {
   931             {
   933                 allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",new Attribute("",className + "            MyMandatoryTarget  MyMandatoryAction      "));
   932                 allAttributes.put(PermissionAttribute.OPTIONAL_ATTRIBUTE_PREFIX + "1",new Attribute("",className + "            MyMandatoryTarget  MyMandatoryAction      "));
   934                 securityAttributes = new SecurityAttributes();
   933                 securityAttributes = new SecurityAttributes();
   935                 securityAttributes.addDescriptorAttributes(allAttributes);
   934                 securityAttributes.addDescriptorAttributes(allAttributes);
   936                 assertWithTrace(false);
   935                 assertTrue(INVALID_PERMISSION_VALUE_MSG, false);
   937             }
   936             }
   938             catch (InvalidAttributeException e)
   937             catch (InvalidAttributeException e)
   939             {
   938             {
   940             }
   939             }
   941         }
   940         }
  1109             }
  1108             }
  1110         }
  1109         }
  1111         return (checkBoolArray(certsChecked) && checkBoolArray(signaturesChecked));
  1110         return (checkBoolArray(certsChecked) && checkBoolArray(signaturesChecked));
  1112     }
  1111     }
  1113 
  1112 
  1114     private void assertWithTrace(boolean aCondition)
       
  1115     {
       
  1116         assertTrue("" + assertTrace, aCondition);
       
  1117         assertTrace++;
       
  1118     }
       
  1119 
       
  1120 
       
  1121     private int findString(String str, String[] strings)
  1113     private int findString(String str, String[] strings)
  1122     {
  1114     {
  1123         for (int i=0; i<strings.length; i++)
  1115         for (int i=0; i<strings.length; i++)
  1124         {
  1116         {
  1125             if (str.equals(strings[i]))
  1117             if (str.equals(strings[i]))