Skip to content

Commit

Permalink
Standalone NetCopyConnectionInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
TranceLove committed Dec 26, 2022
1 parent e12adf2 commit 0db1101
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ class NetCopyConnectionInfo(url: String) {
}
}

/**
* Returns the last segment of the URL's path element.
*/
fun lastPathSegment(): String? {
return if (filename != null && true == filename?.isNotEmpty()) {
filename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
import com.amaze.filemanager.utils.AppConstants;
import com.amaze.filemanager.utils.BookSorter;
import com.amaze.filemanager.utils.DataUtils;
import com.amaze.filemanager.utils.GenericExtKt;
import com.amaze.filemanager.utils.MainActivityActionMode;
import com.amaze.filemanager.utils.MainActivityHelper;
import com.amaze.filemanager.utils.OTGUtil;
Expand Down Expand Up @@ -204,6 +205,7 @@
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import kotlin.text.Charsets;

public class MainActivity extends PermissionsActivity
implements SmbConnectionListener,
Expand Down Expand Up @@ -1995,7 +1997,9 @@ public void showSftpDialog(String name, String path, boolean edit) {
retval.putString(ARG_ADDRESS, connectionInfo.getHost());
retval.putInt(ARG_PORT, connectionInfo.getPort());
if (!TextUtils.isEmpty(connectionInfo.getDefaultPath())) {
retval.putString(ARG_DEFAULT_PATH, connectionInfo.getDefaultPath());
retval.putString(
ARG_DEFAULT_PATH,
GenericExtKt.urlDecoded(connectionInfo.getDefaultPath(), Charsets.UTF_8));
}
retval.putString(ARG_USERNAME, connectionInfo.getUsername());

Expand Down Expand Up @@ -2043,10 +2047,9 @@ public void addConnection(
if (!edit) {
if ((dataUtils.containsServer(path)) == -1) {
Completable.fromRunnable(
() -> {
utilsHandler.saveToDatabase(
new OperationData(UtilsHandler.Operation.SMB, name, encryptedPath));
})
() ->
utilsHandler.saveToDatabase(
new OperationData(UtilsHandler.Operation.SMB, name, encryptedPath)))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
public class MainActivityTest {

private static final String[] BUNDLE_KEYS = {
"address", "port", "keypairName", "name", "username", "password", "edit"
"address", "port", "keypairName", "name", "username", "password", "edit", "defaultPath"
};

private MockedConstruction<SftpConnectDialog> mc;
Expand Down Expand Up @@ -164,6 +164,55 @@ public void testInvokeSftpConnectionDialogWithPassword()
testOpenSftpConnectDialog(uri, verify);
}

@Test
public void testInvokeSftpConnectionDialogWithPasswordAndDefaultPath()
throws GeneralSecurityException, IOException {
String uri =
NetCopyClientUtils.INSTANCE.encryptFtpPathAsNecessary(
"ssh://root:12345678@127.0.0.1:22/data/incoming");

Bundle verify = new Bundle();
verify.putString("address", "127.0.0.1");
verify.putInt("port", 22);
verify.putString("name", "SCP/SFTP Connection");
verify.putString("username", "root");
verify.putBoolean("hasPassword", true);
verify.putBoolean("edit", true);
verify.putString("defaultPath", "/data/incoming");
verify.putString(
"password",
PasswordUtil.INSTANCE
.encryptPassword(AppConfig.getInstance(), "12345678", Base64.URL_SAFE)
.replace("\n", ""));

testOpenSftpConnectDialog(uri, verify);
}

@Test
public void testInvokeSftpConnectionDialogWithPasswordAndEncodedDefaultPath()
throws GeneralSecurityException, IOException {
String uri =
NetCopyClientUtils.INSTANCE.encryptFtpPathAsNecessary(
"ssh://root:12345678@127.0.0.1:22/Users/TranceLove/My+Documents/%7BReference%7D%20Zobius%20Facro%20%24%24%20%23RFII1");

Bundle verify = new Bundle();
verify.putString("address", "127.0.0.1");
verify.putInt("port", 22);
verify.putString("name", "SCP/SFTP Connection");
verify.putString("username", "root");
verify.putBoolean("hasPassword", true);
verify.putBoolean("edit", true);
verify.putString(
"defaultPath", "/Users/TranceLove/My Documents/{Reference} Zobius Facro $$ #RFII1");
verify.putString(
"password",
PasswordUtil.INSTANCE
.encryptPassword(AppConfig.getInstance(), "12345678", Base64.URL_SAFE)
.replace("\n", ""));

testOpenSftpConnectDialog(uri, verify);
}

private void testOpenSftpConnectDialog(String uri, Bundle verify)
throws GeneralSecurityException, IOException {
MainActivity activity = mock(MainActivity.class);
Expand Down

0 comments on commit 0db1101

Please sign in to comment.