Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ TEST_INTEGRATIONS_70 := \
test_integrations_phpredis5 \
test_integrations_predis_1 \
test_integrations_ratchet \
test_integrations_sqlsrv
test_integrations_sqlsrv \
test_integrations_stripe_latest

TEST_WEB_70 := \
test_metrics \
Expand Down Expand Up @@ -620,6 +621,7 @@ TEST_INTEGRATIONS_71 := \
test_integrations_predis_1 \
test_integrations_ratchet \
test_integrations_sqlsrv \
test_integrations_stripe_latest \
test_opentracing_10

TEST_WEB_71 := \
Expand Down Expand Up @@ -676,6 +678,7 @@ TEST_INTEGRATIONS_72 := \
test_integrations_predis_latest \
test_integrations_ratchet \
test_integrations_sqlsrv \
test_integrations_stripe_latest \
test_opentracing_10

TEST_WEB_72 := \
Expand Down Expand Up @@ -738,6 +741,7 @@ TEST_INTEGRATIONS_73 :=\
test_integrations_predis_latest \
test_integrations_ratchet \
test_integrations_sqlsrv \
test_integrations_stripe_latest \
test_opentracing_10

TEST_WEB_73 := \
Expand Down Expand Up @@ -802,6 +806,7 @@ TEST_INTEGRATIONS_74 := \
test_integrations_ratchet \
test_integrations_roadrunner \
test_integrations_sqlsrv \
test_integrations_stripe_latest \
test_opentracing_10

TEST_WEB_74 := \
Expand Down Expand Up @@ -869,6 +874,7 @@ TEST_INTEGRATIONS_80 := \
test_integrations_predis_latest \
test_integrations_ratchet \
test_integrations_sqlsrv \
test_integrations_stripe_latest \
test_integrations_swoole_5 \
test_opentracing_10

Expand Down Expand Up @@ -925,6 +931,7 @@ TEST_INTEGRATIONS_81 := \
test_integrations_predis_latest \
test_integrations_ratchet \
test_integrations_sqlsrv \
test_integrations_stripe_latest \
test_integrations_swoole_5 \
test_opentracing_10

Expand Down Expand Up @@ -970,6 +977,7 @@ TEST_INTEGRATIONS_82 := \
test_integrations_monolog_latest \
test_integrations_mysqli \
test_integrations_openai_latest \
test_integrations_stripe_latest \
test_opentelemetry_1 \
test_opentelemetry_beta \
test_integrations_googlespanner_latest \
Expand Down Expand Up @@ -1037,6 +1045,7 @@ TEST_INTEGRATIONS_83 := \
test_integrations_monolog_latest \
test_integrations_mysqli \
test_integrations_openai_latest \
test_integrations_stripe_latest \
test_opentelemetry_1 \
test_opentelemetry_beta \
test_integrations_googlespanner_latest \
Expand Down Expand Up @@ -1099,6 +1108,7 @@ TEST_INTEGRATIONS_84 := \
test_integrations_monolog_latest \
test_integrations_mysqli \
test_integrations_openai_latest \
test_integrations_stripe_latest \
test_opentelemetry_1 \
test_integrations_googlespanner_latest \
test_integrations_guzzle_latest \
Expand Down Expand Up @@ -1146,6 +1156,7 @@ TEST_INTEGRATIONS_85 := \
test_integrations_monolog_latest \
test_integrations_mysqli \
test_integrations_openai_latest \
test_integrations_stripe_latest \
test_opentelemetry_1 \
test_integrations_guzzle_latest \
test_integrations_pcntl \
Expand Down Expand Up @@ -1393,6 +1404,8 @@ test_integrations_openai_latest: global_test_run_dependencies tests/Integrations
$(eval TELEMETRY_ENABLED=1)
$(call run_tests_debug,tests/Integrations/OpenAI/Latest)
$(eval TELEMETRY_ENABLED=0)
test_integrations_stripe_latest: global_test_run_dependencies tests/Integrations/Stripe/Latest/composer.lock-php$(PHP_MAJOR_MINOR)
$(call run_tests_debug,tests/Integrations/Stripe/Latest)
test_integrations_pcntl: global_test_run_dependencies
$(call run_tests_debug,tests/Integrations/PCNTL)
test_integrations_pdo: global_test_run_dependencies
Expand Down
2 changes: 1 addition & 1 deletion appsec/tests/integration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ testMatrix.each { spec ->
dependsOn "buildTracer-${phpVersion}-${variant}"
dependsOn "buildAppsec-${phpVersion}-${variant}"

if (version in ['7.0', '7.1']) {
if (phpVersion in ['7.0', '7.1']) {
dependsOn downloadComposerOld
} else {
dependsOn downloadComposer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package com.datadog.appsec.php.mock_stripe

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import io.javalin.Javalin
import io.javalin.http.Context
import groovy.json.JsonOutput
import org.testcontainers.lifecycle.Startable

@Slf4j
@CompileStatic
class MockStripeServer implements Startable {
Javalin httpServer

@Override
void start() {
this.httpServer = Javalin.create(config -> {
config.showJavalinBanner = false
})

httpServer.post("/v1/checkout/sessions") { ctx ->
handleCheckoutSessionCreate(ctx)
}

httpServer.post("/v1/payment_intents") { ctx ->
handlePaymentIntentCreate(ctx)
}

httpServer.error(404, ctx -> {
log.info("Unmatched Stripe mock request: ${ctx.method()} ${ctx.path()}")
ctx.status(404).json(['StripeMock error': 'Not Found'])
})

httpServer.error(405, ctx -> {
ctx.status(405).json(['StripeMock error': 'Method Not Allowed'])
})

httpServer.start(0)
}

int getPort() {
this.httpServer.port()
}

@Override
void stop() {
if (httpServer != null) {
this.httpServer.stop()
this.httpServer = null
}
}

private void handleCheckoutSessionCreate(Context ctx) {
def mode = ctx.formParam("mode")
def clientRefId = ctx.formParam("client_reference_id")

ctx.status(200).json([
id: "cs_test_" + System.currentTimeMillis(),
object: "checkout.session",
mode: mode ?: "payment",
amount_total: 1000,
currency: "usd",
client_reference_id: clientRefId ?: "test_ref",
livemode: false,
payment_status: "unpaid",
status: "open",
discounts: [
[
coupon: "SUMMER20",
promotion_code: "promo_123"
]
],
total_details: [
amount_discount: 200,
amount_shipping: 500,
amount_tax: 0
]
])
}

private void handlePaymentIntentCreate(Context ctx) {
def amountStr = ctx.formParam("amount")
def currency = ctx.formParam("currency")

ctx.status(200).json([
id: "pi_test_" + System.currentTimeMillis(),
object: "payment_intent",
amount: amountStr ? Integer.parseInt(amountStr) : 2000,
currency: currency ?: "usd",
livemode: false,
payment_method: "pm_test_123",
status: "requires_payment_method"
])
}

static Map<String, Object> createWebhookSuccessEvent() {
return [
id: "evt_test_success_${System.currentTimeMillis()}",
object: "event",
type: "payment_intent.succeeded",
data: [
object: [
id: "pi_test_success_123",
object: "payment_intent",
amount: 2000,
currency: "usd",
livemode: false,
payment_method: "pm_test_123",
status: "succeeded"
]
]
]
}

static Map<String, Object> createWebhookFailureEvent() {
return [
id: "evt_test_failure_${System.currentTimeMillis()}",
object: "event",
type: "payment_intent.payment_failed",
data: [
object: [
id: "pi_test_failure_456",
object: "payment_intent",
amount: 1500,
currency: "eur",
livemode: false,
last_payment_error: [
code: "card_declined",
decline_code: "insufficient_funds",
payment_method: [
id: "pm_test_456",
type: "card"
]
],
status: "requires_payment_method"
]
]
]
}

static Map<String, Object> createWebhookCancellationEvent() {
return [
id: "evt_test_cancel_${System.currentTimeMillis()}",
object: "event",
type: "payment_intent.canceled",
data: [
object: [
id: "pi_test_cancel_789",
object: "payment_intent",
amount: 3000,
currency: "gbp",
livemode: false,
cancellation_reason: "requested_by_customer",
status: "canceled"
]
]
]
}

static Map<String, Object> createWebhookUnsupportedEvent() {
return [
id: "evt_test_unsupported_${System.currentTimeMillis()}",
object: "event",
type: "customer.created",
data: [
object: [
id: "cus_test_123",
object: "customer",
email: "test@example.com"
]
]
]
}
}
Loading
Loading