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

29 lines
754 B
Ruby

# 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