Class: SiteInspector::Endpoint::Cookies
- Inherits:
-
Check
- Object
- Check
- SiteInspector::Endpoint::Cookies
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
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
|
#all ⇒ Object
17
18
19
|
# File 'lib/site-inspector/checks/cookies.rb', line 17
def all
@cookies ||= .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 .nil? || .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 = .join('; ').split('; ')
pairs.any? { |c| c.casecmp('secure').zero? } && pairs.any? { |c| c.casecmp('httponly').zero? }
end
|
#to_h ⇒ Object
30
31
32
33
34
35
|
# File 'lib/site-inspector/checks/cookies.rb', line 30
def to_h
{
cookie?: any?,
secure?: secure?
}
end
|