Skip to content

Fix: enforce argument validation in Client#initialize via setter methods#356

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-client-initialization-argument-checks
Open

Fix: enforce argument validation in Client#initialize via setter methods#356
Copilot wants to merge 2 commits intomainfrom
copilot/fix-client-initialization-argument-checks

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

Client.new(env: "live") silently accepted invalid env values by assigning directly to @env, bypassing the env= setter's ArgumentError guard. Same issue applied to live_url_prefix.

Changes

  • initialize: Use self.env = env and self.live_url_prefix = live_url_prefix instead of direct instance variable assignment, so setter validations apply at construction time
  • live_url_prefix=: Guard against nil input (needed since nil is the default, and the setter previously called [] on the value unconditionally)

Before / After

# Before: silently accepted, causing subtle bugs downstream (e.g. `@env == :live` checks)
client = Adyen::Client.new(env: "live")  # no error raised

# After: consistent with setter behaviour
client = Adyen::Client.new(env: "live")  # => ArgumentError
client.env = "live"                       # => ArgumentError (already worked)
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: Client is initialized without proper argument check</issue_title>
<issue_description>### Description

Initializing client skips argument checks and validations

Steps to reproduce

Call Adyen::Client.new with arguments env or live_url_prefix instead of using the env=, live_url_prefix= methods.

This allows initializing client with invalid env, which has implications later in code, e.g. checks like this(@env == :live)

Actual behavior

# This correctly raises ArgumentError, because we set "live" instead of (symbol) :live
client = Adyen::Client.new
client.env = "live"

# This should also raise ArgumentError, but doesn't:
client = Adyen::Client.new(env: "live")

(Similar case can be made for live_url_prefix.)

Expected behavior

# This should also raise ArgumentError
client = Adyen::Client.new(env: "live")

Code snippet or screenshots (if applicable)

Proposal solution: use the setter methods also in initialize.

# in client.rb
def initialize(...)
  ...
  @env = env # <-- replace with `self.env = env`
  ...
  @live_url_prefix = live_url_prefix # <-- replace with self.live_url_prefix = live_url_prefix
  ...  
end

Adyen Ruby API Library version

10.2.0

Ruby language version

3.4.1

Operating System

macOS

Additional context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…ix validation

Co-authored-by: gcatanese <1771700+gcatanese@users.noreply.github.com>
@sonarqubecloud
Copy link

Copilot AI changed the title [WIP] [Bug] Fix client initialization without proper argument checks Fix: enforce argument validation in Client#initialize via setter methods Mar 13, 2026
Copilot AI requested a review from gcatanese March 13, 2026 07:37
@gcatanese gcatanese marked this pull request as ready for review March 13, 2026 08:54
@gcatanese gcatanese requested review from a team as code owners March 13, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Client is initialized without proper argument check

2 participants