csp_report 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -13
  3. data/app/controllers/csp_report/csp_reports_controller.rb +11 -3
  4. data/app/models/csp_report/csp_report.rb +2 -0
  5. data/app/views/csp_report/csp_reports/index.html.haml +11 -0
  6. data/config/routes.rb +4 -1
  7. data/db/migrate/20130630091108_create_csp_report_csp_reports.rb +3 -3
  8. data/db/migrate/20130712162922_add_incoming_ip_to_csp_report_csp_reports.rb +13 -0
  9. data/lib/csp_report/version.rb +1 -1
  10. data/lib/generators/csp_report/csp_declaration_generator.rb +23 -0
  11. data/spec/controllers/csp_report/csp_reports_controller_spec.rb +61 -2
  12. data/spec/dummy/config/routes.rb +1 -1
  13. data/spec/dummy/db/development.sqlite3 +0 -0
  14. data/spec/dummy/db/schema.rb +12 -1
  15. data/spec/dummy/db/test.sqlite3 +0 -0
  16. data/spec/dummy/log/development.log +134 -0
  17. data/spec/dummy/log/test.log +11806 -0
  18. data/spec/dummy/tmp/cache/assets/test/sass/745019acb880ec9412f97713489f02ba42209a06/csp_report.css.sassc +0 -0
  19. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  20. data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  21. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  22. data/spec/dummy/tmp/cache/assets/test/sprockets/4949b199f7a3f61704ee406dfc99e38c +0 -0
  23. data/spec/dummy/tmp/cache/assets/test/sprockets/9b94cd42c6d3c0778772d609a4d7006d +0 -0
  24. data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  25. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  26. data/spec/dummy/tmp/cache/assets/test/sprockets/dc4c1ce2dc434402713320ef23981262 +0 -0
  27. data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  28. data/spec/factories/csp_report_csp_reports.rb +16 -8
  29. data/spec/features/csp_report/csp_reports_index_spec.rb +81 -0
  30. data/spec/generators/csp_report/install_generators_spec.rb +35 -5
  31. data/spec/models/csp_report/csp_report_spec.rb +111 -3
  32. data/spec/spec_helper.rb +39 -8
  33. metadata +45 -5
  34. data/lib/tasks/csp_report_tasks.rake +0 -4
  35. data/lib/tasks/install.thor +0 -6
@@ -1,11 +1,19 @@
1
- # Read about factories at https://github.com/thoughtbot/factory_girl
2
-
3
1
  FactoryGirl.define do
4
- factory :csp_report_csp_report, :class => 'CspReport' do
5
- document_uri "MyString"
6
- referrer "MyString"
7
- blocked_uri "MyString"
8
- violated_directive "MyString"
9
- original_policy "MyString"
2
+ factory :local_inline, :class => 'CspReport::CspReport' do
3
+ document_uri "http://localhost:3000"
4
+ referrer ""
5
+ blocked_uri ""
6
+ violated_directive "script-src 'self'"
7
+ original_policy "script-src 'self'; report-uri /csp/csp_reports"
8
+ incoming_ip "127.0.0.1"
9
+ end
10
+
11
+ factory :local_home_index_inline, :class => 'CspReport::CspReport' do
12
+ document_uri "http://localhost:3000/home/index"
13
+ referrer ""
14
+ blocked_uri ""
15
+ violated_directive "script-src 'self'"
16
+ original_policy "script-src 'self'; report-uri /csp/csp_reports"
17
+ incoming_ip "127.0.0.1"
10
18
  end
11
19
  end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'CspReport index view' do
4
+ describe 'Report data headers' do
5
+ before(:each) do
6
+ visit csp_reports_path
7
+ end
8
+
9
+ it 'should display the report id' do
10
+ page.should have_content 'ID'
11
+ end
12
+ it 'should display the report document URI' do
13
+ page.should have_content 'Document URI'
14
+ end
15
+ it 'should display the report referrer' do
16
+ page.should have_content 'Referrer'
17
+ end
18
+ it 'should display the report original policy' do
19
+ page.should have_content 'Server Policy'
20
+ end
21
+ it 'should display the report violated directive' do
22
+ page.should have_content 'Violated Directive'
23
+ end
24
+ it 'should display the report blocked URI' do
25
+ page.should have_content 'Blocked URI'
26
+ end
27
+ it 'should display the report incoming IP' do
28
+ page.should have_content 'Incoming IP'
29
+ end
30
+ it 'should display the report creation timestamp' do
31
+ page.should have_content 'Reported At'
32
+ end
33
+ it 'should display an Actions column' do
34
+ page.should have_content 'Actions'
35
+ end
36
+ end
37
+
38
+ describe 'Report data content' do
39
+ before(:each) do
40
+ @local_inline = FactoryGirl.create(:local_inline)
41
+ visit csp_reports_path
42
+ end
43
+
44
+ it 'should display the report id' do
45
+ page.should have_content @local_inline.id
46
+ end
47
+ it 'should display the report document URI' do
48
+ page.should have_content @local_inline.document_uri
49
+ end
50
+ it 'should display the report referrer' do
51
+ page.should have_content @local_inline.referrer
52
+ end
53
+ it 'should display the report original policy' do
54
+ page.should have_content @local_inline.original_policy
55
+ end
56
+ it 'should display the report violated directive' do
57
+ page.should have_content @local_inline.violated_directive
58
+ end
59
+ it 'should display the report blocked URI' do
60
+ page.should have_content @local_inline.blocked_uri
61
+ end
62
+ it 'should display the report incoming IP' do
63
+ page.should have_content @local_inline.incoming_ip
64
+ end
65
+ it 'should display the report creation timestamp' do
66
+ page.should have_content @local_inline.created_at
67
+ end
68
+ it 'should display a link to delete the report' do
69
+ page.should have_link 'Delete violation',
70
+ {href: csp_report_path(@local_inline.id)}
71
+ end
72
+ end
73
+
74
+ describe 'Delete All functionnality' do
75
+ it 'should make a "delete all" button available' do
76
+ visit csp_reports_path
77
+ page.should have_link "Delete All",
78
+ {href: csp_reports_destroy_all_path}
79
+ end
80
+ end
81
+ end
@@ -1,10 +1,40 @@
1
1
  require 'spec_helper'
2
- require 'rails/generators/base'
3
- require 'generators/csp_report/install_generator'
2
+ require 'genspec'
3
+ require 'fileutils'
4
4
 
5
+ # Can work if we simulate the app repo. need to find a way to have it use
6
+ # the dummy repo
5
7
  module CspReport
6
- describe "InstallGenerator" do
7
- # puts $:
8
- pending "add some tests here"
8
+ describe :"csp_report:install" do
9
+ # The below does not work. Genspec creates a new uniquely named substructure
10
+ # anyway, and therefore needs to create folder and files
11
+ # GenSpec.root=File.expand_path("../../../dummy", __FILE__)
12
+ # within_source_root do
13
+ # FileUtils.mkdir_p "config"
14
+ # FileUtils.touch "config/routes.rb"
15
+ # FileUtils.touch "Rakefile"
16
+ # FileUtils.touch "Gemfile"
17
+ # File.open('Gemfile', 'w') do |f|
18
+ # f.write "gem 'csp_report', path: '~/Documents/Prog/csp_report'"
19
+ # end
20
+ # # Tried to run bundle install... did not work. not sure we have a rails
21
+ # # app in the temp location
22
+ # end
23
+
24
+ # context "with no arguments or options" do
25
+ # # This actually tries to run the generator in a /tmp folder.
26
+ # # thus the preparations above
27
+ # # Not very practical
28
+ # it "should generate successfully" do
29
+ # subject.should generate
30
+ # end
31
+
32
+ # it "should mount the gem in the routes" do
33
+ # # This checks that you call the inject_into_file with exactly this content.
34
+ # # not very practical.
35
+ # subject.should inject_into_file("config/routes.rb",
36
+ # "\n mount CspReport::Engine, at: 'csp'")
37
+ # end
38
+ # end
9
39
  end
10
40
  end
@@ -1,7 +1,115 @@
1
1
  require 'spec_helper'
2
2
 
3
- module CspReport
4
- describe CspReport do
5
- pending "add some examples to (or delete) #{__FILE__}"
3
+ describe CspReport::CspReport do
4
+ before(:each) do
5
+ @unsaved_report = {
6
+ 'document_uri' => "http://localhost:3000/home/index",
7
+ 'referrer' => "",
8
+ 'blocked_uri' => "",
9
+ 'violated_directive' => "script-src 'self'",
10
+ 'original_policy' => "script-src 'self'; report_uri /csp/csp_reports",
11
+ 'incoming_ip' => "127.0.0.1"
12
+ }
13
+
14
+ @unsaved_report_wout_document_uri = {
15
+ 'referrer' => "",
16
+ 'blocked_uri' => "",
17
+ 'violated_directive' => "script-src 'self'",
18
+ 'original_policy' => "script-src 'self'; report_uri /csp/csp_reports",
19
+ 'incoming_ip' => "127.0.0.1"
20
+ }
21
+
22
+ @unsaved_report_wout_violated_directive = {
23
+ 'document_uri' => "http://localhost:3000/home/index",
24
+ 'referrer' => "",
25
+ 'blocked_uri' => "",
26
+ 'original_policy' => "script-src 'self'; report_uri /csp/csp_reports",
27
+ 'incoming_ip' => "127.0.0.1"
28
+ }
29
+
30
+ @unsaved_report_wout_original_policy = {
31
+ 'document_uri' => "http://localhost:3000/home/index",
32
+ 'referrer' => "",
33
+ 'blocked_uri' => "",
34
+ 'violated_directive' => "script-src 'self'",
35
+ 'incoming_ip' => "127.0.0.1"
36
+ }
37
+
38
+ @unsaved_report_wout_incoming_ip = {
39
+ 'document_uri' => "http://localhost:3000/home/index",
40
+ 'referrer' => "",
41
+ 'blocked_uri' => "",
42
+ 'violated_directive' => "script-src 'self'",
43
+ 'original_policy' => "script-src 'self'; report_uri /csp/csp_reports",
44
+ }
45
+
46
+ end
47
+
48
+ describe "pure model" do
49
+ it "should create a rew report when all the mandatory attributes are provided" do
50
+ report = CspReport::CspReport.new(@unsaved_report)
51
+ assert_not_nil report
52
+ end
53
+
54
+ it "should fail to create a report when the document_uri is missing" do
55
+ report = CspReport::CspReport.new(@unsaved_report_wout_document_uri)
56
+ report.should_not be_valid
57
+ end
58
+
59
+ it "should fail to create a report when the violated_directive is missing" do
60
+ report = CspReport::CspReport.new(@unsaved_report_wout_violated_directive)
61
+ report.should_not be_valid
62
+ end
63
+
64
+ it "should fail to create a report when the original_policy is missing" do
65
+ report = CspReport::CspReport.new(@unsaved_report_wout_original_policy)
66
+ report.should_not be_valid
67
+ end
68
+
69
+ it "shoud fail to create a report when the incoming_ip is missing" do
70
+ report = CspReport::CspReport.new(@unsaved_report_wout_incoming_ip)
71
+ report.should_not be_valid
72
+ end
73
+ end
74
+
75
+ describe "active_record" do
76
+ it "should save to the database when all the mandatory attributes are provided" do
77
+ report = CspReport::CspReport.new(@unsaved_report)
78
+ expect {
79
+ report.save!
80
+ }.to change(CspReport::CspReport, :count).by(1)
81
+ end
82
+
83
+ it "should fail to save to the db when the document_uri is missing" do
84
+ report = CspReport::CspReport.new(@unsaved_report_wout_document_uri)
85
+ expect {
86
+ report.save!
87
+ }.to raise_error
88
+ assert_equal 0, CspReport::CspReport.count
89
+ end
90
+
91
+ it "should fail to save to the db when the violated_directive is missing" do
92
+ report = CspReport::CspReport.new(@unsaved_report_wout_violated_directive)
93
+ expect {
94
+ report.save!
95
+ }.to raise_error
96
+ assert_equal 0, CspReport::CspReport.count
97
+ end
98
+
99
+ it "should fail to save to the db when the original_policy is missing" do
100
+ report = CspReport::CspReport.new(@unsaved_report_wout_original_policy)
101
+ expect {
102
+ report.save!
103
+ }.to raise_error
104
+ assert_equal 0, CspReport::CspReport.count
105
+ end
106
+
107
+ it "should fail to save to the db when the incoming_ip is missing" do
108
+ report = CspReport::CspReport.new(@unsaved_report_wout_incoming_ip)
109
+ expect {
110
+ report.save!
111
+ }.to raise_error
112
+ assert_equal 0, CspReport::CspReport.count
113
+ end
6
114
  end
7
115
  end
@@ -1,18 +1,49 @@
1
- ENV['RAILS_ENV'] ||= 'test'
2
-
3
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../dummy/config/environment", __FILE__)
4
4
  require 'rspec/rails'
5
5
  require 'rspec/autorun'
6
- require 'factory_girl_rails'
6
+ require 'factory_girl'
7
+ require 'capybara/rspec'
8
+
9
+ # Requires supporting ruby files with custom matchers and macros, etc,
10
+ # in spec/support/ and its subdirectories.
11
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
7
12
 
8
- Rails.backtrace_cleaner.remove_silencers!
13
+ # Checks for pending migrations before tests are run.
14
+ # If you are not using ActiveRecord, you can remove this line.
15
+ ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
9
16
 
10
- # Load support files
11
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
17
+ FactoryGirl.find_definitions
12
18
 
13
19
  RSpec.configure do |config|
14
- config.mock_with :rspec
20
+ # For engine testing. Makes the Engine routes available to the test files
21
+ config.include CspReport::Engine.routes.url_helpers
22
+
23
+ # ## Mock Framework
24
+ #
25
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
26
+ #
27
+ # config.mock_with :mocha
28
+ # config.mock_with :flexmock
29
+ # config.mock_with :rr
30
+
31
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
32
+ # config.fixture_path = "#{::Rails.root}/spec/fixtures"
33
+
34
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
35
+ # examples within a transaction, remove the following line or assign false
36
+ # instead of true.
15
37
  config.use_transactional_fixtures = true
38
+
39
+ # If true, the base class of anonymous controllers will be inferred
40
+ # automatically. This will be the default behavior in future versions of
41
+ # rspec-rails.
16
42
  config.infer_base_class_for_anonymous_controllers = false
43
+
44
+ # Run specs in random order to surface order dependencies. If you find an
45
+ # order dependency and want to debug it, you can fix the order by providing
46
+ # the seed, which is printed after each run.
47
+ # --seed 1234
17
48
  config.order = "random"
18
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csp_report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Bataille
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-01 00:00:00.000000000 Z
11
+ date: 2013-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ~>
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.4'
125
+ - !ruby/object:Gem::Dependency
126
+ name: genspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 0.2.8
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 0.2.8
125
139
  description: Provide reporting and analysis of your site CSP violations
126
140
  email:
127
141
  - gbataille.dev@gmail.com
@@ -140,12 +154,12 @@ files:
140
154
  - app/views/layouts/csp_report/application.html.erb
141
155
  - config/routes.rb
142
156
  - db/migrate/20130630091108_create_csp_report_csp_reports.rb
157
+ - db/migrate/20130712162922_add_incoming_ip_to_csp_report_csp_reports.rb
143
158
  - lib/csp_report/engine.rb
144
159
  - lib/csp_report/version.rb
145
160
  - lib/csp_report.rb
161
+ - lib/generators/csp_report/csp_declaration_generator.rb
146
162
  - lib/generators/csp_report/install_generator.rb
147
- - lib/tasks/csp_report_tasks.rake
148
- - lib/tasks/install.thor
149
163
  - MIT-LICENSE
150
164
  - Rakefile
151
165
  - README.md
@@ -186,7 +200,18 @@ files:
186
200
  - spec/dummy/public/favicon.ico
187
201
  - spec/dummy/Rakefile
188
202
  - spec/dummy/README.rdoc
203
+ - spec/dummy/tmp/cache/assets/test/sass/745019acb880ec9412f97713489f02ba42209a06/csp_report.css.sassc
204
+ - spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705
205
+ - spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af
206
+ - spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953
207
+ - spec/dummy/tmp/cache/assets/test/sprockets/4949b199f7a3f61704ee406dfc99e38c
208
+ - spec/dummy/tmp/cache/assets/test/sprockets/9b94cd42c6d3c0778772d609a4d7006d
209
+ - spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
210
+ - spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
211
+ - spec/dummy/tmp/cache/assets/test/sprockets/dc4c1ce2dc434402713320ef23981262
212
+ - spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
189
213
  - spec/factories/csp_report_csp_reports.rb
214
+ - spec/features/csp_report/csp_reports_index_spec.rb
190
215
  - spec/generators/csp_report/install_generators_spec.rb
191
216
  - spec/models/csp_report/csp_report_spec.rb
192
217
  - spec/spec_helper.rb
@@ -194,7 +219,11 @@ homepage: http://www.github.com/gbataille/csp_report
194
219
  licenses:
195
220
  - MIT
196
221
  metadata: {}
197
- post_install_message:
222
+ post_install_message: |
223
+ The model changed in v0.2.0. Make sure to run both
224
+ rake csp_report:install:migrations
225
+ rake db:migrate
226
+ after upgrading
198
227
  rdoc_options: []
199
228
  require_paths:
200
229
  - lib
@@ -252,7 +281,18 @@ test_files:
252
281
  - spec/dummy/public/favicon.ico
253
282
  - spec/dummy/Rakefile
254
283
  - spec/dummy/README.rdoc
284
+ - spec/dummy/tmp/cache/assets/test/sass/745019acb880ec9412f97713489f02ba42209a06/csp_report.css.sassc
285
+ - spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705
286
+ - spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af
287
+ - spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953
288
+ - spec/dummy/tmp/cache/assets/test/sprockets/4949b199f7a3f61704ee406dfc99e38c
289
+ - spec/dummy/tmp/cache/assets/test/sprockets/9b94cd42c6d3c0778772d609a4d7006d
290
+ - spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
291
+ - spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
292
+ - spec/dummy/tmp/cache/assets/test/sprockets/dc4c1ce2dc434402713320ef23981262
293
+ - spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
255
294
  - spec/factories/csp_report_csp_reports.rb
295
+ - spec/features/csp_report/csp_reports_index_spec.rb
256
296
  - spec/generators/csp_report/install_generators_spec.rb
257
297
  - spec/models/csp_report/csp_report_spec.rb
258
298
  - spec/spec_helper.rb