Skip to content

Commit

Permalink
fix: guava missing errors (#374)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomer Aberbach <tomer@stainlessapi.com>
  • Loading branch information
stainless-app[bot] and TomerAberbach committed Nov 7, 2024
1 parent 738ee4f commit 162f2f7
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ constructor(
.addPathSegments("v1", "embed", "card")
.putQueryParam("embed_request", embed_request)
.putQueryParam("hmac", embed_request_hmac)
.putAllHeaders(clientOptions.headers.asMap())
.putAllHeaders(clientOptions.headers)
.replaceAllHeaders(params.getHeaders())
.putHeader("Accept", "text/html")
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@

package com.lithic.api.services.async

import com.google.common.collect.ListMultimap
import com.lithic.api.core.JsonValue
import com.lithic.api.core.http.Headers

interface WebhookServiceAsync {

suspend fun unwrap(
payload: String,
headers: ListMultimap<String, String>,
secret: String?
): JsonValue
suspend fun unwrap(payload: String, headers: Headers, secret: String?): JsonValue

suspend fun verifySignature(
payload: String,
headers: ListMultimap<String, String>,
secret: String?
)
suspend fun verifySignature(payload: String, headers: Headers, secret: String?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
package com.lithic.api.services.async

import com.fasterxml.jackson.core.JsonProcessingException
import com.google.common.collect.ListMultimap
import com.lithic.api.core.ClientOptions
import com.lithic.api.core.JsonValue
import com.lithic.api.core.getRequiredHeader
import com.lithic.api.core.handlers.errorHandler
import com.lithic.api.core.http.Headers
import com.lithic.api.core.http.HttpResponse.Handler
import com.lithic.api.errors.LithicError
import com.lithic.api.errors.LithicException
Expand All @@ -25,11 +25,7 @@ constructor(

private val errorHandler: Handler<LithicError> = errorHandler(clientOptions.jsonMapper)

override suspend fun unwrap(
payload: String,
headers: ListMultimap<String, String>,
secret: String?
): JsonValue {
override suspend fun unwrap(payload: String, headers: Headers, secret: String?): JsonValue {
verifySignature(payload, headers, secret)
return try {
clientOptions.jsonMapper.readValue(payload, JsonValue::class.java)
Expand All @@ -38,11 +34,7 @@ constructor(
}
}

override suspend fun verifySignature(
payload: String,
headers: ListMultimap<String, String>,
secret: String?
) {
override suspend fun verifySignature(payload: String, headers: Headers, secret: String?) {
val webhookSecret =
secret
?: clientOptions.webhookSecret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ constructor(
.addPathSegments("v1", "embed", "card")
.putQueryParam("embed_request", embed_request)
.putQueryParam("hmac", embed_request_hmac)
.putAllHeaders(clientOptions.headers.asMap())
.putAllHeaders(clientOptions.headers)
.replaceAllHeaders(params.getHeaders())
.putHeader("Accept", "text/html")
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

package com.lithic.api.services.blocking

import com.google.common.collect.ListMultimap
import com.lithic.api.core.JsonValue
import com.lithic.api.core.http.Headers

interface WebhookService {

fun unwrap(payload: String, headers: ListMultimap<String, String>, secret: String?): JsonValue
fun unwrap(payload: String, headers: Headers, secret: String?): JsonValue

fun verifySignature(payload: String, headers: ListMultimap<String, String>, secret: String?)
fun verifySignature(payload: String, headers: Headers, secret: String?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
package com.lithic.api.services.blocking

import com.fasterxml.jackson.core.JsonProcessingException
import com.google.common.collect.ListMultimap
import com.lithic.api.core.ClientOptions
import com.lithic.api.core.JsonValue
import com.lithic.api.core.getRequiredHeader
import com.lithic.api.core.handlers.errorHandler
import com.lithic.api.core.http.Headers
import com.lithic.api.core.http.HttpResponse.Handler
import com.lithic.api.errors.LithicError
import com.lithic.api.errors.LithicException
Expand All @@ -25,11 +25,7 @@ constructor(

private val errorHandler: Handler<LithicError> = errorHandler(clientOptions.jsonMapper)

override fun unwrap(
payload: String,
headers: ListMultimap<String, String>,
secret: String?
): JsonValue {
override fun unwrap(payload: String, headers: Headers, secret: String?): JsonValue {
verifySignature(payload, headers, secret)
return try {
clientOptions.jsonMapper.readValue(payload, JsonValue::class.java)
Expand All @@ -38,11 +34,7 @@ constructor(
}
}

override fun verifySignature(
payload: String,
headers: ListMultimap<String, String>,
secret: String?
) {
override fun verifySignature(payload: String, headers: Headers, secret: String?) {
val webhookSecret =
secret
?: clientOptions.webhookSecret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

package com.lithic.api.services.blocking

import com.google.common.collect.ImmutableListMultimap
import com.lithic.api.TestServerExtension
import com.lithic.api.client.okhttp.LithicOkHttpClient
import com.lithic.api.core.http.Headers
import com.lithic.api.errors.LithicException
import com.lithic.api.models.*
import java.time.Clock
Expand All @@ -30,14 +30,11 @@ class WebhookServiceTest {
val payload =
"{\"card_token\":\"sit Lorem ipsum, accusantium repellendus possimus\",\"created_at\":\"elit. placeat libero architecto molestias, sit\",\"account_token\":\"elit.\",\"issuer_decision\":\"magnam, libero esse Lorem ipsum magnam, magnam,\",\"tokenization_attempt_id\":\"illum dolor repellendus libero esse accusantium\",\"wallet_decisioning_info\":{\"device_score\":\"placeat architecto\"},\"digital_wallet_token_metadata\":{\"status\":\"reprehenderit dolor\",\"token_requestor_id\":\"possimus\",\"payment_account_info\":{\"account_holder_data\":{\"phone_number\":\"libero\",\"email_address\":\"nobis molestias, veniam culpa! quas elit. quas libero esse architecto placeat\"},\"pan_unique_reference\":\"adipisicing odit magnam, odit\"}}}"
val headers =
ImmutableListMultimap.of(
"webhook-id",
"msg_2Lh9KRb0pzN4LePd3XiA4v12Axj",
"webhook-timestamp",
"1676312382",
"webhook-signature",
"v1,Dwa0AHInLL3XFo2sxcHamOQDrJNi7F654S3L6skMAOI="
)
Headers.builder()
.put("webhook-id", "msg_2Lh9KRb0pzN4LePd3XiA4v12Axj")
.put("webhook-timestamp", "1676312382")
.put("webhook-signature", "v1,Dwa0AHInLL3XFo2sxcHamOQDrJNi7F654S3L6skMAOI=")
.build()

val event = client.webhooks().unwrap(payload, headers, null)

Expand All @@ -59,28 +56,22 @@ class WebhookServiceTest {
val webhookTimestamp = "1676312382"
val webhookSignature = "Dwa0AHInLL3XFo2sxcHamOQDrJNi7F654S3L6skMAOI="
val headers =
ImmutableListMultimap.of(
"webhook-id",
webhookId,
"webhook-timestamp",
webhookTimestamp,
"webhook-signature",
"v1,$webhookSignature"
)
Headers.builder()
.put("webhook-id", webhookId)
.put("webhook-timestamp", webhookTimestamp)
.put("webhook-signature", "v1,$webhookSignature")
.build()

assertThatThrownBy {
client
.webhooks()
.verifySignature(
payload,
ImmutableListMultimap.of(
"webhook-id",
webhookId,
"webhook-timestamp",
"1676312022",
"webhook-signature",
"v1,$webhookSignature"
),
Headers.builder()
.put("webhook-id", webhookId)
.put("webhook-timestamp", "1676312022")
.put("webhook-signature", "v1,$webhookSignature")
.build(),
null
)
}
Expand All @@ -92,14 +83,11 @@ class WebhookServiceTest {
.webhooks()
.verifySignature(
payload,
ImmutableListMultimap.of(
"webhook-id",
webhookId,
"webhook-timestamp",
"1676312742",
"webhook-signature",
"v1,$webhookSignature"
),
Headers.builder()
.put("webhook-id", webhookId)
.put("webhook-timestamp", "1676312742")
.put("webhook-signature", "v1,$webhookSignature")
.build(),
null
)
}
Expand All @@ -119,14 +107,14 @@ class WebhookServiceTest {
.webhooks()
.verifySignature(
payload,
ImmutableListMultimap.of(
"webhook-id",
webhookId,
"webhook-timestamp",
webhookTimestamp,
"webhook-signature",
"v1,$webhookSignature v1,Zm9v",
),
Headers.builder()
.put("webhook-id", webhookId)
.put("webhook-timestamp", webhookTimestamp)
.put(
"webhook-signature",
"v1,$webhookSignature v1,Zm9v",
)
.build(),
null
)
}
Expand All @@ -137,14 +125,14 @@ class WebhookServiceTest {
.webhooks()
.verifySignature(
payload,
ImmutableListMultimap.of(
"webhook-id",
webhookId,
"webhook-timestamp",
webhookTimestamp,
"webhook-signature",
"v2,$webhookSignature",
),
Headers.builder()
.put("webhook-id", webhookId)
.put("webhook-timestamp", webhookTimestamp)
.put(
"webhook-signature",
"v2,$webhookSignature",
)
.build(),
null
)
}
Expand All @@ -156,14 +144,14 @@ class WebhookServiceTest {
.webhooks()
.verifySignature(
payload,
ImmutableListMultimap.of(
"webhook-id",
webhookId,
"webhook-timestamp",
webhookTimestamp,
"webhook-signature",
"v1,$webhookSignature v2,$webhookSignature",
),
Headers.builder()
.put("webhook-id", webhookId)
.put("webhook-timestamp", webhookTimestamp)
.put(
"webhook-signature",
"v1,$webhookSignature v2,$webhookSignature",
)
.build(),
null
)
}
Expand All @@ -174,14 +162,14 @@ class WebhookServiceTest {
.webhooks()
.verifySignature(
payload,
ImmutableListMultimap.of(
"webhook-id",
webhookId,
"webhook-timestamp",
webhookTimestamp,
"webhook-signature",
webhookSignature,
),
Headers.builder()
.put("webhook-id", webhookId)
.put("webhook-timestamp", webhookTimestamp)
.put(
"webhook-signature",
webhookSignature,
)
.build(),
null
)
}
Expand Down

0 comments on commit 162f2f7

Please sign in to comment.