Skip to content

Commit 7c2434c

Browse files
authored
Remove entropy from client failures (#262)
This removes details from client failures and include status code only so that entropy is minimized.
1 parent aec6a22 commit 7c2434c

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

modules/http4s/src/main/scala/com.snowplowanalytics.iglu/client/resolver/registries/Http4sRegistryLookup.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ object Http4sRegistryLookup {
134134
RegistryError.RepoFailure(error).asLeft
135135
}
136136
case Status.ClientError(response) =>
137-
response.bodyText.compile.string.map { body =>
138-
val error = s"Unexpected server response: $body"
139-
RegistryError.ClientFailure(error).asLeft
140-
}
137+
val error = s"Unexpected response code: ${response.status.code}"
138+
(RegistryError.ClientFailure(error): RegistryError).asLeft[A].pure[F]
141139
case response =>
142140
response.bodyText.compile.string.map { body =>
143141
val error = s"Unexpected response: $body"

modules/http4s/src/test/scala/com.snowplowanalytics.iglu/client/resolver/registries/Http4sRegistryLookupSpec.scala

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package com.snowplowanalytics.iglu.client.resolver.registries
1414

1515
import cats.effect.testing.specs2.CatsEffect
1616
import cats.effect.{IO, Resource}
17+
import com.snowplowanalytics.iglu.client.resolver.registries.RegistryError.ClientFailure
1718
import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaList, SchemaVer}
1819
import io.circe.Json
1920
import org.http4s.client.{Client => HttpClient}
@@ -84,6 +85,44 @@ class Http4sRegistryLookupSpec extends Specification with CatsEffect {
8485
result should beLeft
8586
}
8687
}
88+
89+
"return a registry error with status code only for a client failure - Forbidden" in {
90+
91+
val repositoryRef =
92+
Registry.Http(
93+
Registry.Config("name", 1, Nil),
94+
Registry.HttpConnection(URI.create("http://custom-iglu.com"), None)
95+
)
96+
val schemaKey = SchemaKey("com.myvendor", "status", "jsonschema", SchemaVer.Full(42, 42, 42))
97+
98+
val client = HttpClient[IO] { _ =>
99+
val dsl = new Http4sDsl[IO] {}; import dsl._
100+
Resource.eval(Forbidden("forbidden"))
101+
}
102+
103+
Http4sRegistryLookup(client).lookup(repositoryRef, schemaKey).map { result =>
104+
result should beLeft(ClientFailure("Unexpected response code: 403"))
105+
}
106+
}
107+
108+
"return a registry error with status code only for a client failure - RequestTimeout" in {
109+
110+
val repositoryRef =
111+
Registry.Http(
112+
Registry.Config("name", 1, Nil),
113+
Registry.HttpConnection(URI.create("http://custom-iglu.com"), None)
114+
)
115+
val schemaKey = SchemaKey("com.myvendor", "status", "jsonschema", SchemaVer.Full(42, 42, 42))
116+
117+
val client = HttpClient[IO] { _ =>
118+
val dsl = new Http4sDsl[IO] {}; import dsl._
119+
Resource.eval(RequestTimeout("timeout"))
120+
}
121+
122+
Http4sRegistryLookup(client).lookup(repositoryRef, schemaKey).map { result =>
123+
result should beLeft(ClientFailure("Unexpected response code: 408"))
124+
}
125+
}
87126
}
88127

89128
"The Http4sRegistryLookup list" should {

0 commit comments

Comments
 (0)