safe_cookies 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/safe_cookies.rb CHANGED
@@ -21,6 +21,8 @@ module SafeCookies
21
21
  # The :non_http_only option is analog, use it for storing data you want to access
22
22
  # with javascript.
23
23
 
24
+ options = options.dup
25
+
24
26
  @app = app
25
27
  @non_secure = (options.delete(:non_secure) || []).map(&:to_s)
26
28
  @non_http_only = (options.delete(:non_http_only) || []).map(&:to_s)
@@ -1,3 +1,3 @@
1
1
  module SafeCookies
2
- VERSION = "0.1.1"
2
+ VERSION = '0.1.2'
3
3
  end
@@ -30,7 +30,7 @@ describe SafeCookies::Middleware do
30
30
  # second request: do not rewrite cookie again
31
31
  subject = described_class.new(app, :foo => 24 * 60 * 60)
32
32
  app.should_receive(:call).and_return([ stub, {}, stub ])
33
- received_cookies = headers['Set-Cookie'].scan(/[^,;]+=[^,;]+(?=;\s)/i) # extract cookies
33
+ received_cookies = headers['Set-Cookie'].scan(/[^\n;]+=[^\n;]+(?=;\s)/i) # extract cookies
34
34
  env['HTTP_COOKIE'] = received_cookies.join(',')
35
35
 
36
36
  code, headers, response = subject.call(env)
@@ -42,14 +42,14 @@ describe SafeCookies::Middleware do
42
42
  app.should_receive(:call).and_return([ stub, { 'Set-Cookie' => 'neuer_cookie=neuer_cookie_wert'}, stub ])
43
43
 
44
44
  code, headers, response = subject.call(env)
45
- headers['Set-Cookie'].should =~ /neuer_cookie=neuer_cookie_wert;[^\n]* secure/
45
+ headers['Set-Cookie'].should =~ /neuer_cookie=neuer_cookie_wert;.* secure/
46
46
  end
47
47
 
48
48
  it "should make new cookies http_only" do
49
49
  app.should_receive(:call).and_return([ stub, { 'Set-Cookie' => 'neuer_cookie=neuer_cookie_wert'}, stub ])
50
50
 
51
51
  code, headers, response = subject.call(env)
52
- headers['Set-Cookie'].should =~ /neuer_cookie=neuer_cookie_wert;[^\n]* HttpOnly/
52
+ headers['Set-Cookie'].should =~ /neuer_cookie=neuer_cookie_wert;.* HttpOnly/
53
53
  end
54
54
 
55
55
  it "should not make new cookies secure that are specified as 'non_secure'" do
@@ -85,8 +85,8 @@ describe SafeCookies::Middleware do
85
85
 
86
86
  code, headers, response = subject.call(env)
87
87
  set_cookie = headers['Set-Cookie'].gsub(/,(?=\s\d)/, '') # remove commas in expiry dates to simplify matching below
88
- set_cookie.should =~ /filter=cars_only;[^,]* HttpOnly/
89
- set_cookie.should_not match(/filter=cars_only;[^,]* secure/)
88
+ set_cookie.should =~ /filter=cars_only;.* HttpOnly/
89
+ set_cookie.should_not match(/filter=cars_only;.* secure/)
90
90
  end
91
91
 
92
92
  it "should not make existing cookies http_only that are specified as 'non_http_only'" do
@@ -95,9 +95,9 @@ describe SafeCookies::Middleware do
95
95
  env['HTTP_COOKIE'] = 'js_data=json'
96
96
 
97
97
  code, headers, response = subject.call(env)
98
- set_cookie = headers['Set-Cookie'].gsub(/,(?=\s\d)/, '') # remove commas in expiry dates to simplify matching below
99
- set_cookie.should =~ /js_data=json;[^,]* secure/
100
- set_cookie.should_not match(/js_data=json;[^,]* HttpOnly/)
98
+ set_cookie = headers['Set-Cookie']
99
+ set_cookie.should =~ /js_data=json;.* secure/
100
+ set_cookie.should_not match(/js_data=json;.* HttpOnly/)
101
101
  end
102
102
 
103
103
  it "should not make cookies secure if the request was not secure" do
@@ -110,4 +110,13 @@ describe SafeCookies::Middleware do
110
110
  headers['Set-Cookie'].should_not match(/secure/i)
111
111
  end
112
112
 
113
+ it 'does not mutate an options hash passed to it' do
114
+ options = { :cookie1 => 3600, :non_secure => [:cookie2], :non_http_only => [:cookie3] }
115
+ described_class.new(app, options)
116
+
117
+ options[:cookie1].should == 3600
118
+ options[:non_secure].should == [:cookie2]
119
+ options[:non_http_only].should == [:cookie3]
120
+ end
121
+
113
122
  end
metadata CHANGED
@@ -1,71 +1,75 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: safe_cookies
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
6
11
  platform: ruby
7
- authors:
8
- - Dominik Schöler
12
+ authors:
13
+ - "Dominik Sch\xC3\xB6ler"
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-06-28 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-08-26 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: rack
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
31
36
  name: rspec
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
37
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
38
+ requirement: &id002 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: timecop
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
54
47
  type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: timecop
55
51
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
52
+ requirement: &id003 !ruby/object:Gem::Requirement
57
53
  none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
62
63
  description: Make cookies as `secure` and `HttpOnly` as possible.
63
- email:
64
+ email:
64
65
  - dominik.schoeler@makandra.de
65
66
  executables: []
67
+
66
68
  extensions: []
69
+
67
70
  extra_rdoc_files: []
68
- files:
71
+
72
+ files:
69
73
  - .gitignore
70
74
  - Gemfile
71
75
  - LICENSE
@@ -76,30 +80,40 @@ files:
76
80
  - safe_cookies.gemspec
77
81
  - spec/safe_cookies_spec.rb
78
82
  - spec/spec_helper.rb
83
+ has_rdoc: true
79
84
  homepage: http://www.makandra.de
80
85
  licenses: []
86
+
81
87
  post_install_message:
82
88
  rdoc_options: []
83
- require_paths:
89
+
90
+ require_paths:
84
91
  - lib
85
- required_ruby_version: !ruby/object:Gem::Requirement
92
+ required_ruby_version: !ruby/object:Gem::Requirement
86
93
  none: false
87
- requirements:
88
- - - ! '>='
89
- - !ruby/object:Gem::Version
90
- version: '0'
91
- required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
102
  none: false
93
- requirements:
94
- - - ! '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
97
110
  requirements: []
111
+
98
112
  rubyforge_project:
99
- rubygems_version: 1.8.24
113
+ rubygems_version: 1.3.9.5
100
114
  signing_key:
101
115
  specification_version: 3
102
116
  summary: Make cookies as `secure` and `HttpOnly` as possible.
103
- test_files:
117
+ test_files:
104
118
  - spec/safe_cookies_spec.rb
105
119
  - spec/spec_helper.rb