Nanny { public static boolean isIntentFromPermissionNanny(Intent intent) throws NannyException { Bundle entity = intent.getBundleExtra(Nanny.ENTITY_BODY); if (entity == null) { throw new NannyException("ENTITY_BODY is missing."); } PendingIntent sender = entity.getParcelable(Nanny.SENDER_IDENTITY); if (sender == null) { throw new NannyException("SENDER_IDENTITY is missing."); } String senderPackage = sender.getIntentSender().getTargetPackage(); if (!Nanny.getServerAppId().equals(senderPackage)) { throw new NannyException(senderPackage + " is attempting to impersonate Permission Nanny."); } return true; }  @VisibleForTesting static void configureServer(boolean targetDebugBuild); static String getServerAppId(); static Uri getProxyContentProvider(); static boolean isPermissionNannyInstalled(@NonNull Context context); static boolean isIntentFromPermissionNanny(Intent intent); @PPP static final String PROTOCOL_VERSION; @PPP static final String PPP_0_1; @PPP static final String STATUS_CODE; @PPP static final int SC_OK; @PPP static final int SC_BAD_REQUEST; @PPP static final int SC_UNAUTHORIZED; @PPP static final int SC_FORBIDDEN; @PPP static final int SC_NOT_FOUND; @PPP static final int SC_TIMEOUT; @PPP static final String CLIENT_ADDRESS; @PPP static final String CONNECTION; @PPP static final String CLOSE; @PPP static final String SERVER; @PPP static final String AUTHORIZATION_SERVICE; @PPP static final String PERMISSION_MANIFEST_SERVICE; @PPP static final String LOCATION_SERVICE; @PPP static final String GPS_STATUS_SERVICE; @PPP static final String NMEA_SERVICE; @PPP static final String ACCOUNTS_UPDATE_SERVICE; @PPP static final String ENTITY_BODY; @PPP static final String ENTITY_ERROR; @PPP static final String TYPE; @PPP static final String REQUEST_PARAMS; @PPP @Deprecated static final String REQUEST_REASON; @PPP static final String REQUEST_RATIONALE; @PPP static final String SENDER_IDENTITY; @PPP static final String PERMISSION_MANIFEST; @PPP static final String ACK_SERVER_ADDRESS; @PPP static final String DEEP_LINK_TARGET; @PPP static final String MANAGE_APPLICATIONS_SETTINGS; @PPP static final String SERVER_PACKAGE_NAME; @PPP static final String SERVER_APP_ID; static final String SERVER_DEBUG_APP_ID; @PPP static final String CLIENT_REQUEST_RECEIVER; @PPP static final String CLIENT_PERMISSION_MANIFEST_RECEIVER; @PPP static final String CLIENT_DEEP_LINK_RECEIVER; @PPP static final String ACTION_GET_PERMISSION_MANIFEST; @PPP static final String PROVIDER_AUTHORITY; @PPP static final Uri PROVIDER; @PPP static final Uri DEBUG_PROVIDER; }
@Test public void isIntentFromPermissionNannyShouldReturnTrueWhenIntentIsValid() throws Exception { intent.putExtra(Nanny.ENTITY_BODY, entity); entity.putParcelable(Nanny.SENDER_IDENTITY, sender); mockPendingIntent(sender, Nanny.SERVER_APP_ID); boolean ans = Nanny.isIntentFromPermissionNanny(intent); assertThat(ans, is(true)); }
@Test(expected = NannyException.class) public void isIntentFromPermissionNannyShouldThrowWhenSenderIdentityIsWrong() throws Exception { intent.putExtra(Nanny.ENTITY_BODY, entity); entity.putParcelable(Nanny.SENDER_IDENTITY, sender); mockPendingIntent(sender, "3rd.party.app"); Nanny.isIntentFromPermissionNanny(intent); }
@Test(expected = NannyException.class) public void isIntentFromPermissionNannyShouldThrowWhenSenderIdentityIsMissing() throws Exception { intent.putExtra(Nanny.ENTITY_BODY, entity); Nanny.isIntentFromPermissionNanny(intent); }
@Test(expected = NannyException.class) public void isIntentFromPermissionNannyShouldThrowWhenEntityIsMissing() throws Exception { Nanny.isIntentFromPermissionNanny(intent); }