mockcard-rails 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 71ee8d2dc5416ea8327f04808052ecfa0cb381495e64747c886d549bf7bb1acc
4
+ data.tar.gz: 894ff28d6f8ec386a91c33ee2fb19f9d1ff48f2c2dc47db34db81b6d5961e5f1
5
+ SHA512:
6
+ metadata.gz: 07771466c9e57ff7831ade7664110c1d82abb34c96e13f2bbceee7df25cc2dbe5510af3100d88c630b2d52f17e4f5156b5b74c108d972161b843fa0a2e0cf105
7
+ data.tar.gz: 04d1b669bcba6c016a651cfec27890eab8c8938a1f415038b9d1697c03e6a14392e1c11f14c2b9bd69525c1bd7b764c125bd5ebdc3b7cbb642f89fa82ddb238b
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Arixeva Labs <hello@arixevalabs.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction,
7
+ including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9
+ subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
16
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # mockcard-rails
2
+
3
+ MockCard for Rails: guard your payment webhook routes against MockCard's production probes, with
4
+ secrets from Rails credentials. Chaos runs and test helpers come from the `mockcard` gem.
5
+
6
+ Author: Arixeva Labs <hello@arixevalabs.com> · [mockcard.io](https://www.mockcard.io) · MIT
7
+
8
+ ```ruby
9
+ gem "mockcard-rails"
10
+ ```
11
+
12
+ ```sh
13
+ bin/rails generate mockcard:install
14
+ bin/rails credentials:edit # mockcard: { api_key: "mc_…", probe_secret: "mcp_…" }
15
+ ```
16
+
17
+ The initializer lists the webhook paths to guard (`config.mockcard.webhook_paths`). Verified MockCard
18
+ probes to those paths get `200` + `MockCard-Probe-Ack: skipped` before Rails routes them; everything
19
+ else, including forged probes, reaches your controllers as usual. Works with the Pay gem's webhook route.
20
+
21
+ For chaos runs in your test suite, see the [`mockcard`](https://rubygems.org/gems/mockcard) gem.
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # `bin/rails generate mockcard:install` — adds config/initializers/mockcard.rb.
4
+ #
5
+ # Author: Arixeva Labs <hello@arixevalabs.com>
6
+ require "rails/generators"
7
+
8
+ module Mockcard
9
+ module Generators
10
+ class InstallGenerator < ::Rails::Generators::Base
11
+ source_root File.expand_path("templates", __dir__)
12
+ desc "Creates the MockCard initializer."
13
+
14
+ # Copies the initializer template.
15
+ # @return [void]
16
+ def create_initializer
17
+ template "mockcard.rb", "config/initializers/mockcard.rb"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # MockCard (https://www.mockcard.io). Secrets live in credentials:
4
+ # bin/rails credentials:edit → mockcard: { api_key: "mc_…", probe_secret: "mcp_…" }
5
+ Rails.application.configure do
6
+ # Payment webhook paths guarded against MockCard production probes (verified probes get 200 +
7
+ # MockCard-Probe-Ack and never reach your controllers).
8
+ config.mockcard.webhook_paths = ["/webhooks/stripe", "/pay/webhooks"]
9
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Rack middleware for payment webhook paths: answers verified MockCard production probes with
4
+ # 200 + "MockCard-Probe-Ack: skipped" before Rails routes the request. Forged probes pass through to
5
+ # your normal handling, so the header can never make your app process anything it otherwise wouldn't.
6
+ #
7
+ # Author: Arixeva Labs <hello@arixevalabs.com>
8
+ module MockCard
9
+ module Rails
10
+ class ProbeGuard
11
+ # @param app [#call] The next Rack app.
12
+ # @param probe_secret [String, #call] The probe secret, or a proc returning it (read lazily).
13
+ # @param paths [Array<String>] Only requests to these path prefixes are checked.
14
+ def initialize(app, probe_secret:, paths: ["/"])
15
+ @app = app
16
+ @probe_secret = probe_secret
17
+ @paths = paths
18
+ end
19
+
20
+ # @param env [Hash] The Rack env.
21
+ # @return [Array] The probe acknowledgement, or the next app's response.
22
+ def call(env)
23
+ return @app.call(env) unless env["REQUEST_METHOD"] == "POST" && @paths.any? { |p| env["PATH_INFO"].to_s.start_with?(p) } && MockCard::Probe.probe?(env)
24
+
25
+ input = env["rack.input"]
26
+ body = input.read.to_s
27
+ input.rewind
28
+ secret = @probe_secret.respond_to?(:call) ? @probe_secret.call : @probe_secret
29
+ return @app.call(env) unless MockCard::Probe.verify(env, body, secret.to_s)
30
+
31
+ [200, { "content-type" => "application/json", MockCard::Probe::ACK_HEADER.downcase => "skipped" }, ['{"received":true,"probe":true}']]
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Wires MockCard into Rails: `config.mockcard.webhook_paths` enables the probe guard for those paths,
4
+ # and the probe secret / API key come from `config.mockcard`, Rails credentials (`mockcard:`) or ENV.
5
+ #
6
+ # Author: Arixeva Labs <hello@arixevalabs.com>
7
+ require "active_support/ordered_options"
8
+
9
+ module MockCard
10
+ module Rails
11
+ class Railtie < ::Rails::Railtie
12
+ config.mockcard = ActiveSupport::OrderedOptions.new
13
+ config.mockcard.webhook_paths = []
14
+
15
+ initializer "mockcard.probe_guard" do |app|
16
+ paths = app.config.mockcard.webhook_paths
17
+ next if paths.empty?
18
+
19
+ secret = -> { app.config.mockcard.probe_secret || app.credentials.dig(:mockcard, :probe_secret) || ENV["MOCKCARD_PROBE_SECRET"] }
20
+ app.middleware.insert_before 0, MockCard::Rails::ProbeGuard, probe_secret: secret, paths: paths
21
+ end
22
+
23
+ initializer "mockcard.api_key" do |app|
24
+ key = app.config.mockcard.api_key || app.credentials.dig(:mockcard, :api_key)
25
+ ENV["MOCKCARD_API_KEY"] ||= key if key
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # MockCard for Rails. Author: Arixeva Labs <hello@arixevalabs.com>
4
+ require "mockcard"
5
+ require_relative "mockcard/rails/probe_guard"
6
+ require_relative "mockcard/rails/railtie" if defined?(Rails::Railtie)
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mockcard-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Arixeva Labs
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: mockcard
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: "2.0"
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: "2.0"
28
+ - !ruby/object:Gem::Dependency
29
+ name: railties
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ -
33
+ - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "7.1"
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ -
41
+ - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "7.1"
44
+ description: "Rails integration for MockCard: Rack middleware that answers MockCard's production monitoring probes safely, Rails credentials support and a rails g mockcard:install generator. Builds on the mockcard gem."
45
+ email: hello@arixevalabs.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - LICENSE
51
+ - README.md
52
+ - lib/generators/mockcard/install/install_generator.rb
53
+ - lib/generators/mockcard/install/templates/mockcard.rb
54
+ - lib/mockcard-rails.rb
55
+ - lib/mockcard/rails/probe_guard.rb
56
+ - lib/mockcard/rails/railtie.rb
57
+ homepage: "https://www.mockcard.io"
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: "https://www.mockcard.io"
62
+ documentation_uri: "https://www.mockcard.io/docs"
63
+ source_code_uri: "https://github.com/arixevalabs/mockcard-rails"
64
+ bug_tracker_uri: "https://github.com/arixevalabs/mockcard-rails/issues"
65
+ rubygems_mfa_required: "true"
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ -
72
+ - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "3.1"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ -
78
+ - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ requirements: []
82
+ rubygems_version: 4.1.0
83
+ specification_version: 4
84
+ summary: "MockCard for Rails: probe-guard middleware, credentials integration and an install generator."
85
+ test_files: []