|
15 | 15 |
|
16 | 16 | from unittest.mock import Mock, patch
|
17 | 17 |
|
| 18 | +from http_server_mock import HttpServerMock |
18 | 19 | from tornado.testing import AsyncHTTPTestCase
|
19 | 20 |
|
20 | 21 | from opentelemetry import trace
|
@@ -494,32 +495,35 @@ def test_response_headers(self):
|
494 | 495 | self.memory_exporter.clear()
|
495 | 496 | set_global_response_propagator(orig)
|
496 | 497 |
|
497 |
| - # todo(srikanthccv): fix this test |
498 |
| - # this test is making request to real httpbin.org/status/200 which |
499 |
| - # is not a good idea as it can fail due to availability of the |
500 |
| - # service. |
501 |
| - # def test_credential_removal(self): |
502 |
| - # response = self.fetch( |
503 |
| - # "http://username:password@httpbin.org/status/200" |
504 |
| - # ) |
505 |
| - # self.assertEqual(response.code, 200) |
506 |
| - |
507 |
| - # spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) |
508 |
| - # self.assertEqual(len(spans), 1) |
509 |
| - # client = spans[0] |
510 |
| - |
511 |
| - # self.assertEqual(client.name, "GET") |
512 |
| - # self.assertEqual(client.kind, SpanKind.CLIENT) |
513 |
| - # self.assertSpanHasAttributes( |
514 |
| - # client, |
515 |
| - # { |
516 |
| - # SpanAttributes.HTTP_URL: "http://httpbin.org/status/200", |
517 |
| - # SpanAttributes.HTTP_METHOD: "GET", |
518 |
| - # SpanAttributes.HTTP_STATUS_CODE: 200, |
519 |
| - # }, |
520 |
| - # ) |
521 |
| - |
522 |
| - # self.memory_exporter.clear() |
| 498 | + def test_credential_removal(self): |
| 499 | + app = HttpServerMock("test_credential_removal") |
| 500 | + |
| 501 | + @app.route("/status/200") |
| 502 | + def index(): |
| 503 | + return "hello" |
| 504 | + |
| 505 | + with app.run("localhost", 5000): |
| 506 | + response = self.fetch( |
| 507 | + "http://username:password@localhost:5000/status/200" |
| 508 | + ) |
| 509 | + self.assertEqual(response.code, 200) |
| 510 | + |
| 511 | + spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) |
| 512 | + self.assertEqual(len(spans), 1) |
| 513 | + client = spans[0] |
| 514 | + |
| 515 | + self.assertEqual(client.name, "GET") |
| 516 | + self.assertEqual(client.kind, SpanKind.CLIENT) |
| 517 | + self.assertSpanHasAttributes( |
| 518 | + client, |
| 519 | + { |
| 520 | + SpanAttributes.HTTP_URL: "http://localhost:5000/status/200", |
| 521 | + SpanAttributes.HTTP_METHOD: "GET", |
| 522 | + SpanAttributes.HTTP_STATUS_CODE: 200, |
| 523 | + }, |
| 524 | + ) |
| 525 | + |
| 526 | + self.memory_exporter.clear() |
523 | 527 |
|
524 | 528 |
|
525 | 529 | class TestTornadoInstrumentationWithXHeaders(TornadoTest):
|
|
0 commit comments