diff --git a/lib/checkout_sdk/environment_subdomain.rb b/lib/checkout_sdk/environment_subdomain.rb index a65260a..d10d653 100644 --- a/lib/checkout_sdk/environment_subdomain.rb +++ b/lib/checkout_sdk/environment_subdomain.rb @@ -29,8 +29,7 @@ def add_subdomain_to_api_url_environment(environment, subdomain) api_url = environment.base_uri new_environment = api_url - # Regex to match a subdomain consisting of 8 to 11 lowercase alphanumeric characters - if subdomain =~ /^[0-9a-z]{8,11}$/ + if subdomain =~ /^[0-9a-z]+$/ url_parts = URI.parse(api_url) new_host = "#{subdomain}.#{url_parts.host}" diff --git a/spec/checkout_sdk/configuration/configuration_spec.rb b/spec/checkout_sdk/configuration/configuration_spec.rb index a97d596..3da329a 100644 --- a/spec/checkout_sdk/configuration/configuration_spec.rb +++ b/spec/checkout_sdk/configuration/configuration_spec.rb @@ -31,9 +31,10 @@ class FakeLogger end [ - %w[123dmain https://123dmain.api.sandbox.checkout.com/], - %w[123domain https://123domain.api.sandbox.checkout.com/], - %w[1234domain https://1234domain.api.sandbox.checkout.com/], + %w[a https://a.api.sandbox.checkout.com/], + %w[ab https://ab.api.sandbox.checkout.com/], + %w[abc https://abc.api.sandbox.checkout.com/], + %w[abc1 https://abc1.api.sandbox.checkout.com/], %w[12345domain https://12345domain.api.sandbox.checkout.com/] ].each do |subdomain, expected_url| it "should create configuration with subdomain #{subdomain}" do @@ -57,11 +58,13 @@ class FakeLogger [ ['', 'https://api.sandbox.checkout.com/'], - %w[123 https://api.sandbox.checkout.com/], - %w[123bad https://api.sandbox.checkout.com/], - %w[12345domainBad https://api.sandbox.checkout.com/] + [' ', 'https://api.sandbox.checkout.com/'], + [' ', 'https://api.sandbox.checkout.com/'], + [' - ', 'https://api.sandbox.checkout.com/'], + ['a b', 'https://api.sandbox.checkout.com/'], + ['ab bc1', 'https://api.sandbox.checkout.com/'] ].each do |subdomain, expected_url| - it 'should create configuration with bad subdomain #{subdomain}' do + it "should create configuration with bad subdomain #{subdomain}" do environment_subdomain = CheckoutSdk::EnvironmentSubdomain.new(CheckoutSdk::Environment.sandbox, subdomain) configuration = CheckoutSdk::CheckoutConfiguration.new(