5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-28 17:36:23 +00:00
panel/test/system/constraints_api_subdomain_test.rb

30 lines
754 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class ConstraintsApiSubdomainTest < ActiveSupport::TestCase
setup do
@constraint = Constraints::ApiSubdomain.new
MockRequest = Struct.new(:hostname, keyword_init: true) unless defined? MockRequest
end
test 'cualquier subdominio que empiece con api. matchea' do
request = MockRequest.new hostname: 'api.'
(rand * 10).to_i.times do
request.hostname += "#{SecureRandom.hex}."
assert @constraint.matches?(request)
end
end
test 'cualquier subdominio que no empiece con api. matchea' do
request = MockRequest.new hostname: 'panel.'
(rand * 10).to_i.times do
request.hostname += "#{SecureRandom.hex}."
assert_not @constraint.matches?(request)
end
end
end