|
56 | 56 | end |
57 | 57 | end |
58 | 58 |
|
| 59 | + describe "data collection" do |
| 60 | + describe "query parameters" do |
| 61 | + def perform_get_request(query: "token=secret&page=5") |
| 62 | + transaction = Sentry.start_transaction |
| 63 | + Sentry.get_current_scope.set_span(transaction) |
| 64 | + Excon.stub({}, { body: "", status: 200 }) |
| 65 | + Excon.get("http://example.com/path?#{query}", mock: true) |
| 66 | + transaction |
| 67 | + end |
| 68 | + |
| 69 | + it "does not collect them when the mode is off" do |
| 70 | + Sentry.configuration.data_collection.url_query_params.mode = :off |
| 71 | + transaction = perform_get_request |
| 72 | + |
| 73 | + expect(transaction.span_recorder.spans.last.data).not_to have_key("http.query") |
| 74 | + expect(transaction.span_recorder.spans.last.data["url"]).to eq("http://example.com/path") |
| 75 | + end |
| 76 | + |
| 77 | + it "filters sensitive values in deny-list mode" do |
| 78 | + Sentry.configuration.data_collection.url_query_params.mode = :deny_list |
| 79 | + transaction = perform_get_request |
| 80 | + |
| 81 | + expect(transaction.span_recorder.spans.last.data["http.query"]).to eq( |
| 82 | + "token=[Filtered]&page=5" |
| 83 | + ) |
| 84 | + expect(transaction.span_recorder.spans.last.data["url"]).to eq( |
| 85 | + "http://example.com/path?token=[Filtered]&page=5" |
| 86 | + ) |
| 87 | + end |
| 88 | + |
| 89 | + it "collects only allowed values in allow-list mode" do |
| 90 | + Sentry.configuration.data_collection.url_query_params.mode = :allow_list |
| 91 | + Sentry.configuration.data_collection.url_query_params.terms = ["page"] |
| 92 | + transaction = perform_get_request(query: "another=value&page=5") |
| 93 | + |
| 94 | + expect(transaction.span_recorder.spans.last.data["http.query"]).to eq( |
| 95 | + "another=[Filtered]&page=5" |
| 96 | + ) |
| 97 | + expect(transaction.span_recorder.spans.last.data["url"]).to eq( |
| 98 | + "http://example.com/path?another=[Filtered]&page=5" |
| 99 | + ) |
| 100 | + end |
| 101 | + end |
| 102 | + |
| 103 | + describe "request bodies" do |
| 104 | + before do |
| 105 | + Sentry.configuration.breadcrumbs_logger = [:http_logger] |
| 106 | + end |
| 107 | + |
| 108 | + def perform_post_request |
| 109 | + transaction = Sentry.start_transaction |
| 110 | + Sentry.get_current_scope.set_span(transaction) |
| 111 | + Excon.stub({}, { body: "", status: 200 }) |
| 112 | + Excon.post("http://example.com/path", body: "secret body", mock: true) |
| 113 | + end |
| 114 | + |
| 115 | + it "collects them when all body types are enabled" do |
| 116 | + Sentry.configuration.data_collection.http_bodies = nil |
| 117 | + perform_post_request |
| 118 | + |
| 119 | + expect(Sentry.get_current_scope.breadcrumbs.peek.data[:body]).to eq("secret body") |
| 120 | + end |
| 121 | + |
| 122 | + it "collects them when outgoing requests are enabled" do |
| 123 | + Sentry.configuration.data_collection.http_bodies = [:outgoing_request] |
| 124 | + perform_post_request |
| 125 | + |
| 126 | + expect(Sentry.get_current_scope.breadcrumbs.peek.data[:body]).to eq("secret body") |
| 127 | + end |
| 128 | + |
| 129 | + it "does not collect them when body types are disabled" do |
| 130 | + Sentry.configuration.data_collection.http_bodies = [] |
| 131 | + perform_post_request |
| 132 | + |
| 133 | + expect(Sentry.get_current_scope.breadcrumbs.peek.data).not_to have_key(:body) |
| 134 | + end |
| 135 | + end |
| 136 | + end |
| 137 | + |
59 | 138 | context "with config.send_default_pii = true" do |
60 | 139 | before do |
61 | 140 | Sentry.configuration.send_default_pii = true |
|
82 | 161 | expect(request_span.description).to eq("GET http://example.com/path") |
83 | 162 | expect(request_span.data).to eq({ |
84 | 163 | "http.response.status_code" => 200, |
85 | | - "url" => "http://example.com/path", |
| 164 | + "url" => "http://example.com/path?foo=bar", |
86 | 165 | "http.request.method" => "GET", |
87 | 166 | "http.query" => "foo=bar" |
88 | 167 | }) |
|
95 | 174 | Sentry.get_current_scope.set_span(transaction) |
96 | 175 |
|
97 | 176 | connection = Excon.new("http://example.com/path") |
98 | | - response = connection.get(mock: true, query: build_nested_query({ foo: "bar", baz: [1, 2], qux: { a: 1, b: 2 } })) |
| 177 | + response = connection.get(mock: true, query: "foo=bar&baz[]=1&baz[]=2&qux[a]=1&qux[b]=2") |
99 | 178 |
|
100 | 179 | expect(response.status).to eq(200) |
101 | 180 | expect(transaction.span_recorder.spans.count).to eq(2) |
|
109 | 188 | expect(request_span.description).to eq("GET http://example.com/path") |
110 | 189 | expect(request_span.data).to eq({ |
111 | 190 | "http.response.status_code" => 200, |
112 | | - "url" => "http://example.com/path", |
| 191 | + "url" => "http://example.com/path?foo=bar&baz[]=1&baz[]=2&qux[a]=1&qux[b]=2", |
113 | 192 | "http.request.method" => "GET", |
114 | | - "http.query" => "foo=bar&baz%5B%5D=1&baz%5B%5D=2&qux%5Ba%5D=1&qux%5Bb%5D=2" |
| 193 | + "http.query" => "foo=bar&baz[]=1&baz[]=2&qux[a]=1&qux[b]=2" |
115 | 194 | }) |
116 | 195 | end |
117 | 196 |
|
|
0 commit comments