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 +4 -4
- data/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb +38 -7
- data/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb +5 -5
- data/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb +4 -4
- 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: 6c50ee601efebfe772b5db15f70dab16639280ceff867bf6c3738d1efe32fe8c
|
|
4
|
+
data.tar.gz: 6c836c49bd80738c93ac3b11274979b1036490d9f86ea955a9656988f859c66e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
-
|
|
20
|
-
|
|
42
|
+
elements.each do |host|
|
|
43
|
+
next if host.nil?
|
|
21
44
|
|
|
22
|
-
|
|
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
|
|
25
|
-
raise
|
|
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 =
|
|
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 =
|
|
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"
|
data/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb
CHANGED
|
@@ -21,14 +21,14 @@ module MicrosoftKiotaAbstractions
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def get_serialization_writer(content_type)
|
|
24
|
-
raise
|
|
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 =
|
|
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 =
|
|
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"
|