Skip to content

Commit 5591795

Browse files
committed
Don't gate capability detection behind a mint for WP.com Simple sites
WP.com Simple sites are proxy-served and OAuth-authed; the application-password mint returns NotSupported for them, so the pipeline was returning Unprovisionable and never reaching capability detection (which works fine through the proxy) -- a regression vs. the old ungated probe. ensureAuth now short-circuits them to a new SiteAuthState.NotApplicable (treated like Provisioned), and recoverRestUrlIfNeeded skips them too.
1 parent f52c9cd commit 5591795

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

WordPress/src/main/java/org/wordpress/android/repositories/SiteProvisioningSource.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class SiteProvisioningSource @Inject constructor(
140140

141141
private suspend fun runPipeline(siteLocalId: Int): SiteReadiness =
142142
when (val auth = ensureAuth(siteLocalId)) {
143-
SiteAuthState.Provisioned -> coroutineScope {
143+
SiteAuthState.Provisioned, SiteAuthState.NotApplicable -> coroutineScope {
144144
// Post-auth, the REST-capability chain and the XML-RPC recovery are independent —
145145
// each reads the site fresh and writes only its own column — so run them in
146146
// parallel. recoverRestUrlIfNeeded precedes detectCapabilities within its branch because
@@ -165,6 +165,10 @@ class SiteProvisioningSource @Inject constructor(
165165
private suspend fun ensureAuth(siteLocalId: Int): SiteAuthState {
166166
val site = siteStore.getSiteByLocalId(siteLocalId)
167167
?: return SiteAuthState.Unprovisionable(hadCredentials = false)
168+
// WP.com Simple sites are fully proxied and OAuth-bearer-authed — no application password
169+
// applies (the mint returns NotSupported). Capability detection works through the proxy, so
170+
// treat them as ready instead of blocking detection behind a mint that can never run.
171+
if (site.isWPComSimpleSite) return SiteAuthState.NotApplicable
168172
val hadCredentials = !applicationPasswordLoginHelper.siteHasBadCredentials(site)
169173
if (hadCredentials) {
170174
when (applicationPasswordValidator.validate(site)) {
@@ -201,7 +205,9 @@ class SiteProvisioningSource @Inject constructor(
201205
*/
202206
private suspend fun recoverRestUrlIfNeeded(siteLocalId: Int) {
203207
val site = siteStore.getSiteByLocalId(siteLocalId) ?: return
204-
if (!site.wpApiRestUrl.isNullOrEmpty()) return
208+
// WP.com Simple sites are proxy-served — no direct REST host to recover (their wpApiRestUrl
209+
// is legitimately null), so don't burn a discovery call on them.
210+
if (site.isWPComSimpleSite || !site.wpApiRestUrl.isNullOrEmpty()) return
205211
siteApiRestUrlRecoverer.discoverApiRootUrl(site.url)?.let { apiRootUrl ->
206212
siteApiRestUrlRecoverer.persistApiRootUrl(siteLocalId, apiRootUrl)
207213
}
@@ -247,6 +253,10 @@ sealed interface SiteAuthState {
247253
/** Credentials are usable (validated, or freshly minted). */
248254
data object Provisioned : SiteAuthState
249255

256+
/** No application password applies — a WP.com Simple site, which is proxy-served and
257+
* OAuth-bearer-authed. Treated like [Provisioned]: capability detection runs via the proxy. */
258+
data object NotApplicable : SiteAuthState
259+
250260
/** Not usable yet, but not a terminal failure — a mint is implied / a transient
251261
* validation error occurred. The card stays hidden; the next run retries. */
252262
data object Provisioning : SiteAuthState

WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/applicationpassword/ApplicationPasswordViewModelSlice.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class ApplicationPasswordViewModelSlice @Inject constructor(
8282
uiModelMutable.postValue(null)
8383
appLogWrapper.d(AppLog.T.MAIN, "A_P: Provisioning in progress for ${site.url}")
8484
}
85-
SiteAuthState.Provisioned -> Unit // unreachable: Provisioned never wraps in NeedsAuth
85+
SiteAuthState.Provisioned, SiteAuthState.NotApplicable ->
86+
Unit // never wrap in NeedsAuth — they proceed to detection
8687
}
8788
// Any terminal provisioned state — the credentials are usable, so the only card left to
8889
// show is the self-hosted XML-RPC fallback. Capability outcome (Ready/Unreachable) is the

WordPress/src/test/java/org/wordpress/android/repositories/SiteProvisioningSourceTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ class SiteProvisioningSourceTest : BaseUnitTest(StandardTestDispatcher()) {
157157
assertThat(result).isEqualTo(SiteReadiness.NeedsAuth(SiteAuthState.Unprovisionable(hadCredentials = false)))
158158
}
159159

160+
@Test
161+
fun `given a WPCom Simple site, then it detects capabilities without minting`() = test {
162+
val simple = SiteModel().apply {
163+
id = TEST_SITE_LOCAL_ID
164+
url = "https://simple.wordpress.com"
165+
setIsWPCom(true) // isWPComSimpleSite = isWPCom && !isWPComAtomic
166+
wpApiRestUrl = "https://simple.wordpress.com/wp-json"
167+
}
168+
whenever(siteStore.getSiteByLocalId(TEST_SITE_LOCAL_ID)).thenReturn(simple)
169+
stubCapabilityProbe(ok = true)
170+
171+
assertThat(source.await(simple)).isEqualTo(SiteReadiness.Ready)
172+
// No application password applies — it must not validate or mint, just probe via the proxy.
173+
verify(applicationPasswordValidator, never()).validate(any())
174+
verify(siteStore, never()).createApplicationPassword(any())
175+
}
176+
160177
// endregion
161178

162179
// region recovery + capability stages

0 commit comments

Comments
 (0)