|
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 | + end |
| 75 | + |
| 76 | + it "filters sensitive values in deny-list mode" do |
| 77 | + Sentry.configuration.data_collection.url_query_params.mode = :deny_list |
| 78 | + transaction = perform_get_request |
| 79 | + |
| 80 | + expect(transaction.span_recorder.spans.last.data["http.query"]).to eq( |
| 81 | + "token=%5BFiltered%5D&page=5" |
| 82 | + ) |
| 83 | + end |
| 84 | + |
| 85 | + it "collects only allowed values in allow-list mode" do |
| 86 | + Sentry.configuration.data_collection.url_query_params.mode = :allow_list |
| 87 | + Sentry.configuration.data_collection.url_query_params.terms = ["page"] |
| 88 | + transaction = perform_get_request(query: "another=value&page=5") |
| 89 | + |
| 90 | + expect(transaction.span_recorder.spans.last.data["http.query"]).to eq( |
| 91 | + "another=%5BFiltered%5D&page=5" |
| 92 | + ) |
| 93 | + end |
| 94 | + end |
| 95 | + |
| 96 | + describe "request bodies" do |
| 97 | + before do |
| 98 | + Sentry.configuration.breadcrumbs_logger = [:http_logger] |
| 99 | + end |
| 100 | + |
| 101 | + def perform_post_request |
| 102 | + transaction = Sentry.start_transaction |
| 103 | + Sentry.get_current_scope.set_span(transaction) |
| 104 | + Excon.stub({}, { body: "", status: 200 }) |
| 105 | + Excon.post("http://example.com/path", body: "secret body", mock: true) |
| 106 | + end |
| 107 | + |
| 108 | + it "collects them when all body types are enabled" do |
| 109 | + Sentry.configuration.data_collection.http_bodies = nil |
| 110 | + perform_post_request |
| 111 | + |
| 112 | + expect(Sentry.get_current_scope.breadcrumbs.peek.data[:body]).to eq("secret body") |
| 113 | + end |
| 114 | + |
| 115 | + it "collects them when outgoing requests are enabled" do |
| 116 | + Sentry.configuration.data_collection.http_bodies = [:outgoing_request] |
| 117 | + perform_post_request |
| 118 | + |
| 119 | + expect(Sentry.get_current_scope.breadcrumbs.peek.data[:body]).to eq("secret body") |
| 120 | + end |
| 121 | + |
| 122 | + it "does not collect them when body types are disabled" do |
| 123 | + Sentry.configuration.data_collection.http_bodies = [] |
| 124 | + perform_post_request |
| 125 | + |
| 126 | + expect(Sentry.get_current_scope.breadcrumbs.peek.data).not_to have_key(:body) |
| 127 | + end |
| 128 | + end |
| 129 | + end |
| 130 | + |
59 | 131 | context "with config.send_default_pii = true" do |
60 | 132 | before do |
61 | 133 | Sentry.configuration.send_default_pii = true |
|
95 | 167 | Sentry.get_current_scope.set_span(transaction) |
96 | 168 |
|
97 | 169 | 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 } })) |
| 170 | + response = connection.get(mock: true, query: "foo=bar&baz[]=1&baz[]=2&qux[a]=1&qux[b]=2") |
99 | 171 |
|
100 | 172 | expect(response.status).to eq(200) |
101 | 173 | expect(transaction.span_recorder.spans.count).to eq(2) |
|
0 commit comments