microsoft_kiota_abstractions 0.25.3 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86e29962236a43fe36f9606ce411217392788b49899ba76c53100aa109b0fd69
4
- data.tar.gz: a508765b80eba3cc0ea4143cf9d5cc76cd960a1b0340498b862eab12b0efe683
3
+ metadata.gz: 6c50ee601efebfe772b5db15f70dab16639280ceff867bf6c3738d1efe32fe8c
4
+ data.tar.gz: 6c836c49bd80738c93ac3b11274979b1036490d9f86ea955a9656988f859c66e
5
5
  SHA512:
6
- metadata.gz: 19e2eb208ceeac2a34a7977b47af90348e6a8c4818e40f01da2adc2c82219cb88bd29fbcd7711c650a7f4f0f8ff2487a41464fa34cac6f48ffeb928f613c639f
7
- data.tar.gz: a0e5573e8f792325c3403ccfd523d694228540a615fed49054201903658ea53c1a76ba8d6b151b4e69904985e07f1aeb7952fba15dbef2297595c18f46970278
6
+ metadata.gz: 2480624018e4c17ddb67b0d8c11ff781c9385ce976e8a9ae1fc6ad03c06d25da9aec3d3c426f8f21302e27b81cdc75983277bb3a92b70fd83c2f7282bf48884d
7
+ data.tar.gz: e475b25ed724dc7ff768c646b593e248cf90628333420879c6c1dbcdfb430e2485bd5b793c61a1d06bbc02d4132a5d98eadc91d3a835210090c43586d6a4edef
@@ -4,32 +4,63 @@ require 'uri'
4
4
 
5
5
  module MicrosoftKiotaAbstractions
6
6
  # Maintains a list of valid hosts and allows authentication providers to check whether
7
- # a host is valid before authenticating a request
7
+ # a host is valid before authenticating a request.
8
+ #
9
+ # @note Passing +nil+ or an empty collection explicitly enables allow-all semantics for HTTPS hosts,
10
+ # disabling host restriction checks.
8
11
  class AllowedHostsValidator
9
12
  LOCALHOST_STRINGS = ['localhost', '::1', '[::1]', '127.0.0.1'].freeze
10
13
 
11
- # creates a new AllocatedHostsValidator with provided values
14
+ # creates a new AllowedHostsValidator with provided values
15
+ #
16
+ # @param allowed_hosts [Enumerable, nil] collection of valid hosts. If nil or empty, allow-all semantics are enabled.
12
17
  def initialize(allowed_hosts)
13
18
  self.allowed_hosts = allowed_hosts
14
19
  end
15
20
 
16
21
  # sets the list of valid hosts with provided value (val)
22
+ #
23
+ # @note Passing +nil+ or an empty collection explicitly enables allow-all semantics for HTTPS hosts,
24
+ # disabling host restriction checks.
25
+ # @param val [Enumerable, nil] collection of valid hosts.
17
26
  def allowed_hosts=(val)
27
+ if val.nil?
28
+ @allowed_hosts = {}
29
+ return
30
+ end
31
+
32
+ raise ArgumentError, 'allowed_hosts cannot be a string' if val.is_a?(String)
33
+ raise ArgumentError, 'allowed_hosts must be an Enumerable collection or nil' unless val.respond_to?(:each)
34
+
35
+ elements = val.to_a
36
+ if elements.empty?
37
+ @allowed_hosts = {}
38
+ return
39
+ end
40
+
18
41
  hosts = {}
19
- val.each do |host|
20
- raise ArgumentError, "host should not contain http or https prefix: #{host}" if host.match?(%r{\Ahttps?://}i)
42
+ elements.each do |host|
43
+ next if host.nil?
21
44
 
22
- hosts[host.downcase] = true
45
+ cleaned = host.to_s.strip
46
+ next if cleaned.empty?
47
+
48
+ raise ArgumentError, "host should not contain http or https prefix: #{cleaned}" if cleaned.match?(%r{\Ahttps?://}i)
49
+
50
+ hosts[cleaned.downcase] = true
23
51
  end
52
+
53
+ raise ArgumentError, 'allowed_hosts must contain at least one valid host when provided as a non-empty list' if hosts.empty?
54
+
24
55
  @allowed_hosts = hosts
25
56
  end
26
57
 
27
58
  # checks whether the provided host is valid
28
59
  def url_host_valid?(url)
29
- return false if url.nil?
60
+ return false if url.nil? || (url.respond_to?(:empty?) && url.empty?)
30
61
 
31
62
  begin
32
- parsed_url = URI(url)
63
+ parsed_url = URI(url.respond_to?(:strip) ? url.strip : url)
33
64
  rescue URI::InvalidURIError, ArgumentError
34
65
  return false
35
66
  end
@@ -21,15 +21,15 @@ module MicrosoftKiotaAbstractions
21
21
  end
22
22
 
23
23
  def get_parse_node(content_type, content)
24
- raise StandardError, 'content type cannot be undefined or empty' unless content_type
25
- raise StandardError, 'content cannot be undefined or empty' unless content
24
+ raise ArgumentError, 'content type cannot be undefined or empty' if content_type.nil? || content_type.strip.empty?
25
+ raise ArgumentError, 'content cannot be undefined or empty' if content.nil? || (content.respond_to?(:empty?) && content.empty?)
26
26
 
27
- vendor_specific_content_type = content_type.split(';').first
28
- factory = @content_type_associated_factories[vendor_specific_content_type]
27
+ vendor_specific_content_type = content_type.split(';').first.strip
28
+ factory = content_type_associated_factories[vendor_specific_content_type]
29
29
  return factory.get_parse_node(vendor_specific_content_type, content) if factory
30
30
 
31
31
  clean_content_type = get_clean_content_type(vendor_specific_content_type)
32
- factory = @content_type_associated_factories[clean_content_type]
32
+ factory = content_type_associated_factories[clean_content_type]
33
33
  return factory.get_parse_node(clean_content_type, content) if factory
34
34
 
35
35
  raise StandardError, "Content type #{content_type} does not have a factory to be parsed"
@@ -21,14 +21,14 @@ module MicrosoftKiotaAbstractions
21
21
  end
22
22
 
23
23
  def get_serialization_writer(content_type)
24
- raise StandardError, 'content type cannot be undefined or empty' unless content_type
24
+ raise ArgumentError, 'content type cannot be undefined or empty' if content_type.nil? || content_type.strip.empty?
25
25
 
26
- vendor_specific_content_type = content_type.split(';').first
27
- factory = @content_type_associated_factories[vendor_specific_content_type]
26
+ vendor_specific_content_type = content_type.split(';').first.strip
27
+ factory = content_type_associated_factories[vendor_specific_content_type]
28
28
  return factory.get_serialization_writer(vendor_specific_content_type) if factory
29
29
 
30
30
  clean_content_type = get_clean_content_type(vendor_specific_content_type)
31
- factory = @content_type_associated_factories[clean_content_type]
31
+ factory = content_type_associated_factories[clean_content_type]
32
32
  return factory.get_serialization_writer(clean_content_type) if factory
33
33
 
34
34
  raise StandardError, "Content type #{content_type} does not have a factory to be serialized"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MicrosoftKiotaAbstractions
4
- VERSION = '0.25.3' # x-release-please-version
4
+ VERSION = '0.26.0' # x-release-please-version
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: microsoft_kiota_abstractions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.3
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Microsoft Corporation