Class: SiteInspector::Endpoint::Cookies

Inherits:
Check
  • Object
show all
Defined in:
lib/site-inspector/checks/cookies.rb

Instance Attribute Summary

Attributes inherited from Check

#endpoint

Instance Method Summary collapse

Methods inherited from Check

enabled=, enabled?, #host, #initialize, #inspect, #name, name, #request, #response

Constructor Details

This class inherits a constructor from SiteInspector::Endpoint::Check

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/site-inspector/checks/cookies.rb', line 21

def [](key)
  all.find { |cookie| cookie.keys.first == key } if cookies?
end

#allObject



17
18
19
# File 'lib/site-inspector/checks/cookies.rb', line 17

def all
  @cookies ||= cookie_header.map { |c| CGI::Cookie.parse(c) } if cookies?
end

#any?(&block) ⇒ Boolean Also known as: cookies?



6
7
8
9
10
11
12
13
14
# File 'lib/site-inspector/checks/cookies.rb', line 6

def any?(&block)
  if cookie_header.nil? || cookie_header.empty?
    false
  elsif block_given?
    all.any?(&block)
  else
    true
  end
end

#secure?Boolean



25
26
27
28
# File 'lib/site-inspector/checks/cookies.rb', line 25

def secure?
  pairs = cookie_header.join('; ').split('; ') # CGI::Cookies#Parse doesn't seem to like secure headers
  pairs.any? { |c| c.casecmp('secure').zero? } && pairs.any? { |c| c.casecmp('httponly').zero? }
end

#to_hObject



30
31
32
33
34
35
# File 'lib/site-inspector/checks/cookies.rb', line 30

def to_h
  {
    cookie?: any?,
    secure?: secure?
  }
end