This repository was archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Add a 'report only' feature where activerecord models will not blow up when firewalled but will just log #3
Open
JackMc
wants to merge
5
commits into
master
Choose a base branch
from
add-report-only
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b71f4dd
Add a 'report only' feature where activerecord models will not blow u…
JackMc 16584f3
Drop rails version
JackMc bf28cbe
Somehow my test helpers don't work on Rails 5.0.x :(
JackMc 8162212
Remove Current autoload hack
JackMc 84942e9
Version bump, add CHANGELOG
JackMc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ## 0.2.0 | ||
|
|
||
| - Added `report_only` option to `firewalled_belongs_to` to log violations and | ||
| not raise |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,4 +20,4 @@ commands: | |
| syntax: | ||
| argument: file | ||
| optional: args... | ||
| run: bin/testunit | ||
| run: bin/test | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| module Activerecord | ||
| module Firewall | ||
| VERSION = '0.1.0' | ||
| VERSION = '0.2.0' | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| class Image < ApplicationRecord | ||
| firewalled_belongs_to :user, report_only: true | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| Rails.application.routes.draw do | ||
| # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | ||
|
|
||
| get '/:user_id/:blog_post_id', to: "blog_post#show" | ||
| get '/blogs/:user_id/:blog_post_id', to: "blog_post#show" | ||
| get '/images/:user_id/:image_id', to: "blog_post#image" | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| class CreateImages < ActiveRecord::Migration[5.1] | ||
| def change | ||
| create_table :images do |t| | ||
| t.string :alt | ||
| t.string :url | ||
| t.belongs_to :user, foreign_key: true | ||
|
|
||
| t.timestamps | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| require 'test_helper' | ||
|
|
||
| class ImageTest < ActiveSupport::TestCase | ||
| setup do | ||
| @goodbob = users(:goodbob) | ||
| @evilbob = users(:evilbob) | ||
|
|
||
| @goodbobs_image = images(:goodbobs_image) | ||
| @evilbobs_image = images(:evilbobs_image) | ||
|
|
||
| @log_msg = "[activerecord-firewall] Image from User #{@goodbob.id} was accessed from User #{@evilbob.id}" | ||
|
|
||
| Current.user = @evilbob | ||
| end | ||
|
|
||
| teardown do | ||
| Current.reset | ||
| end | ||
|
|
||
| test "image belonging to evil bob is accessible by evil bob with no log messages" do | ||
| assert_nothing_raised do | ||
| assert_not_logged(@log_msg) do | ||
| Image.where(user: @evilbob).first | ||
| end | ||
| end | ||
| end | ||
|
|
||
| test "image belonging to good bob is accessible by evil bob with no log messages" do | ||
| assert_nothing_raised do | ||
| assert_logged(@log_msg) do | ||
| Image.where(user: @goodbob).first | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
|
||
| goodbobs_image: | ||
| alt: This is alt text for good bob's image | ||
| url: https://example.com/goodbob.png | ||
| user: goodbob | ||
|
|
||
| evilbobs_image: | ||
| alt: This is alt text for evil bob's image | ||
| url: https://example.com/evilbob.png | ||
| user: evilbob |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two helpers are copied & modified from an internal helper in ActionView: https://github.com/rails/rails/blob/309bb6c4d068b0d480681cf4ef1b90158527dfe5/actionview/test/template/digestor_test.rb#L304-L317