| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| package com.amaze.filemanager.utils |
|
|
| import android.os.Build |
| import android.os.Build.VERSION_CODES.LOLLIPOP |
| import android.os.Build.VERSION_CODES.P |
| import androidx.test.core.app.ApplicationProvider |
| import androidx.test.ext.junit.runners.AndroidJUnit4 |
| import com.amaze.filemanager.fileoperations.filesystem.DOESNT_EXIST |
| import com.amaze.filemanager.fileoperations.filesystem.WRITABLE_ON_REMOTE |
| import com.amaze.filemanager.shadows.ShadowSmbUtil |
| import com.amaze.filemanager.test.ShadowPasswordUtil |
| import com.amaze.filemanager.utils.smb.SmbUtil.checkFolder |
| import com.amaze.filemanager.utils.smb.SmbUtil.createFrom |
| import com.amaze.filemanager.utils.smb.SmbUtil.getSmbDecryptedPath |
| import com.amaze.filemanager.utils.smb.SmbUtil.getSmbEncryptedPath |
| import org.junit.Assert.assertEquals |
| import org.junit.Assert.assertNotEquals |
| import org.junit.Assert.assertTrue |
| import org.junit.Test |
| import org.junit.runner.RunWith |
| import org.robolectric.annotation.Config |
|
|
| |
| |
| |
| @Suppress("StringLiteralDuplication") |
| @RunWith(AndroidJUnit4::class) |
| @Config( |
| sdk = [LOLLIPOP, P, Build.VERSION_CODES.R], |
| shadows = [ShadowPasswordUtil::class, ShadowSmbUtil::class], |
| ) |
| class SmbUtilTest { |
| |
| |
| |
| @Test |
| fun testEncryptDecryptSmb() { |
| val path = "smb://root:toor@127.0.0.1" |
| val encrypted = getSmbEncryptedPath(ApplicationProvider.getApplicationContext(), path) |
| assertNotEquals(path, encrypted) |
| assertTrue(encrypted.startsWith("smb://root:")) |
| assertTrue(encrypted.endsWith("@127.0.0.1")) |
| val decrypted = getSmbDecryptedPath(ApplicationProvider.getApplicationContext(), encrypted) |
| assertEquals(path, decrypted) |
| } |
|
|
| |
| |
| |
| @Test |
| fun testEncryptDecryptFtps() { |
| val path = "ftps://root:toor@127.0.0.1" |
| val encrypted = getSmbEncryptedPath(ApplicationProvider.getApplicationContext(), path) |
| assertNotEquals(path, encrypted) |
| assertTrue(encrypted.startsWith("ftps://root:")) |
| assertTrue(encrypted.endsWith("@127.0.0.1")) |
| val decrypted = getSmbDecryptedPath(ApplicationProvider.getApplicationContext(), encrypted) |
| assertEquals(path, decrypted) |
| } |
|
|
| |
| |
| |
| @Test |
| fun testEncryptDecryptFtpsWithExtraParams() { |
| val path = "ftps://root:toor@127.0.0.1?tls=explicit" |
| val encrypted = getSmbEncryptedPath(ApplicationProvider.getApplicationContext(), path) |
| assertNotEquals(path, encrypted) |
| assertTrue(encrypted.startsWith("ftps://root:")) |
| assertTrue(encrypted.endsWith("@127.0.0.1?tls=explicit")) |
| val decrypted = getSmbDecryptedPath(ApplicationProvider.getApplicationContext(), encrypted) |
| assertEquals(path, decrypted) |
| } |
|
|
| |
| |
| |
| @Test |
| fun testEncryptWithoutCredentials() { |
| val path = "smb://127.0.0.1" |
| assertEquals( |
| path, |
| getSmbEncryptedPath(ApplicationProvider.getApplicationContext(), path), |
| ) |
| } |
|
|
| |
| |
| |
| @Test |
| fun testEncryptWithoutPassword() { |
| val path = "smb://toor@127.0.0.1" |
| assertEquals( |
| path, |
| getSmbEncryptedPath(ApplicationProvider.getApplicationContext(), path), |
| ) |
| } |
|
|
| |
| |
| |
| @Test |
| fun testCheckFolder() { |
| assertEquals( |
| DOESNT_EXIST, |
| checkFolder("smb://user:password@5.6.7.8/newfolder/DummyFolder"), |
| ) |
| assertEquals( |
| DOESNT_EXIST, |
| checkFolder("smb://user:password@5.6.7.8/newfolder/resume.doc"), |
| ) |
| assertEquals( |
| WRITABLE_ON_REMOTE, |
| checkFolder("smb://user:password@5.6.7.8/newfolder/Documents"), |
| ) |
| assertEquals( |
| DOESNT_EXIST, |
| checkFolder("smb://user:password@5.6.7.8/newfolder/wirebroken.log"), |
| ) |
| assertEquals( |
| DOESNT_EXIST, |
| checkFolder("smb://user:password@5.6.7.8/newfolder/failcheck"), |
| ) |
| } |
|
|
| |
| |
| |
| @Test |
| fun testCreateNtlmPasswordAuthenticator() { |
| var auth = createFrom(null) |
| assertEquals("", auth.userDomain) |
| assertEquals("", auth.username) |
| assertEquals("", auth.password) |
| auth = createFrom("") |
| assertEquals("", auth.userDomain) |
| assertEquals("", auth.username) |
| assertEquals("", auth.password) |
| auth = createFrom("username:password") |
| assertEquals("", auth.userDomain) |
| assertEquals("username", auth.username) |
| assertEquals("password", auth.password) |
| auth = createFrom("WORKGROUP;username:password") |
| assertEquals("WORKGROUP", auth.userDomain) |
| assertEquals("username", auth.username) |
| assertEquals("password", auth.password) |
| auth = createFrom("WORKGROUP;username") |
| assertEquals("WORKGROUP", auth.userDomain) |
| assertEquals("username", auth.username) |
| assertEquals("", auth.password) |
|
|
| |
| auth = createFrom("username:pass%w0rd") |
| assertEquals("", auth.userDomain) |
| assertEquals("username", auth.username) |
| assertEquals("pass%w0rd", auth.password) |
|
|
| |
| auth = createFrom("WORKGROUP;user%1") |
| assertEquals("WORKGROUP", auth.userDomain) |
| assertEquals("user%1", auth.username) |
| assertEquals("", auth.password) |
| auth = createFrom("WORKGROUP%2;user%1:pass%word") |
| assertEquals("WORKGROUP%2", auth.userDomain) |
| assertEquals("user%1", auth.username) |
| assertEquals("pass%word", auth.password) |
| } |
| } |
|
|