From 4c889751c3789ff4c7390a2d6f75fcf9faaac7a1 Mon Sep 17 00:00:00 2001 From: Adrian Gruntkowski Date: Mon, 6 Jan 2025 13:21:22 +0100 Subject: [PATCH] Remove support for legacy Paddle webhook passthrough formats --- lib/plausible/billing/billing.ex | 8 -------- test/plausible/billing/billing_test.exs | 19 ------------------- .../api/paddle_controller_test.exs | 6 ++++-- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.ex index ca7ed18a909c..245d78f53f7d 100644 --- a/lib/plausible/billing/billing.ex +++ b/lib/plausible/billing/billing.ex @@ -157,14 +157,6 @@ defmodule Plausible.Billing do ["ee:true", "user:" <> user_id] -> {user_id, "0"} - # NOTE: legacy pattern, to be removed in a follow-up - ["user:" <> user_id, "team:" <> team_id] -> - {user_id, team_id} - - # NOTE: legacy pattern, to be removed in a follow-up - [user_id] -> - {user_id, "0"} - _ -> raise "Invalid passthrough sent via Paddle: #{inspect(passthrough)}" end diff --git a/test/plausible/billing/billing_test.exs b/test/plausible/billing/billing_test.exs index a5c72959ef8d..5cc1da016236 100644 --- a/test/plausible/billing/billing_test.exs +++ b/test/plausible/billing/billing_test.exs @@ -225,25 +225,6 @@ defmodule Plausible.BillingTest do assert subscription.currency_code == "EUR" end - test "supports old format without prefix" do - user = new_user() - {:ok, team} = Plausible.Teams.get_or_create(user) - - %{@subscription_created_params | "passthrough" => "user:#{user.id};team:#{team.id}"} - |> Billing.subscription_created() - - assert user |> team_of() |> Plausible.Teams.with_subscription() |> Map.fetch!(:subscription) - end - - test "supports old format without prefix for user without a team" do - user = new_user() - - %{@subscription_created_params | "passthrough" => user.id} - |> Billing.subscription_created() - - assert user |> team_of() |> Plausible.Teams.with_subscription() |> Map.fetch!(:subscription) - end - test "unlocks sites if user has any locked sites" do user = new_user() site = new_site(owner: user, locked: true) diff --git a/test/plausible_web/controllers/api/paddle_controller_test.exs b/test/plausible_web/controllers/api/paddle_controller_test.exs index f37f2e22d67d..47f46c49258e 100644 --- a/test/plausible_web/controllers/api/paddle_controller_test.exs +++ b/test/plausible_web/controllers/api/paddle_controller_test.exs @@ -33,8 +33,10 @@ defmodule PlausibleWeb.Api.PaddleControllerTest do test "is verified when signature is correct", %{conn: conn} do insert(:user, id: 235) - conn = post(conn, Routes.paddle_path(conn, :webhook), @webhook_body) - assert conn.status == 200 + # NOTE: signature check happens sooner + assert_raise RuntimeError, ~r/Invalid passthrough sent via Paddle/, fn -> + post(conn, Routes.paddle_path(conn, :webhook), @webhook_body) + end end test "not verified when signature is corrupted", %{conn: conn} do