Skip to content

Commit

Permalink
use androidx preferences, fix translation errors, prevent zip path tr…
Browse files Browse the repository at this point in the history
…aversal attack
  • Loading branch information
friedger committed Nov 22, 2019
1 parent 06a3a99 commit b5060e6
Show file tree
Hide file tree
Showing 65 changed files with 534 additions and 494 deletions.
7 changes: 5 additions & 2 deletions FileManager/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
apply plugin: 'com.android.application'

dependencies {
implementation 'com.github.openintents:distribution:3.0.2'
implementation 'com.github.openintents:distribution:3.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "androidx.preference:preference:1.1.0"
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta3"

androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand All @@ -15,7 +19,6 @@ dependencies {

android {
compileSdkVersion compile_sdk_version
buildToolsVersion build_tools_version

defaultConfig {
applicationId "org.openintents.filemanager"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package androidTest.java.org.openintents.filemanager.test;
package org.openintents.filemanager.test;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.test.rule.ActivityTestRule;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;

import java.lang.reflect.Field;

import static android.app.Instrumentation.ActivityResult;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class ActivityResultTestRule<T extends Activity> extends ActivityTestRule<T> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package androidTest.java.org.openintents.filemanager.test;
package org.openintents.filemanager.test;

import androidx.test.espresso.ViewAssertion;
import androidx.test.espresso.matcher.BoundedMatcher;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;

import androidx.test.espresso.Espresso;
import androidx.test.espresso.ViewAssertion;
import androidx.test.espresso.action.ViewActions;
import androidx.test.espresso.matcher.BoundedMatcher;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
import org.openintents.filemanager.bookmarks.BookmarkListAdapter;
import org.openintents.filemanager.files.FileHolder;
Expand All @@ -16,14 +20,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.longClick;
import static androidx.test.espresso.action.ViewActions.pressBack;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import java.nio.charset.StandardCharsets;

public class BaseTestFileManager {
public static final String TEST_DIRECTORY = "oi-filemanager-tests";
Expand All @@ -49,7 +46,7 @@ protected static void cleanDirectory(File file) {

protected static void createFile(String path, String content) throws IOException {
File file = new File(path);
OutputStreamWriter wr = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
OutputStreamWriter wr = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
wr.write(content);
wr.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package androidTest.java.org.openintents.filemanager.test;
package org.openintents.filemanager.test;

import androidx.test.espresso.IdlingResource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
* limitations under the License.
*/

package androidTest.java.org.openintents.filemanager.test;
package org.openintents.filemanager.test;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.test.InstrumentationRegistry;
import androidx.test.annotation.Beta;
import androidx.test.espresso.intent.Checks;
import androidx.test.rule.UiThreadTestRule;
import android.util.Log;

import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import static androidx.test.internal.util.Checks.checkNotNull;

/**
* This rule provides functional testing of a single activity. The activity under test will be
* launched before each test annotated with
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
/*
* This is an example test project created in Eclipse to test NotePad which is a sample
* This is an example test project created in Eclipse to test NotePad which is a sample
* project located in AndroidSDK/samples/android-11/NotePad
* Just click on File --> New --> Project --> Android Project --> Create Project from existing source and
* select NotePad.
*
*
* Then you can run these test cases either on the emulator or on device. You right click
* the test project and select Run As --> Run As Android JUnit Test
*
*
* @author Renas Reda, [email protected]
*
*
*/

package androidTest.java.org.openintents.filemanager.test;
package org.openintents.filemanager.test;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;
import android.preference.PreferenceManager;
import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.Espresso;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
import android.text.format.Formatter;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ListView;

import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.Espresso;
import androidx.test.espresso.action.ViewActions;
import androidx.test.espresso.assertion.ViewAssertions;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
import org.junit.After;
import org.junit.Before;
Expand All @@ -46,27 +51,8 @@
import java.io.IOException;
import java.util.Random;

import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static androidx.test.espresso.Espresso.openContextualActionModeOverflowMenu;
import static androidx.test.espresso.Espresso.pressBack;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.longClick;
import static androidx.test.espresso.action.ViewActions.pressKey;
import static androidx.test.espresso.action.ViewActions.replaceText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.assertThat;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

@RunWith(AndroidJUnit4.class)
public class TestFileManagerActivity extends BaseTestFileManager {
public class TestFileManagerActivity extends org.openintents.filemanager.test.BaseTestFileManager {

private static String filenameIsInRightDirectory;
@Rule
Expand Down Expand Up @@ -379,9 +365,9 @@ private void setAscending(boolean enabled) {
@Test
public void testBrowseToOnPressEnter() throws IOException {

/*
/*
* We start at the SD card.
*/
*/
Espresso.onView(ViewMatchers.withText(Environment.getExternalStorageDirectory().getParentFile().getName())).perform(ViewActions.longClick());
Espresso.onView(ViewMatchers.withId(R.id.path_bar_path_edit_text)).perform(ViewActions.click()); // Let the editText have focus to be able to send the enter key.
Espresso.onView(ViewMatchers.withId(R.id.path_bar_path_edit_text)).perform(ViewActions.replaceText(sdcardPath + TEST_DIRECTORY));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package androidTest.java.org.openintents.filemanager.test;
package org.openintents.filemanager.test;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;

import androidx.test.espresso.assertion.ViewAssertions;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;

Expand All @@ -14,9 +17,6 @@

import java.io.IOException;

import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;

@RunWith(AndroidJUnit4.class)
public class TestFileManagerActivityWithIntents extends BaseTestFileManager {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package androidTest.java.org.openintents.filemanager.test;
package org.openintents.filemanager.test;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;

import androidx.test.espresso.assertion.ViewAssertions;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;

Expand All @@ -15,9 +18,6 @@

import java.io.IOException;

import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;

@RunWith(AndroidJUnit4.class)
public class TestIntentFilterActivityForPickFile extends BaseTestFileManager {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package androidTest.java.org.openintents.filemanager.test;
package org.openintents.filemanager.test;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.view.View;

import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.Espresso;
import androidx.test.espresso.action.ViewActions;
import androidx.test.espresso.assertion.ViewAssertions;
import androidx.test.espresso.matcher.BoundedMatcher;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.rule.UiThreadTestRule;
import androidx.test.runner.AndroidJUnit4;
import android.view.View;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -24,14 +29,6 @@
import java.io.File;
import java.io.IOException;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.endsWith;

@RunWith(AndroidJUnit4.class)
public class TestPickFilePathHistory extends BaseTestFileManager {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package androidTest.java.org.openintents.filemanager.test;
package org.openintents.filemanager.test;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;

import androidx.test.espresso.Espresso;
import androidx.test.espresso.action.ViewActions;
import androidx.test.espresso.intent.matcher.IntentMatchers;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -15,13 +21,8 @@

import java.io.IOException;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasData;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.junit.Assert.assertThat;
import static androidTest.java.org.openintents.filemanager.test.ActivityResultTestRule.hasResultCode;
import static androidTest.java.org.openintents.filemanager.test.ActivityResultTestRule.hasResultData;
import static org.openintents.filemanager.test.ActivityResultTestRule.hasResultCode;
import static org.openintents.filemanager.test.ActivityResultTestRule.hasResultData;

@RunWith(AndroidJUnit4.class)
public class TestPickFileResult extends BaseTestFileManager {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package androidTest.java.org.openintents.filemanager.test;
package org.openintents.filemanager.test;

import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.os.SystemClock;
import android.view.KeyEvent;
import android.view.View;

import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.Espresso;
import androidx.test.espresso.InjectEventSecurityException;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.action.ViewActions;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.rule.ActivityTestRule;
import android.view.KeyEvent;
import android.view.View;

import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -23,15 +29,6 @@
import java.io.File;
import java.io.IOException;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.actionWithAssertions;
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
import static androidx.test.espresso.action.ViewActions.replaceText;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withHint;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

public class TestSaveAsActivity extends BaseTestFileManager {

@Rule
Expand Down
Loading

0 comments on commit b5060e6

Please sign in to comment.