diff options
author | Arne Schwabe <arne@rfc2549.org> | 2018-03-15 00:31:30 +0100 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2018-03-15 00:31:30 +0100 |
commit | e279f9d2760f5902c9a9fc68068e579805a12f2a (patch) | |
tree | d7d4f8cdd1184530b3799cd0e10c72ea7198db52 /main/src/test | |
parent | 111c3cf994f6788aa6251f3f8a1992765ba967d1 (diff) |
Test and fix auth-retry config feature (closes #853)
Diffstat (limited to 'main/src/test')
-rw-r--r-- | main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java b/main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java new file mode 100644 index 00000000..58e5c268 --- /dev/null +++ b/main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012-2018 Arne Schwabe + * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt + */ + +package de.blinkt.openvpn.core; + +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.test.mock.MockContext; + +import junit.framework.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; + +import java.io.File; + +import static de.blinkt.openvpn.VpnProfile.TYPE_USERPASS; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import de.blinkt.openvpn.VpnProfile; + +import static de.blinkt.openvpn.VpnProfile.AUTH_RETRY_NOINTERACT; + +/** + * Created by arne on 14.03.18. + */ + +@Config(manifest= Config.NONE) +@RunWith(RobolectricTestRunner.class) +public class TestConfigGenerator { + @Test + public void testAuthRetryGen() throws PackageManager.NameNotFoundException { + /*Context mc = mock(Context.class); + PackageManager mpm = mock(PackageManager.class); + + PackageInfo mpi = new PackageInfo(); + mpi.versionCode = 177; + mpi.versionName = "foo"; + + when(mc.getCacheDir()).thenReturn(new File("/j/unit/test/")); + when(mc.getPackageName()).thenReturn("de.blinkt.openvpn"); + when(mc.getPackageManager()).thenReturn(mpm); + when(mpm.getPackageInfo(eq("de.blinkt.openvpn"),eq(0))).thenReturn(mpi);*/ + + + + VpnProfile vp = new VpnProfile ("test") { + @Override + public String getVersionEnvString(Context c) { + return "no ver"; + } + + @Override + public String getPlatformVersionEnvString() { + return "test"; + } + }; + + vp.mAuthenticationType = TYPE_USERPASS; + vp.mAuthRetry = AUTH_RETRY_NOINTERACT; + String config = vp.getConfigFile(RuntimeEnvironment.application, false); + Assert.assertTrue(config.contains("\nauth-retry nointeract\n")); + + } +} |