ie_iframe_cookies 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ group :dev do # not development <-> would add unneeded development dependencies in gemspec
4
+ gem 'rails', '~>2'
5
+ gem 'redgreen'
6
+ gem 'rake'
7
+ gem 'jeweler'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (2.3.14)
5
+ actionpack (= 2.3.14)
6
+ actionpack (2.3.14)
7
+ activesupport (= 2.3.14)
8
+ rack (~> 1.1.0)
9
+ activerecord (2.3.14)
10
+ activesupport (= 2.3.14)
11
+ activeresource (2.3.14)
12
+ activesupport (= 2.3.14)
13
+ activesupport (2.3.14)
14
+ git (1.2.5)
15
+ jeweler (1.6.4)
16
+ bundler (~> 1.0)
17
+ git (>= 1.2.5)
18
+ rake
19
+ rack (1.1.2)
20
+ rails (2.3.14)
21
+ actionmailer (= 2.3.14)
22
+ actionpack (= 2.3.14)
23
+ activerecord (= 2.3.14)
24
+ activeresource (= 2.3.14)
25
+ activesupport (= 2.3.14)
26
+ rake (>= 0.8.3)
27
+ rake (0.9.2)
28
+ redgreen (1.2.2)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ jeweler
35
+ rails (~> 2)
36
+ rake
37
+ redgreen
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rake/testtask'
2
+ Rake::TestTask.new(:default) do |test|
3
+ test.libs << 'lib'
4
+ test.pattern = 'test/**/*_test.rb'
5
+ test.verbose = true
6
+ end
7
+
8
+ begin
9
+ require 'jeweler'
10
+ Jeweler::Tasks.new do |gem|
11
+ gem.name = 'ie_iframe_cookies'
12
+ gem.summary = "Rails: Enabled cookies inside IFrames for IE via p3p headers"
13
+ gem.email = "michael@grosser.it"
14
+ gem.homepage = "http://github.com/grosser/#{gem.name}"
15
+ gem.authors = ["Michael Grosser"]
16
+ end
17
+
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
21
+ end
data/Readme.md ADDED
@@ -0,0 +1,29 @@
1
+ Rails: Enabled cookies inside IFrames for IE via P3P headers.<br/>
2
+
3
+ IFrames in IE only get the same cookies as normal pages when P3P headers are added<br/>
4
+ => 'iframe-using' IE users get P3P headers on every request<br/>
5
+ 304 Not modified pages do not get P3P headers (via ETag)<br/>
6
+ => 'iframe-using' IE users do not get 304
7
+
8
+ Install
9
+ =======
10
+ sudo gem install ie_iframe_cookies
11
+ Or
12
+
13
+ rails plugin install git://github.com/grosser/ie_iframe_cookies.git
14
+
15
+
16
+ Usage
17
+ =====
18
+ To cookie-tag users as 'iframe-using', add this to all actions rendered inside IFrames.<br/>
19
+ (only IE users are tagged)
20
+
21
+ before_filter :normal_cookies_for_ie_in_iframes! # :only => [:foo, :bar]
22
+
23
+ Authors
24
+ =======
25
+ [Sascha Depold](https://github.com/sdepold)
26
+
27
+ [Michael Grosser](http://grosser.it)<br/>
28
+ michael@grosser.it<br/>
29
+ Hereby placed under public domain, do what you want, just do not hold me accountable...
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,40 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ie_iframe_cookies}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Michael Grosser"]
12
+ s.date = %q{2011-09-08}
13
+ s.email = %q{michael@grosser.it}
14
+ s.files = [
15
+ "Gemfile",
16
+ "Gemfile.lock",
17
+ "Rakefile",
18
+ "Readme.md",
19
+ "VERSION",
20
+ "ie_iframe_cookies.gemspec",
21
+ "init.rb",
22
+ "lib/ie_iframe_cookies.rb",
23
+ "test/ie_iframe_cookies_test.rb",
24
+ "test/test_helper.rb"
25
+ ]
26
+ s.homepage = %q{http://github.com/grosser/ie_iframe_cookies}
27
+ s.require_paths = ["lib"]
28
+ s.rubygems_version = %q{1.6.2}
29
+ s.summary = %q{Rails: Enabled cookies inside IFrames for IE via p3p headers}
30
+
31
+ if s.respond_to? :specification_version then
32
+ s.specification_version = 3
33
+
34
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
35
+ else
36
+ end
37
+ else
38
+ end
39
+ end
40
+
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'ie_iframe_cookies'
@@ -0,0 +1,40 @@
1
+ class IEIframeCookies
2
+ VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
3
+ end
4
+
5
+ module ActionController
6
+ class Base
7
+ before_filter :normal_cookies_for_ie_in_iframes
8
+
9
+ def normal_cookies_for_ie_in_iframes!
10
+ if request.ie_iframe_cookies_browser_is_ie?
11
+ normal_cookies_for_ie_in_iframes(:force => true)
12
+ cookies["using_iframes_in_ie"] = true
13
+ end
14
+ end
15
+
16
+ def normal_cookies_for_ie_in_iframes(options={})
17
+ headers['P3P'] = 'CP="ALL DSP COR CURa ADMa DEVa OUR IND COM NAV"' if request.normal_cookies_for_ie_in_iframes? or options[:force]
18
+ end
19
+ end
20
+
21
+ class Request
22
+ def ie_iframe_cookies_browser_is_ie?
23
+ (env['HTTP_USER_AGENT'] || "").include?("MSIE")
24
+ end
25
+
26
+ def normal_cookies_for_ie_in_iframes?
27
+ ie_iframe_cookies_browser_is_ie? and cookies["using_iframes_in_ie"]
28
+ end
29
+
30
+ alias_method :etag_matches_without_ie_iframe_cookies?, :etag_matches?
31
+ def etag_matches?(*args)
32
+ not normal_cookies_for_ie_in_iframes? and etag_matches_without_ie_iframe_cookies?(*args)
33
+ end
34
+
35
+ alias_method :not_modified_without_ie_iframe_cookies?, :not_modified?
36
+ def not_modified?(*args)
37
+ not normal_cookies_for_ie_in_iframes? and not_modified_without_ie_iframe_cookies?(*args)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,142 @@
1
+ require 'test/test_helper'
2
+
3
+ class IETestController < ActionController::Base
4
+ before_filter :normal_cookies_for_ie_in_iframes!, :only => :activate
5
+
6
+ def activate
7
+ render :text => 'OK'
8
+ end
9
+
10
+ def visit
11
+ render :text => 'OK'
12
+ end
13
+
14
+ def with_etag
15
+ if stale?(:etag => 'foo')
16
+ render :text => 'OK'
17
+ end
18
+ end
19
+
20
+ def with_modified
21
+ if stale?(:last_modified => 1.minute.ago)
22
+ render :text => 'OK'
23
+ end
24
+ end
25
+ end
26
+
27
+ class IEIFrameCookiesTest < ActionController::TestCase
28
+ def setup
29
+ @controller = IETestController.new
30
+ @request = ActionController::TestRequest.new
31
+ @response = ActionController::TestResponse.new
32
+ end
33
+
34
+ def is_ok!
35
+ assert_equal 'OK', @response.body
36
+ assert_equal 200, @response.status.to_i
37
+ end
38
+
39
+ def is_not_modified!
40
+ assert_equal 304, @response.status.to_i
41
+ end
42
+
43
+ def set_ie
44
+ @request.env['HTTP_USER_AGENT'] = 'Mr. MSIE is coming...'
45
+ end
46
+
47
+ def set_tracked
48
+ @request.cookies['using_iframes_in_ie'] = 'true'
49
+ end
50
+
51
+ def set_etag
52
+ @request.env['HTTP_IF_NONE_MATCH'] = '"acbd18db4cc2f85cedef654fccc4a4d8"'
53
+ end
54
+
55
+ def set_modified(time)
56
+ @request.env['HTTP_IF_MODIFIED_SINCE'] = time.rfc2822
57
+ end
58
+
59
+ test "it has a VERSION" do
60
+ assert_match /^\d+\.\d+\.\d+$/, IEIframeCookies::VERSION
61
+ end
62
+
63
+ # adding tracking cookie
64
+ test "it sets tracking cookie for IE users" do
65
+ set_ie
66
+ get :activate
67
+ is_ok!
68
+ assert_equal "true", cookies['using_iframes_in_ie']
69
+ end
70
+
71
+ test "does not set tracking cookie for nice users" do
72
+ get :activate
73
+ is_ok!
74
+ assert_equal nil, cookies['using_iframes_in_ie']
75
+ end
76
+
77
+ # returning P3P headers
78
+ test "it adds P3P headers for tracked IE users" do
79
+ set_tracked
80
+ set_ie
81
+ get :visit
82
+ is_ok!
83
+ assert_equal 'CP="ALL DSP COR CURa ADMa DEVa OUR IND COM NAV"', @response.headers['P3P']
84
+ end
85
+
86
+ test "it does not add P3P headers for un-tracked IE users" do
87
+ set_ie
88
+ get :visit
89
+ is_ok!
90
+ assert_equal nil, @response.headers['P3P']
91
+ end
92
+
93
+ test "it does not add P3P headers for tracked nice users" do
94
+ set_tracked
95
+ get :visit
96
+ is_ok!
97
+ assert_equal nil, @response.headers['P3P']
98
+ end
99
+
100
+ # disable ETags 304
101
+ test "is not modified for tracked nice users" do
102
+ set_etag
103
+ set_tracked
104
+ get :with_etag
105
+ is_not_modified!
106
+ end
107
+
108
+ test "is not modified for un-tracked ie users" do
109
+ set_etag
110
+ set_tracked
111
+ get :with_etag
112
+ is_not_modified!
113
+ end
114
+
115
+ test "is modified for tracked ie users" do
116
+ set_etag
117
+ set_tracked
118
+ set_ie
119
+ get :with_etag
120
+ is_ok!
121
+ end
122
+
123
+ test "is not modified via modified since" do
124
+ set_modified(0.minutes.ago)
125
+ get :with_modified
126
+ is_not_modified!
127
+ end
128
+
129
+ test "is modified via modified since" do
130
+ set_modified(2.minutes.ago)
131
+ get :with_modified
132
+ is_ok!
133
+ end
134
+
135
+ test "is modified via modified since for tracked ie users" do
136
+ set_tracked
137
+ set_ie
138
+ set_modified(0.minutes.ago)
139
+ get :with_modified
140
+ is_ok!
141
+ end
142
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'action_pack'
3
+ require 'action_controller'
4
+ require 'action_controller/test_process'
5
+ require 'test/unit'
6
+ require 'redgreen' rescue nil
7
+
8
+ $LOAD_PATH << 'lib'
9
+
10
+ # fake rails env for initialisation
11
+ # when Rails is defined, backtrace_cleaner is used, when assert fails
12
+ RAILS_ENV='development'
13
+
14
+ ActionController::Routing::Routes.reload
15
+
16
+ require "init"
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ie_iframe_cookies
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Michael Grosser
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-08 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: michael@grosser.it
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - Gemfile
32
+ - Gemfile.lock
33
+ - Rakefile
34
+ - Readme.md
35
+ - VERSION
36
+ - ie_iframe_cookies.gemspec
37
+ - init.rb
38
+ - lib/ie_iframe_cookies.rb
39
+ - test/ie_iframe_cookies_test.rb
40
+ - test/test_helper.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/grosser/ie_iframe_cookies
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.6.2
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: "Rails: Enabled cookies inside IFrames for IE via p3p headers"
75
+ test_files: []
76
+