Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def url_host_valid?(url)

return false unless parsed_url.is_a?(URI::HTTPS)

@allowed_hosts.key? parsed_url.host.downcase
hostname = parsed_url.host.downcase
return true if @allowed_hosts.key? hostname

@allowed_hosts.any? { |allowed_host, _| allowed_host.start_with?('.') && hostname.end_with?(allowed_host) }
rescue URI::InvalidURIError
false
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,31 @@
expect(url6).to eq(false)
end

it 'returns true for subdomain matching allowed suffix' do
ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['.fabric.microsoft.com'])

expect(ahv.url_host_valid?('https://abc.123.graphql.fabric.microsoft.com/path')).to eq(true)
end

it 'returns false for bare domain when allowed as suffix' do
ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['.fabric.microsoft.com'])

expect(ahv.url_host_valid?('https://fabric.microsoft.com/path')).to eq(false)
end

it 'matches suffix hosts case-insensitively' do
ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['.Fabric.Microsoft.COM'])

expect(ahv.url_host_valid?('https://ABC.z2c.graphql.fabric.microsoft.com/path')).to eq(true)
end

it 'allows suffix-based hosts after update' do
ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['example.com'])
ahv.allowed_hosts = ['.fabric.microsoft.com']

expect(ahv.url_host_valid?('https://abc.123.graphql.fabric.microsoft.com/path')).to eq(true)
end

it 'tests the default instance for ParseNodeFactoryRegistry is set' do
expect(MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance).to_not be_nil
end
Expand Down