microsoft_kiota_abstractions 0.25.0 → 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 +4 -4
- data/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb +35 -7
- data/lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb +2 -1
- data/lib/microsoft_kiota_abstractions/request_information.rb +0 -2
- data/lib/microsoft_kiota_abstractions/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6ab594b471705d419a392d73fd99f80f2e5b0e2b80ff8fd4ae5fd25ba18aaa37
|
|
4
|
+
data.tar.gz: 6e2fb313b636b5ea1f8ccbec0c45f08cb8f5c74f2d9f8957164777d20f34c1bf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
35
|
-
return true if @allowed_hosts.key?
|
|
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
|
-
|
|
39
|
-
|
|
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
|
data/lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb
CHANGED
|
@@ -24,7 +24,8 @@ module MicrosoftKiotaAbstractions
|
|
|
24
24
|
end
|
|
25
25
|
else
|
|
26
26
|
Fiber.new do
|
|
27
|
-
|
|
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)
|