Fix push gateway with some push provider (Sunup/autopush) (#5741)
* Add more HTTP response code returning NoMatrixGateway Fix Push notifications with Mozilla's autopush that returns 406 * Update gateway resolver tests to match new known errors
This commit is contained in:
@@ -64,8 +64,9 @@ class DefaultUnifiedPushGatewayResolver(
|
||||
UnifiedPushGatewayResolverResult.NoMatrixGateway
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
if ((throwable as? HttpException)?.code() == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||
Timber.tag(loggerTag.value).i("Checking for UnifiedPush endpoint yielded 404, using fallback")
|
||||
val code = (throwable as? HttpException)?.code()
|
||||
if (code in NoMatrixGatewayResp) {
|
||||
Timber.tag(loggerTag.value).i("Checking for UnifiedPush endpoint yielded $code, using fallback")
|
||||
UnifiedPushGatewayResolverResult.NoMatrixGateway
|
||||
} else {
|
||||
Timber.tag(loggerTag.value).e(throwable, "Error checking for UnifiedPush endpoint")
|
||||
@@ -75,4 +76,14 @@ class DefaultUnifiedPushGatewayResolver(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val NoMatrixGatewayResp = listOf<Int>(
|
||||
HttpURLConnection.HTTP_UNAUTHORIZED,
|
||||
HttpURLConnection.HTTP_FORBIDDEN,
|
||||
HttpURLConnection.HTTP_NOT_FOUND,
|
||||
HttpURLConnection.HTTP_BAD_METHOD,
|
||||
HttpURLConnection.HTTP_NOT_ACCEPTABLE
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ class DefaultUnifiedPushGatewayResolverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when a custom url is forbidden (403), Error is returned`() = runTest {
|
||||
fun `when a custom url is forbidden (403), NoMatrixGateway is returned`() = runTest {
|
||||
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
|
||||
discoveryResponse = {
|
||||
throw HttpException(Response.error<Unit>(HttpURLConnection.HTTP_FORBIDDEN, "".toResponseBody()))
|
||||
@@ -130,6 +130,36 @@ class DefaultUnifiedPushGatewayResolverTest {
|
||||
)
|
||||
val result = sut.getGateway("http://custom.url")
|
||||
assertThat(unifiedPushApiFactory.baseUrlParameter).isEqualTo("http://custom.url")
|
||||
assertThat(result).isEqualTo(UnifiedPushGatewayResolverResult.NoMatrixGateway)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when a custom url is not acceptable (406), NoMatrixGateway is returned`() = runTest {
|
||||
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
|
||||
discoveryResponse = {
|
||||
throw HttpException(Response.error<Unit>(HttpURLConnection.HTTP_NOT_ACCEPTABLE, "".toResponseBody()))
|
||||
}
|
||||
)
|
||||
val sut = createDefaultUnifiedPushGatewayResolver(
|
||||
unifiedPushApiFactory = unifiedPushApiFactory
|
||||
)
|
||||
val result = sut.getGateway("http://custom.url")
|
||||
assertThat(unifiedPushApiFactory.baseUrlParameter).isEqualTo("http://custom.url")
|
||||
assertThat(result).isEqualTo(UnifiedPushGatewayResolverResult.NoMatrixGateway)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when a custom url is internal error (500), Error is returned`() = runTest {
|
||||
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
|
||||
discoveryResponse = {
|
||||
throw HttpException(Response.error<Unit>(HttpURLConnection.HTTP_INTERNAL_ERROR, "".toResponseBody()))
|
||||
}
|
||||
)
|
||||
val sut = createDefaultUnifiedPushGatewayResolver(
|
||||
unifiedPushApiFactory = unifiedPushApiFactory
|
||||
)
|
||||
val result = sut.getGateway("http://custom.url")
|
||||
assertThat(unifiedPushApiFactory.baseUrlParameter).isEqualTo("http://custom.url")
|
||||
assertThat(result).isEqualTo(UnifiedPushGatewayResolverResult.Error("http://custom.url/_matrix/push/v1/notify"))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user