From 3b8e8139d3bfe68579c9cd6599d5ab623aab68c3 Mon Sep 17 00:00:00 2001 From: Isabel Martin Date: Mon, 26 Feb 2024 09:36:15 -0800 Subject: [PATCH] MBL-1172: Remove Perimeter X (#1955) --- app/build.gradle | 3 - .../com/kickstarter/ApplicationModule.java | 35 ++-- .../libs/perimeterx/PerimeterXClient.kt | 127 --------------- .../libs/perimeterx/PerimeterXClientType.kt | 87 ---------- .../mock/factories/PXClientFactory.kt | 63 ------- .../interceptors/ApiRequestInterceptor.kt | 5 - .../interceptors/GraphQLInterceptor.kt | 11 +- .../interceptors/KSRequestInterceptor.java | 6 +- .../interceptors/WebRequestInterceptor.kt | 5 +- .../com/kickstarter/ui/views/KSWebView.kt | 20 --- .../com/kickstarter/libs/PerimeterXTest.kt | 154 ------------------ build.gradle | 1 - 12 files changed, 14 insertions(+), 503 deletions(-) delete mode 100644 app/src/main/java/com/kickstarter/libs/perimeterx/PerimeterXClient.kt delete mode 100644 app/src/main/java/com/kickstarter/libs/perimeterx/PerimeterXClientType.kt delete mode 100644 app/src/main/java/com/kickstarter/mock/factories/PXClientFactory.kt delete mode 100644 app/src/test/java/com/kickstarter/libs/PerimeterXTest.kt diff --git a/app/build.gradle b/app/build.gradle index 5e3c2d2d89..998b694ac6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -252,9 +252,6 @@ dependencies { implementation 'com.segment.analytics.android:analytics:4.11.3' implementation 'com.appboy:appboy-segment-integration:15.0.1' - // Security - implementation 'com.perimeterx.sdk:msdk:1.16.7' - // Dependencies for HTML Parser implementation 'org.jsoup:jsoup:1.16.1' diff --git a/app/src/main/java/com/kickstarter/ApplicationModule.java b/app/src/main/java/com/kickstarter/ApplicationModule.java index 5cae00612f..fa40a21111 100644 --- a/app/src/main/java/com/kickstarter/ApplicationModule.java +++ b/app/src/main/java/com/kickstarter/ApplicationModule.java @@ -46,8 +46,6 @@ import com.kickstarter.libs.graphql.DateTimeAdapter; import com.kickstarter.libs.graphql.Iso8601DateTimeAdapter; import com.kickstarter.libs.graphql.EmailAdapter; -import com.kickstarter.libs.perimeterx.PerimeterXClient; -import com.kickstarter.libs.perimeterx.PerimeterXClientType; import com.kickstarter.libs.preferences.BooleanPreference; import com.kickstarter.libs.preferences.BooleanPreferenceType; import com.kickstarter.libs.preferences.IntPreference; @@ -228,18 +226,6 @@ static ApolloClient provideApolloClient(final @NonNull Build build, final @NonNu .build(); } - @Provides - @Singleton - @NonNull - static PerimeterXClientType providePerimeterXManager(final @ApplicationContext @NonNull Context context, final @NonNull Build build) { - final PerimeterXClient manager = new PerimeterXClient(build); - if (context instanceof KSApplication && !((KSApplication) context).isInUnitTests()) { - manager.start(context); - } - - return manager; - } - @Provides @Singleton @NonNull @@ -287,17 +273,16 @@ static Retrofit provideApiRetrofitV2(final @NonNull ApiEndpoint apiEndpoint, @NonNull static ApiRequestInterceptor provideApiRequestInterceptor( final @NonNull String clientId, final @NonNull CurrentUserTypeV2 currentUser, - final @NonNull ApiEndpoint endpoint, final @NonNull PerimeterXClientType manager, - final @NonNull Build build) { - return new ApiRequestInterceptor(clientId, currentUser, endpoint.url(), manager, build); + final @NonNull ApiEndpoint endpoint, final @NonNull Build build) { + return new ApiRequestInterceptor(clientId, currentUser, endpoint.url(), build); } @Provides @Singleton @NonNull static GraphQLInterceptor provideGraphQLInterceptor(final @NonNull String clientId, - final @NonNull CurrentUserType currentUser, final @NonNull Build build, final @NonNull PerimeterXClientType manager) { - return new GraphQLInterceptor(clientId, currentUser, build, manager); + final @NonNull CurrentUserType currentUser, final @NonNull Build build) { + return new GraphQLInterceptor(clientId, currentUser, build); } @Provides @@ -325,8 +310,8 @@ static String provideClientId(final @NonNull ApiEndpoint apiEndpoint) { @Provides @Singleton @NonNull - static KSRequestInterceptor provideKSRequestInterceptor(final @NonNull Build build, final @NonNull PerimeterXClientType manager) { - return new KSRequestInterceptor(build, manager); + static KSRequestInterceptor provideKSRequestInterceptor(final @NonNull Build build) { + return new KSRequestInterceptor(build); } @Provides @@ -352,8 +337,8 @@ static Retrofit provideWebRetrofit(@NonNull @WebEndpoint final String webEndpoin @Singleton @NonNull static WebRequestInterceptor provideWebRequestInterceptor(final @NonNull CurrentUserType currentUser, - @NonNull @WebEndpoint final String endpoint, final @NonNull InternalToolsType internalTools, final @NonNull Build build, final @NonNull PerimeterXClientType manager) { - return new WebRequestInterceptor(currentUser, endpoint, internalTools, build, manager); + @NonNull @WebEndpoint final String endpoint, final @NonNull InternalToolsType internalTools, final @NonNull Build build) { + return new WebRequestInterceptor(currentUser, endpoint, internalTools, build); } private static @NonNull Retrofit createRetrofit(final @NonNull String baseUrl, final @NonNull Gson gson, final @NonNull OkHttpClient okHttpClient) { @@ -591,8 +576,8 @@ static KSString provideKSString(final @PackageNameString @NonNull String package @Provides static KSWebViewClient provideKSWebViewClient(final @NonNull OkHttpClient okHttpClient, - final @WebEndpoint String webEndpoint, final @NonNull PerimeterXClientType manager) { - return new KSWebViewClient(okHttpClient, webEndpoint, manager); + final @WebEndpoint String webEndpoint) { + return new KSWebViewClient(okHttpClient, webEndpoint); } @Provides diff --git a/app/src/main/java/com/kickstarter/libs/perimeterx/PerimeterXClient.kt b/app/src/main/java/com/kickstarter/libs/perimeterx/PerimeterXClient.kt deleted file mode 100644 index 523c17d13e..0000000000 --- a/app/src/main/java/com/kickstarter/libs/perimeterx/PerimeterXClient.kt +++ /dev/null @@ -1,127 +0,0 @@ -package com.kickstarter.libs.perimeterx - -import android.content.Context -import com.kickstarter.libs.Build -import com.kickstarter.libs.utils.Secrets -import com.perimeterx.msdk.CaptchaResultCallback -import com.perimeterx.msdk.PXManager -import com.perimeterx.msdk.PXResponse -import okhttp3.Request -import okhttp3.Response -import rx.Observable -import rx.subjects.PublishSubject -import timber.log.Timber -import java.util.Date - -private const val LOGTAG = "PerimeterXClient" -open class PerimeterXClient(private val build: Build) : PerimeterXClientType { - - private val headers: PublishSubject> = PublishSubject.create() - private val isManagerReady: PublishSubject = PublishSubject.create() - private val captchaSuccess: PublishSubject = PublishSubject.create() - private val captchaCanceled: PublishSubject = PublishSubject.create() - - private val pxManager = PXManager.getInstance() - private var pxResponse: PXResponse? = null - - override val headersAdded: Observable> - get() = this.headers - - override val isCaptchaCanceled: Observable - get() = this.captchaCanceled - - override val isCaptchaSuccess: Observable - get() = this.captchaSuccess - - override val isReady: Observable - get() = this.isManagerReady - - override fun getCookieForWebView(): String { - val date = Date() - date.time = date.time + 60 * 60 * 1000 // - Set the expiration to one hour - return "_pxmvid=${this.visitorId()} expires= $date;" - } - - override fun httpHeaders(): MutableMap? = PXManager.httpHeaders() - - private fun initialize() { - pxManager - .setNewHeadersCallback { newHeaders: HashMap -> - if (build.isDebug) Timber.d("$LOGTAG NewHeadersCallback :$newHeaders") - this.headers.onNext(newHeaders) - } - .setManagerReadyCallback { headers: HashMap -> - if (build.isDebug) Timber.d("$LOGTAG setManagerReadyCallback :$headers") - this.isManagerReady.onNext(true) - } - } - - override fun addHeaderTo(builder: Request.Builder?) { - val headers = httpHeaders()?.toMap() ?: emptyMap() - - headers.forEach { (key, value) -> - builder?.removeHeader(key) - builder?.addHeader(key, value) - } - - if (build.isDebug) Timber.d("$LOGTAG headers: $headers added to requestBuilder: ${builder?.toString()}") - } - - override fun visitorId(): String { - val visitorID: String? = pxManager.vid - return visitorID?.let { it } ?: "" - } - - override fun start(context: Context) { - initialize() - pxManager.start(context, Secrets.PERIMETERX_APPID) - } - - override fun intercept(response: Response) { - if (build.isDebug) Timber.d("$LOGTAG intercepted response for request:${response.request.url} with VID :${this.visitorId()}") - - if (response.code == 403) { - this.cloneResponse(response).body?.string()?.let { - if (this.isChallenged(it)) { - if (build.isDebug) Timber.d("$LOGTAG Response Challenged for Request: ${response.request.url}") - this.handleChallengedResponse(it) - } - } - } - } - - /** - * Accessing the body of the response more than once (down on the flow Retrofit/Apollo will access the response as well) will throw an IllegalStateException by OkHttp. - * Clone the response and access the body via `peekBody` to get a lightweight copy of it - */ - private fun cloneResponse(response: Response) = response.newBuilder() - .code(response.code) - .request(response.request) - .body(response.peekBody(Long.MAX_VALUE)) - .build() - - override fun isChallenged(body: String): Boolean { - this.pxResponse = PXManager.checkError(body) - return pxResponse?.enforcement()?.name != "NOT_PX_BLOCK" - } - - override fun handleChallengedResponse(body: String) { - pxResponse?.let { response -> - PXManager.handleResponse(response) { result: CaptchaResultCallback.Result?, reason: CaptchaResultCallback.CancelReason? -> - when (result) { - CaptchaResultCallback.Result.SUCCESS -> { - if (build.isDebug) Timber.d("$LOGTAG CaptchaResultCallback.Result.SUCCESS") - this.captchaSuccess.onNext(true) - } - CaptchaResultCallback.Result.CANCELED -> { - reason?.let { cancelReason -> - if (build.isDebug) Timber.d("$LOGTAG CaptchaResultCallback.Result.CANCELED reason: ${cancelReason.name}") - this.captchaCanceled.onNext(cancelReason.name) - } - } - else -> {} - } - } - } - } -} diff --git a/app/src/main/java/com/kickstarter/libs/perimeterx/PerimeterXClientType.kt b/app/src/main/java/com/kickstarter/libs/perimeterx/PerimeterXClientType.kt deleted file mode 100644 index 012bd5fd50..0000000000 --- a/app/src/main/java/com/kickstarter/libs/perimeterx/PerimeterXClientType.kt +++ /dev/null @@ -1,87 +0,0 @@ -package com.kickstarter.libs.perimeterx - -import android.content.Context -import okhttp3.Request -import okhttp3.Response -import rx.Observable -import kotlin.collections.HashMap - -/** - * Wrapper interface to handle the implementation with the PerimeterX SDK - */ -interface PerimeterXClientType { - - /** - * Captcha challenge successful - */ - val isCaptchaSuccess: Observable - - /** - * Captcha challenge canceled - */ - val isCaptchaCanceled: Observable - - /** - * Every time a new header is added - */ - val headersAdded: Observable> - - /** - * Will emit once the SDK is ready - */ - val isReady: Observable - - /** - * The perimeterX headers will be added to the given Request Builder - */ - fun addHeaderTo(builder: Request.Builder?) - - /** - * Getter for the PerimeterX headers, null in case no headers found - */ - fun httpHeaders(): MutableMap? - - /** - * Start SDK with the given context. - */ - fun start(context: Context) - - /** - * Intercept a response, - * will call internally the following methods: - * - * - @see fun isChallenged - * - @see fun handleChallengedResponse - */ - fun intercept(response: Response) - - /** - * created `_pxmvid` cookie, with 1 hour expiration time - * @see {@link https://docs.perimeterx.com/pxconsole/docs/android-sdk-integration-guide#section-web-view-integration} - */ - fun getCookieForWebView(): String - - /** - * Identification for the PerimeterX sdk - */ - fun visitorId(): String - - /** - * Will evaluate the body of a response - * and say id that response was challenged or not - */ - fun isChallenged(body: String): Boolean - - /** - * Will take the response body from a challenged response, - * and internally handle any outcome: - * - response intercepted and successfully passed the challenge: - * @isCaptchaSuccess will emit - * - * - response intercepted but challenge canceled: - * @isCaptchaCanceled will emit - * - * - response not challenged none of the above will emit - */ - fun handleChallengedResponse(body: String) -} diff --git a/app/src/main/java/com/kickstarter/mock/factories/PXClientFactory.kt b/app/src/main/java/com/kickstarter/mock/factories/PXClientFactory.kt deleted file mode 100644 index 068b0ebc9a..0000000000 --- a/app/src/main/java/com/kickstarter/mock/factories/PXClientFactory.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.kickstarter.mock.factories - -import android.content.Context -import com.kickstarter.libs.Build -import com.kickstarter.libs.perimeterx.PerimeterXClient -import okhttp3.Response -import rx.Observable -import rx.subjects.PublishSubject -import java.util.HashMap - -open class MockPXClient(build: Build) : PerimeterXClient(build) { - - private val headers: PublishSubject> = PublishSubject.create() - private val isManagerReady: PublishSubject = PublishSubject.create() - private val captchaSuccess: PublishSubject = PublishSubject.create() - - override val headersAdded: Observable> - get() = this.headers - - override val isCaptchaSuccess: Observable - get() = this.captchaSuccess - - override val isReady: Observable - get() = this.isManagerReady - - override fun visitorId() = "VID" - override fun httpHeaders(): MutableMap = mutableMapOf("h1" to "value1", "h2" to "value2") - override fun start(context: Context) { - headers.onNext(hashMapOf()) - isManagerReady.onNext(true) - } - - override fun isChallenged(body: String) = true - - override fun intercept(response: Response) { - captchaSuccess.onNext(true) - } -} - -class MockPXClientNotChallenged(build: Build) : MockPXClient(build) { - override fun isChallenged(body: String) = false - override fun intercept(response: Response) { - // no captcha emitted - } -} - -class MockPXClientCaptchaCanceled(build: Build) : MockPXClient(build) { - private val captchaCanceled: PublishSubject = PublishSubject.create() - override val isCaptchaCanceled: Observable - get() = this.captchaCanceled - - override fun intercept(response: Response) { - captchaCanceled.onNext("Back Button") - } -} - -class PXClientFactory private constructor() { - companion object { - fun pxChallengedSuccessful(build: Build) = MockPXClient(build) - fun pxChallengedCanceled(build: Build) = MockPXClientCaptchaCanceled(build) - fun pxNotChallenged(build: Build) = MockPXClientNotChallenged(build) - } -} diff --git a/app/src/main/java/com/kickstarter/services/interceptors/ApiRequestInterceptor.kt b/app/src/main/java/com/kickstarter/services/interceptors/ApiRequestInterceptor.kt index 2706f11bba..92025b19a5 100644 --- a/app/src/main/java/com/kickstarter/services/interceptors/ApiRequestInterceptor.kt +++ b/app/src/main/java/com/kickstarter/services/interceptors/ApiRequestInterceptor.kt @@ -4,7 +4,6 @@ import android.net.Uri import com.kickstarter.libs.Build import com.kickstarter.libs.CurrentUserTypeV2 import com.kickstarter.libs.FirebaseHelper -import com.kickstarter.libs.perimeterx.PerimeterXClientType import com.kickstarter.libs.utils.WebUtils.userAgent import com.kickstarter.libs.utils.extensions.isApiUri import okhttp3.HttpUrl @@ -19,7 +18,6 @@ class ApiRequestInterceptor( private val clientId: String, private val currentUser: CurrentUserTypeV2, private val endpoint: String, - private val pxManager: PerimeterXClientType, private val build: Build ) : Interceptor { @@ -27,7 +25,6 @@ class ApiRequestInterceptor( override fun intercept(chain: Chain): Response { val response: Response = chain.proceed(request(chain.request())) - pxManager.intercept(response) return response } @@ -41,8 +38,6 @@ class ApiRequestInterceptor( .addHeader("Kickstarter-Android-App-UUID", FirebaseHelper.identifier) .addHeader("User-Agent", userAgent(build)) - pxManager.addHeaderTo(builder) - return builder .url(url(initialRequest.url)) .build() diff --git a/app/src/main/java/com/kickstarter/services/interceptors/GraphQLInterceptor.kt b/app/src/main/java/com/kickstarter/services/interceptors/GraphQLInterceptor.kt index 2c4bddcad5..aaa8e74e5a 100644 --- a/app/src/main/java/com/kickstarter/services/interceptors/GraphQLInterceptor.kt +++ b/app/src/main/java/com/kickstarter/services/interceptors/GraphQLInterceptor.kt @@ -3,7 +3,6 @@ package com.kickstarter.services.interceptors import com.kickstarter.libs.Build import com.kickstarter.libs.CurrentUserType import com.kickstarter.libs.FirebaseHelper -import com.kickstarter.libs.perimeterx.PerimeterXClientType import com.kickstarter.libs.utils.WebUtils import okhttp3.Interceptor import okhttp3.Interceptor.Chain @@ -16,8 +15,7 @@ import okhttp3.Response class GraphQLInterceptor( private val clientId: String, private val currentUser: CurrentUserType, - private val build: Build, - private val pxManager: PerimeterXClientType + private val build: Build ) : Interceptor { override fun intercept(chain: Chain): Response { val original = chain.request() @@ -32,11 +30,6 @@ class GraphQLInterceptor( .addHeader("X-KICKSTARTER-CLIENT", this.clientId) .addHeader("Kickstarter-Android-App-UUID", FirebaseHelper.identifier) - pxManager.addHeaderTo(builder) - - val response = chain.proceed(builder.build()) - pxManager.intercept(response) - - return response + return chain.proceed(builder.build()) } } diff --git a/app/src/main/java/com/kickstarter/services/interceptors/KSRequestInterceptor.java b/app/src/main/java/com/kickstarter/services/interceptors/KSRequestInterceptor.java index e61cc7ee3b..7ef620a6e7 100644 --- a/app/src/main/java/com/kickstarter/services/interceptors/KSRequestInterceptor.java +++ b/app/src/main/java/com/kickstarter/services/interceptors/KSRequestInterceptor.java @@ -1,7 +1,6 @@ package com.kickstarter.services.interceptors; import com.kickstarter.libs.Build; -import com.kickstarter.libs.perimeterx.PerimeterXClientType; import com.kickstarter.libs.utils.I18nUtils; import java.io.IOException; @@ -16,11 +15,9 @@ */ public final class KSRequestInterceptor implements Interceptor { private final Build build; - private final PerimeterXClientType pxManager; - public KSRequestInterceptor(final @NonNull Build build, final @NonNull PerimeterXClientType manager) { + public KSRequestInterceptor(final @NonNull Build build) { this.build = build; - this.pxManager = manager; } @Override @@ -34,7 +31,6 @@ private Request request(final @NonNull Request initialRequest) { .header("Kickstarter-App-Id", this.build.applicationId()) .header("Accept-Language", I18nUtils.language()); - this.pxManager.addHeaderTo(builder); return builder.build(); } } diff --git a/app/src/main/java/com/kickstarter/services/interceptors/WebRequestInterceptor.kt b/app/src/main/java/com/kickstarter/services/interceptors/WebRequestInterceptor.kt index 122e66c008..356f373633 100644 --- a/app/src/main/java/com/kickstarter/services/interceptors/WebRequestInterceptor.kt +++ b/app/src/main/java/com/kickstarter/services/interceptors/WebRequestInterceptor.kt @@ -4,7 +4,6 @@ import android.net.Uri import com.kickstarter.libs.Build import com.kickstarter.libs.CurrentUserType import com.kickstarter.libs.InternalToolsType -import com.kickstarter.libs.perimeterx.PerimeterXClientType import com.kickstarter.libs.utils.Secrets import com.kickstarter.libs.utils.WebUtils.userAgent import com.kickstarter.libs.utils.extensions.isHivequeenUri @@ -25,8 +24,7 @@ class WebRequestInterceptor( private val currentUser: CurrentUserType, private val endpoint: String, private val internalTools: InternalToolsType, - private val build: Build, - private val pxManager: PerimeterXClientType + private val build: Build ) : Interceptor { private var loggedInUser: User? = null @@ -69,7 +67,6 @@ class WebRequestInterceptor( ) } - pxManager.addHeaderTo(requestBuilder) return requestBuilder.build() } diff --git a/app/src/main/java/com/kickstarter/ui/views/KSWebView.kt b/app/src/main/java/com/kickstarter/ui/views/KSWebView.kt index c792e3d64f..faef700540 100644 --- a/app/src/main/java/com/kickstarter/ui/views/KSWebView.kt +++ b/app/src/main/java/com/kickstarter/ui/views/KSWebView.kt @@ -5,7 +5,6 @@ import android.content.Context import android.util.AttributeSet import android.view.LayoutInflater import android.view.View -import android.webkit.CookieManager import android.webkit.ValueCallback import android.webkit.WebChromeClient import android.webkit.WebView.setWebContentsDebuggingEnabled @@ -14,10 +13,8 @@ import com.kickstarter.KSApplication import com.kickstarter.databinding.WebViewBinding import com.kickstarter.libs.Build import com.kickstarter.libs.WebViewJavascriptInterface -import com.kickstarter.libs.perimeterx.PerimeterXClientType import com.kickstarter.services.KSWebViewClient import com.kickstarter.services.RequestHandler -import timber.log.Timber import javax.inject.Inject private const val LOGTAG = "KSWebView" @@ -34,9 +31,6 @@ class KSWebView@JvmOverloads constructor( @Inject lateinit var build: Build - @Inject - lateinit var perimeterX: PerimeterXClientType - private var delegate: Delegate? = null interface Delegate { @@ -73,19 +67,6 @@ class KSWebView@JvmOverloads constructor( } } - /** - * Added `_pxmvid` cookie to each loaded url, with 1 hour expiration time - * @see {@link https://docs.perimeterx.com/pxconsole/docs/android-sdk-integration-guide#section-web-view-integration} - */ - private fun setPerimeterXCookie(url: String?) { - val cookieManager: CookieManager = CookieManager.getInstance() - cookieManager.removeSessionCookies { } - - val cookie = this.perimeterX.getCookieForWebView() - cookieManager.setCookie(url, cookie) - if (build.isDebug) Timber.d("$LOGTAG: for url:$url cookie:${cookieManager.getCookie(url)} ") - } - override fun externalLinkActivated(url: String) { this.delegate?.externalLinkActivated(url) } @@ -130,7 +111,6 @@ class KSWebView@JvmOverloads constructor( fun loadUrl(url: String?) { url?.let { binding.internalWebView.loadUrl(it) - setPerimeterXCookie(it) } } diff --git a/app/src/test/java/com/kickstarter/libs/PerimeterXTest.kt b/app/src/test/java/com/kickstarter/libs/PerimeterXTest.kt deleted file mode 100644 index 188c3fac8a..0000000000 --- a/app/src/test/java/com/kickstarter/libs/PerimeterXTest.kt +++ /dev/null @@ -1,154 +0,0 @@ -package com.kickstarter.libs - -import androidx.test.core.app.ApplicationProvider -import com.kickstarter.KSRobolectricTestCase -import com.kickstarter.mock.factories.PXClientFactory -import okhttp3.Protocol -import okhttp3.Request -import okhttp3.Response -import okhttp3.ResponseBody.Companion.toResponseBody -import org.junit.Test -import rx.observers.TestSubscriber -import java.util.HashMap - -class PerimeterXTest : KSRobolectricTestCase() { - - lateinit var build: Build - - private val mockRequest = Request.Builder() - .url("http://url.com") - .build() - - private val mockResponse = Response.Builder() - .request(mockRequest) - .protocol(Protocol.HTTP_2) - .message("") - .code(403) - .body("body".toResponseBody()) - .build() - - private val mockBody = mockResponse.body?.string() ?: "" - - override fun setUp() { - super.setUp() - build = requireNotNull(environment().build()) - } - - @Test - fun testCookieForWebView() { - val pxClient = PXClientFactory.pxChallengedSuccessful(build) - val cookie = pxClient.getCookieForWebView() - val assertValue = "_pxmvid=${pxClient.visitorId()}" - - assert(cookie.contains(assertValue)) - } - - @Test - fun testVisitiorId() { - val pxClient = PXClientFactory.pxChallengedSuccessful(build) - val vid = pxClient.visitorId() - - assertNotNull(vid) - assertEquals(vid, "VID") - } - - @Test - fun testHeaders() { - val pxClient = PXClientFactory.pxChallengedSuccessful(build) - val pxHeader = pxClient.httpHeaders() - val headerVariable = mutableMapOf("h1" to "value1", "h2" to "value2") - - assert(pxHeader.isNotEmpty()) - assertEquals(pxHeader.size, 2) - assertEquals(pxHeader.keys, headerVariable.keys) - assertEquals(pxHeader.values.toString(), headerVariable.values.toString()) - } - - @Test - fun testAddHeaderToBuilder() { - val pxClient = PXClientFactory.pxChallengedSuccessful(build) - val mockRequestBuilder = Request.Builder() - .url("http://url.com") - - val headerVariable = mutableMapOf("h1" to "value1", "h2" to "value2") - - pxClient.addHeaderTo(mockRequestBuilder) - - val request = mockRequestBuilder.build() - val first = request.headers[headerVariable.keys.first()] - val last = request.headers[headerVariable.keys.last()] - - assertEquals(first, headerVariable[headerVariable.keys.first()]) - assertEquals(last, headerVariable[headerVariable.keys.last()]) - } - - @Test - fun testChallengedResponse() { - val build = requireNotNull(environment().build()) - val clientNotChallenged = PXClientFactory.pxNotChallenged(build) - val clientWithChallenged = PXClientFactory.pxChallengedSuccessful(build) - - val challenge1 = clientWithChallenged.isChallenged(mockBody) - val challenge2 = clientNotChallenged.isChallenged(mockBody) - - assertTrue(challenge1) - assertFalse(challenge2) - } - - @Test - fun testIntercept_whenCaptchaSuccess() { - val pxClient = PXClientFactory.pxChallengedSuccessful(build) - - val testIsManagerReady = TestSubscriber.create() - val testCaptchaSuccess = TestSubscriber.create() - val testCaptchaCanceled = TestSubscriber.create() - val testHeadersAdded = TestSubscriber.create>() - - pxClient.isReady.subscribe(testIsManagerReady) - pxClient.isCaptchaSuccess.subscribe(testCaptchaSuccess) - pxClient.headersAdded.subscribe(testHeadersAdded) - pxClient.isCaptchaCanceled.subscribe(testCaptchaCanceled) - - pxClient.start(ApplicationProvider.getApplicationContext()) - pxClient.intercept(mockResponse) - - testIsManagerReady.assertValue(true) - testCaptchaSuccess.assertValue(true) - testCaptchaCanceled.assertNoValues() - testHeadersAdded.assertValueCount(1) - } - - @Test - fun testIntercept_whenCaptchaCanceled() { - val build = requireNotNull(environment().build()) - val client = PXClientFactory.pxChallengedCanceled(build) - val testCaptchaSuccess = TestSubscriber.create() - val testCaptchaCanceled = TestSubscriber.create() - - client.isCaptchaSuccess.subscribe(testCaptchaSuccess) - client.isCaptchaCanceled.subscribe(testCaptchaCanceled) - - client.start(ApplicationProvider.getApplicationContext()) - client.intercept(mockResponse) - - testCaptchaCanceled.assertValue("Back Button") - testCaptchaSuccess.assertNoValues() - } - - @Test - fun testIntercept_whenNoChallenged_NoCaptcha() { - val client = PXClientFactory.pxNotChallenged(build) - val testCaptchaSuccess = TestSubscriber.create() - val testCaptchaCanceled = TestSubscriber.create() - - client.isCaptchaSuccess.subscribe(testCaptchaSuccess) - client.isCaptchaCanceled.subscribe(testCaptchaCanceled) - - client.start(ApplicationProvider.getApplicationContext()) - client.intercept(mockResponse) - - assertFalse(client.isChallenged(mockBody)) - testCaptchaCanceled.assertNoValues() - testCaptchaSuccess.assertNoValues() - } -} diff --git a/build.gradle b/build.gradle index eb30f6e60c..d511581b7c 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,6 @@ allprojects { url 'http://appboy.github.io/appboy-segment-android/sdk' allowInsecureProtocol = true } - maven { url 'https://perimeterx.jfrog.io/artifactory/px-Android-SDK/' } } }