/** * Verifies that passing a valid Intent to {@link BundleScrubber#scrub(Intent)} returns false and * does not mutate the Intent. */ @SmallTest public static void testScrubValidIntent() { { /* * An empty Intent should be valid and should not be mutated */ final Intent intent = new Intent(); assertNull(intent.getExtras()); assertFalse(BundleScrubber.scrub(intent)); assertNull(intent.getExtras()); } { /* * A non empty Intent should be valid and should not be mutated */ final Intent intent = new Intent().putExtra("test", "test"); // $NON-NLS-1$ //$NON-NLS-2$ assertFalse(BundleScrubber.scrub(intent)); assertEquals(1, intent.getExtras().keySet().size()); assertEquals("test", intent.getStringExtra("test")); // $NON-NLS-1$//$NON-NLS-2$ } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* * A hack to prevent a private serializable classloader attack */ BundleScrubber.scrub(getIntent()); BundleScrubber.scrub(getIntent().getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE)); setContentView(R.layout.activity_edit); isCancelled = false; /* * if savedInstanceState is null, then then this is a new Activity instance and a check for EXTRA_BUNDLE is needed */ if (null == savedInstanceState) { final Bundle forwardedBundle = getIntent().getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE); if (PluginBundleManager.isBundleValid(forwardedBundle)) { // PluginBundleManager.isBundleValid must be changed if elements are added to the bundle // ((EditText) findViewById(R.id.account_id)) .setText( String.valueOf( forwardedBundle.getLong(PluginBundleManager.BUNDLE_EXTRA_INT_ACCOUNT_ID))); ((CheckBox) findViewById(R.id.account_deactivate)) .setChecked( forwardedBundle.getBoolean(PluginBundleManager.BUNDLE_EXTRA_BOOL_DEACTIVATE)); } } }
/** Verifies that passing null to {@link BundleScrubber#scrub(Bundle)} returns false. */ @SmallTest public static void testScrubNullBundle() { assertFalse(BundleScrubber.scrub((Bundle) null)); }
/** Verifies that passing null to {@link BundleScrubber#scrub(Intent)} returns false. */ @SmallTest public static void testScrubNullIntent() { assertFalse(BundleScrubber.scrub((Intent) null)); }