cookie_cutter 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,15 +4,17 @@ module CookieCutter
4
4
  module Cookie
5
5
  module ClassMethods
6
6
  def find(request)
7
- new(request.cookie_jar)
7
+ new(request.cookie_jar, secure_request: request.scheme == 'https')
8
8
  end
9
9
 
10
10
  attr_reader :cookie_name
11
+
11
12
  def store_as(name)
12
13
  @cookie_name = name
13
14
  end
14
15
 
15
16
  attr_reader :cookie_domain
17
+
16
18
  def domain(domain_value)
17
19
  @cookie_domain = domain_value
18
20
  add_handler do |cookie|
@@ -21,6 +23,7 @@ module CookieCutter
21
23
  end
22
24
 
23
25
  attr_reader :cookie_lifetime
26
+
24
27
  def lifetime(seconds)
25
28
  @cookie_lifetime = seconds
26
29
  add_handler do |cookie|
@@ -36,7 +39,9 @@ module CookieCutter
36
39
  def secure_requests_only
37
40
  @secure = true
38
41
  add_handler do |cookie|
39
- cookie[:secure] = true
42
+ if cookie[:secure_request]
43
+ cookie[:secure] = true
44
+ end
40
45
  end
41
46
  end
42
47
 
@@ -50,11 +55,13 @@ module CookieCutter
50
55
  cookie[:httponly] = true
51
56
  end
52
57
  end
58
+
53
59
  alias_method :httponly, :http_only
54
60
 
55
61
  def http_only?
56
62
  @http_only ? true : false
57
63
  end
64
+
58
65
  alias_method :httponly?, :http_only?
59
66
 
60
67
  def has_attribute(attribute_name, options={})
@@ -96,8 +103,13 @@ module CookieCutter
96
103
  klass.extend ClassMethods
97
104
  end
98
105
 
99
- def initialize(cookie_jar)
106
+ def initialize(cookie_jar, options={})
100
107
  @cookie_jar = cookie_jar
108
+ @secure_request = options[:secure_request]
109
+ end
110
+
111
+ def secure_request?
112
+ @secure_request.nil? ? true : @secure_request
101
113
  end
102
114
 
103
115
  def value
@@ -109,7 +121,7 @@ module CookieCutter
109
121
  end
110
122
 
111
123
  def value=(val)
112
- cookie = { value: val }
124
+ cookie = {value: val, secure_request: secure_request?}
113
125
  self.class.add_options(cookie)
114
126
  @cookie_jar[cookie_name] = cookie
115
127
  end
@@ -1,3 +1,3 @@
1
1
  module CookieCutter
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
data/spec/base_spec.rb CHANGED
@@ -91,10 +91,23 @@ describe CookieCutter::Base do
91
91
  store_as :cwsro
92
92
  secure_requests_only
93
93
  end
94
- cookie = CookieWithSecureRequestsOnly.new(cookie_jar)
94
+ options = { secure_request: true }
95
+ cookie = CookieWithSecureRequestsOnly.new(cookie_jar, options)
95
96
  cookie.value = "my value"
96
97
  cookie_jar.metadata_for(:cwsro)[:secure].should be_true
97
98
  end
99
+
100
+ it 'ignores secure_requests_only if set from non-secure url scheme' do
101
+ class CookieWithSecureRequestsOnly < CookieCutter::Base
102
+ store_as :cwsro
103
+ secure_requests_only
104
+ end
105
+ options = { secure_request: false }
106
+ cookie = CookieWithSecureRequestsOnly.new(cookie_jar, options)
107
+ cookie.value = "my value"
108
+ cookie_jar.metadata_for(:cwsro)[:secure].should be_nil
109
+ end
110
+
98
111
  end
99
112
  describe 'http_only' do
100
113
  it 'defaults to being accessible to client scripts (i.e. not http_only)' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookie_cutter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-03 00:00:00.000000000 Z
13
+ date: 2013-06-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -96,21 +96,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
96
  - - ! '>='
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
- segments:
100
- - 0
101
- hash: 2629765522304587425
102
99
  required_rubygems_version: !ruby/object:Gem::Requirement
103
100
  none: false
104
101
  requirements:
105
102
  - - ! '>='
106
103
  - !ruby/object:Gem::Version
107
104
  version: '0'
108
- segments:
109
- - 0
110
- hash: 2629765522304587425
111
105
  requirements: []
112
106
  rubyforge_project:
113
- rubygems_version: 1.8.24
107
+ rubygems_version: 1.8.25
114
108
  signing_key:
115
109
  specification_version: 3
116
110
  summary: Provides a way to define the structure, lifetime, and other properties of