Skip to content

Commit

Permalink
Merge pull request #14 from sealink/occurrence_env
Browse files Browse the repository at this point in the history
Adds `original_env` and `filtered_env` properties to occurrence
  • Loading branch information
alvinypyim committed Dec 27, 2016
2 parents 99f14dc + 4cade5a commit f742c5d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).
### Changed
- Updates README for usage with Rails middleware stack

### Added
- Adds `original_env` and `filtered_env` properties to occurrence

## [0.2.4] - 2016-12-22
### Changed
- Does not match credit cards numbers that are part of alphanumerical strings
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ An occurrence object has the following properties:
* session: the session properties for the request
* matches: the matched sensitive data
* matches_count: the number of matches per data type, e.g. { 'CreditCard' => 1 }
* original_env: the original unfiltered Rack env
* filtered_env: the filtered Rack env which will be passed down the middleware stack

It also exposes `to_h` and `to_s` methods for hash and string representation respectively.
Please note that these representations omit sensitive data,
Expand Down
8 changes: 8 additions & 0 deletions lib/sensitive_data_filter/middleware/occurrence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def filtered_body_params
@filtered_env_parser.body_params
end

def original_env
@original_env_parser.env
end

def filtered_env
@filtered_env_parser.env
end

def_delegators :@filtered_env_parser, :request_method, :url, :content_type, :session

def matches_count
Expand Down
10 changes: 8 additions & 2 deletions spec/sensitive_data_filter/middleware/occurrence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
let(:original_body_params) { { credit_cards: '4111 1111 1111 1111 and 5123 4567 8901 2346' } }
let(:filtered_body_params) { { credit_cards: '[FILTERED] and [FILTERED]' } }
let(:session) { { 'session_id' => '01ab02cd' } }
let(:original_env) { double }
let(:filtered_env) { double }
let(:original_env_parser) {
double(
ip: ip,
Expand All @@ -23,7 +25,8 @@
content_type: content_type,
query_params: original_query_params,
body_params: original_body_params,
session: session
session: session,
env: original_env
)
}
let(:filtered_env_parser) {
Expand All @@ -34,7 +37,8 @@
content_type: content_type,
query_params: filtered_query_params,
body_params: filtered_body_params,
session: session
session: session,
env: filtered_env
)
}
let(:matches) {
Expand All @@ -61,6 +65,8 @@
specify { expect(occurrence.filtered_body_params).to eq filtered_body_params }
specify { expect(occurrence.session).to eq session }
specify { expect(occurrence.matches_count).to eq matches_count }
specify { expect(occurrence.original_env).to eq original_env }
specify { expect(occurrence.filtered_env).to eq filtered_env }

let(:expected_to_h) {
{
Expand Down

0 comments on commit f742c5d

Please sign in to comment.