lib/site-inspector/checks/cookies.rb in site-inspector-3.1.1 vs lib/site-inspector/checks/cookies.rb in site-inspector-3.2.0
- old
+ new
@@ -1,18 +1,20 @@
+# frozen_string_literal: true
+
class SiteInspector
class Endpoint
class Cookies < Check
def any?(&block)
if cookie_header.nil? || cookie_header.empty?
false
elsif block_given?
- all.any? { |cookie| block.call(cookie) }
+ all.any?(&block)
else
true
end
end
- alias_method :cookies?, :any?
+ alias cookies? any?
def all
@cookies ||= cookie_header.map { |c| CGI::Cookie.parse(c) } if cookies?
end
@@ -20,10 +22,10 @@
all.find { |cookie| cookie.keys.first == key } if cookies?
end
def secure?
pairs = cookie_header.join('; ').split('; ') # CGI::Cookies#Parse doesn't seem to like secure headers
- pairs.any? { |c| c.downcase == 'secure' } && pairs.any? { |c| c.downcase == 'httponly' }
+ pairs.any? { |c| c.casecmp('secure').zero? } && pairs.any? { |c| c.casecmp('httponly').zero? }
end
def to_h
{
cookie?: any?,