File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
lib/datadog/appsec/api_security
spec/datadog/appsec/api_security Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,9 @@ def self.route_pattern(request)
49
49
pattern = request . env [ RAILS_ROUTES_KEY ] . router
50
50
. recognize ( request ) { |route , _ | break route . path . spec . to_s }
51
51
52
+ # NOTE: If rails is unable to recognize request it returns empty Array
53
+ pattern = nil if pattern &.empty?
54
+
52
55
# NOTE: If rails can't recognize the request, we are going to fallback
53
56
# to generic request path
54
57
( pattern || request . path ) . delete_suffix ( RAILS_FORMAT_SUFFIX )
Original file line number Diff line number Diff line change 91
91
92
92
it { expect ( described_class . route_pattern ( request ) ) . to eq ( '/api/v1/users/:id/posts/:post_id' ) }
93
93
end
94
+
95
+ context 'when Rails router cannot recognize request' do
96
+ before do
97
+ allow ( request ) . to receive ( :env ) . and_return ( { 'action_dispatch.routes' => route_set } )
98
+ allow ( request ) . to receive ( :path ) . and_return ( '/unmatched/route' )
99
+ allow ( router ) . to receive ( :recognize ) . with ( request ) . and_return ( [ ] )
100
+ end
101
+
102
+ let ( :router ) { double ( 'ActionDispatch::Routing::RouteSet::Router' ) }
103
+ let ( :route_set ) { double ( 'ActionDispatch::Routing::RouteSet' , router : router ) }
104
+
105
+ it { expect ( described_class . route_pattern ( request ) ) . to eq ( '/unmatched/route' ) }
106
+ end
94
107
end
95
108
96
109
context 'when Rack routing is present' do
You can’t perform that action at this time.
0 commit comments