microsoft_kiota_abstractions 0.25.1 → 0.25.2

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: 2ba7ddf7b17643a875b6f49757bea1ec1cbd4482beeeb61b288a714d7469df0b
4
- data.tar.gz: 670faf6e2676386cb879456c7c204e41ebeb14be0b8a0629ea3e23b48587bd87
3
+ metadata.gz: 6ab594b471705d419a392d73fd99f80f2e5b0e2b80ff8fd4ae5fd25ba18aaa37
4
+ data.tar.gz: 6e2fb313b636b5ea1f8ccbec0c45f08cb8f5c74f2d9f8957164777d20f34c1bf
5
5
  SHA512:
6
- metadata.gz: 5cadd848507db4d323827e4d505644d6fdc2bae9b7e1add6008b8d3c73982d6f99527e90c6c3957a41afeec0563f98cebce8c369c5bcf78abcf31aa62a4bec68
7
- data.tar.gz: a9eea3e5bb2ae6ecc37563452433194a4eae524b356e7becea94baae65d3b19a72c46bff7e784b24093ac2e0aa75c1e75a88657309e653c77ceb9b3579c71696
6
+ metadata.gz: 87928b86bc8de81578ccbb7afac4d0c5f76afa2fa2625464a2981b7fc9bb62e918377cecb317faf6d6921c7407fc998bfe8b946e960876bca9c863daf04efd2e
7
+ data.tar.gz: ee398afe305ba8ad89b92eff176e55e9a5d96a16b2e52b21abddf5c3c02aa0c9212dad0cb843b734ed814a99178e88b227232a834e81aa07070c3278496a3ae8
@@ -6,6 +6,8 @@ module MicrosoftKiotaAbstractions
6
6
  # Maintains a list of valid hosts and allows authentication providers to check whether
7
7
  # a host is valid before authenticating a request
8
8
  class AllowedHostsValidator
9
+ LOCALHOST_STRINGS = ['localhost', '::1', '[::1]', '127.0.0.1'].freeze
10
+
9
11
  # creates a new AllocatedHostsValidator with provided values
10
12
  def initialize(allowed_hosts)
11
13
  self.allowed_hosts = allowed_hosts
@@ -24,19 +26,45 @@ module MicrosoftKiotaAbstractions
24
26
 
25
27
  # checks whether the provided host is valid
26
28
  def url_host_valid?(url)
27
- return true if @allowed_hosts.empty?
29
+ return false if url.nil?
30
+
31
+ begin
32
+ parsed_url = URI(url)
33
+ rescue URI::InvalidURIError, ArgumentError
34
+ return false
35
+ end
28
36
 
29
- parsed_url = URI(url)
30
37
  return false if parsed_url.host.nil?
31
38
 
32
- return false unless parsed_url.is_a?(URI::HTTPS)
39
+ is_https = parsed_url.is_a?(URI::HTTPS)
40
+ is_http_localhost = parsed_url.is_a?(URI::HTTP) && localhost?(parsed_url)
41
+ return false unless is_https || is_http_localhost
42
+
43
+ return true if @allowed_hosts.empty?
44
+
45
+ host = parsed_url.host.downcase
46
+ return true if @allowed_hosts.key?(host)
33
47
 
34
- hostname = parsed_url.host.downcase
35
- return true if @allowed_hosts.key? hostname
48
+ stripped_host = host.delete_prefix('[').delete_suffix(']')
49
+ return true if @allowed_hosts.key?(stripped_host)
50
+
51
+ hostname = (parsed_url.hostname || host).downcase
52
+ return true if @allowed_hosts.key?(hostname)
36
53
 
37
54
  @allowed_hosts.any? { |allowed_host, _| allowed_host.start_with?('.') && hostname.end_with?(allowed_host) }
38
- rescue URI::InvalidURIError
39
- false
55
+ end
56
+
57
+ # checks whether the host in the parsed url is a loopback/localhost address
58
+ def localhost?(parsed_url)
59
+ host = parsed_url.host
60
+ return false if host.nil?
61
+
62
+ return true if LOCALHOST_STRINGS.include?(host.downcase)
63
+
64
+ hostname = parsed_url.hostname
65
+ return false if hostname.nil?
66
+
67
+ LOCALHOST_STRINGS.include?(hostname.downcase)
40
68
  end
41
69
 
42
70
  # gets the list of valid hosts
@@ -24,7 +24,8 @@ module MicrosoftKiotaAbstractions
24
24
  end
25
25
  else
26
26
  Fiber.new do
27
- token = @access_token_provider.get_authorization_token(request.uri, additional_properties).resume
27
+ auth_fiber = @access_token_provider.get_authorization_token(request.uri, additional_properties)
28
+ token = auth_fiber.resume if auth_fiber
28
29
  request.headers.add(AUTHORIZATION_HEADER_KEY, "Bearer #{token}") unless token.nil? || token.empty?
29
30
  end
30
31
  end
@@ -127,8 +127,6 @@ module MicrosoftKiotaAbstractions
127
127
  writer.write_object_value(nil, values)
128
128
  end
129
129
  @content = writer.get_serialized_content
130
- rescue StandardError
131
- raise StandardError, 'could not serialize payload'
132
130
  end
133
131
 
134
132
  def add_headers_from_raw_object(h)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MicrosoftKiotaAbstractions
4
- VERSION = '0.25.1' # x-release-please-version
4
+ VERSION = '0.25.2' # 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.1
4
+ version: 0.25.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Microsoft Corporation