1
0
зеркало из https://github.com/glebtv/yookassa.git synced 2026-09-07 19:35:51 +03:00

fix webhook auth diagnostics and token length handling

Этот коммит содержится в:
Gleb Tv
2026-03-25 18:27:58 +03:00
родитель 5b002870b7
Коммит 185a470641
2 изменённых файлов: 63 добавлений и 10 удалений

Просмотреть файл

@@ -36,6 +36,11 @@ RSpec.describe Yookassa::WebhooksController do
end
it "rejects webhook when token is invalid" do
payments_client = instance_double(Yookassa::Payments)
allow(Yookassa).to receive(:payments).and_return(payments_client)
allow(payments_client).to receive(:find).with(payment_id: "payment-1")
.and_return(instance_double(Yookassa::Entity::Payment, id: "payment-1", status: "succeeded"))
post "/yookassa/webhooks/wrong-token", payload, headers
expect(last_response.status).to eq(401)
@@ -64,6 +69,21 @@ RSpec.describe Yookassa::WebhooksController do
end
end
describe "logging", :rails do
it "logs auth result when webhook authentication fails" do
controller = described_class.new
allow(controller).to receive(:token_valid?).and_return(true)
allow(controller).to receive(:source_ip_allowed?).and_return(false)
allow(controller).to receive(:payload_matches_api_object?).and_return(true)
allow(controller).to receive(:request).and_return(instance_double(ActionDispatch::Request, remote_ip: "192.168.0.10"))
expect(Rails.logger).to receive(:info).with(include("Auth failed: token=true, ip=false, api=true"))
expect(controller.send(:authentic_webhook?, {})).to eq(false)
end
end
describe "IP source check", :rails do
it "uses request.remote_ip" do
controller = described_class.new