Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 5ac70a3

Browse files
authored
Merge pull request #2985 from wordpress-mobile/issue/detect-captcha-pattern
2 parents f154a1a + 2a7c1f3 commit 5ac70a3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/Nonce.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ sealed interface Nonce {
1919
enum class CookieNonceErrorType {
2020
NOT_AUTHENTICATED,
2121
INVALID_RESPONSE,
22+
INVALID_CREDENTIALS,
2223
CUSTOM_LOGIN_URL,
2324
CUSTOM_ADMIN_URL,
2425
INVALID_NONCE,

fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/NonceRestClient.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,18 @@ class NonceRestClient @Inject constructor(
6969
// that it's an authentication issue, otherwise we'll assume it's an invalid response
7070
val errorMessage = extractErrorMessage(response.data.orEmpty())
7171

72+
val errorType = if (hasInvalidCredentialsPattern(response.data.orEmpty())) {
73+
Nonce.CookieNonceErrorType.INVALID_CREDENTIALS
74+
} else if (errorMessage != null) {
75+
Nonce.CookieNonceErrorType.NOT_AUTHENTICATED
76+
} else {
77+
Nonce.CookieNonceErrorType.INVALID_RESPONSE
78+
}
79+
7280
FailedRequest(
7381
timeOfResponse = currentTimeProvider.currentDate().time,
7482
username = username,
75-
type = if (errorMessage != null) Nonce.CookieNonceErrorType.NOT_AUTHENTICATED
76-
else Nonce.CookieNonceErrorType.INVALID_RESPONSE,
83+
type = errorType,
7784
errorMessage = errorMessage
7885
)
7986
}
@@ -145,4 +152,11 @@ class NonceRestClient @Inject constructor(
145152
return HtmlUtils.fastStripHtml(errorHtml)
146153
.trim(' ', '\n')
147154
}
155+
156+
private fun hasInvalidCredentialsPattern(htmlResponse: String) =
157+
htmlResponse.contains(INVALID_CREDENTIAL_HTML_PATTERN)
158+
159+
companion object {
160+
const val INVALID_CREDENTIAL_HTML_PATTERN = "document.querySelector('form').classList.add('shake')"
161+
}
148162
}

0 commit comments

Comments
 (0)