Sha256: da1afb7709328a281b2de272677ab1748c65508f1b575aba322510b83759a0d9

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'test_helper'

module Workarea
  module Storefront
    class FlowWebhookRackAttackIntegrationTest < Workarea::IntegrationTest
      include Workarea::FlowIo::WebhookIntegrationTest

      class AddEnvMiddleware
        def initialize(app)
          @app = app
        end

        def call(env)
          env.merge!(Rails.application.env_config)
          @app.call(env)
        end
      end

      def test_safelist_webhook_requests
        post_signed "/", params: { faked: "request" }.to_json
        assert_equal("allow flow webhooks", @rack_attack_rules["rack.attack.matched"])
        assert_equal(:safelist, @rack_attack_rules["rack.attack.match_type"])
      end

      def test_doesnt_safelist_with_bad_auth
        post "/", params: {}
        assert_nil(@rack_attack_rules["rack.attack.matched"])
        assert_nil(@rack_attack_rules["rack.attack.match_type"])
      end

      private

      def app
        @app ||=
          begin
            endpoint = ->(env) do
              @rack_attack_rules = env.slice(
                "rack.attack.matched",
                "rack.attack.match_type"
              )
              [200, {}, []]
            end

            Rack::Builder.new do
              use AddEnvMiddleware
              use Rack::Attack
              use ActionDispatch::Cookies
              run endpoint
            end
          end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-flow_io-1.2.1 test/integration/workarea/storefront/flow_webhook_rack_attack_integration_test.rb