コード例 #1
0
 def test_near_miss_match_pattern_request_serialization(self):
     e = NearMissMatchPatternRequest(
         url="test",
         url_pattern="test2",
         url_path="test3",
         url_path_pattern="test4",
         method=HttpMethods.GET,
         client_ip="1.1.1.1",
         headers={CommonHeaders.ACCEPT: "json"},
         query_parameters={"test": 1},
         cookies={"chocolate": "chip"},
         body_patterns={"test": 3},
         basic_auth_credentials=BasicAuthCredentials(username="******",
                                                     password="******"),
         browser_proxy_request=False,
         logged_date=12345,
         logged_date_string="1/1/2017 00:00:00+0000",
     )
     serialized = e.get_json_data()
     self.assertDictContainsKeyWithValue(serialized, "url", "test")
     self.assertDictContainsKeyWithValue(serialized, "urlPattern", "test2")
     self.assertDictContainsKeyWithValue(serialized, "urlPath", "test3")
     self.assertDictContainsKeyWithValue(serialized, "urlPathPattern",
                                         "test4")
     self.assertDictContainsKeyWithValue(serialized, "method", "GET")
     self.assertDictContainsKeyWithValue(serialized, "clientIp", "1.1.1.1")
     self.assertDictContainsKeyWithValue(serialized, "headers",
                                         {"Accept": "json"})
     self.assertDictContainsKeyWithValue(serialized, "queryParameters",
                                         {"test": 1})
     self.assertDictContainsKeyWithValue(serialized, "cookies",
                                         {"chocolate": "chip"})
     self.assertDictContainsKeyWithValue(serialized, "bodyPatterns",
                                         {"test": 3})
     self.assertDictContainsKeyWithValue(serialized, "basicAuthCredentials",
                                         {
                                             "username": "******",
                                             "password": "******"
                                         })
     self.assertDictContainsKeyWithValue(serialized, "browserProxyRequest",
                                         False)
     self.assertDictContainsKeyWithValue(serialized, "loggedDate", 12345)
     self.assertDictContainsKeyWithValue(serialized, "loggedDateString",
                                         "1/1/2017 00:00:00+0000")
コード例 #2
0
 def test_near_miss_match_pattern_request_serialization(self):
     e = NearMissMatchPatternRequest(
         url='test',
         url_pattern='test2',
         url_path='test3',
         url_path_pattern='test4',
         method=HttpMethods.GET,
         client_ip='1.1.1.1',
         headers={CommonHeaders.ACCEPT: 'json'},
         query_parameters={'test': 1},
         cookies={'chocolate': 'chip'},
         body_patterns={'test': 3},
         basic_auth_credentials=BasicAuthCredentials(username='******',
                                                     password='******'),
         browser_proxy_request=False,
         logged_date=12345,
         logged_date_string='1/1/2017 00:00:00+0000')
     serialized = e.get_json_data()
     self.assertDictContainsKeyWithValue(serialized, 'url', 'test')
     self.assertDictContainsKeyWithValue(serialized, 'urlPattern', 'test2')
     self.assertDictContainsKeyWithValue(serialized, 'urlPath', 'test3')
     self.assertDictContainsKeyWithValue(serialized, 'urlPathPattern',
                                         'test4')
     self.assertDictContainsKeyWithValue(serialized, 'method', 'GET')
     self.assertDictContainsKeyWithValue(serialized, 'clientIp', '1.1.1.1')
     self.assertDictContainsKeyWithValue(serialized, 'headers',
                                         {'Accept': 'json'})
     self.assertDictContainsKeyWithValue(serialized, 'queryParameters',
                                         {'test': 1})
     self.assertDictContainsKeyWithValue(serialized, 'cookies',
                                         {'chocolate': 'chip'})
     self.assertDictContainsKeyWithValue(serialized, 'bodyPatterns',
                                         {'test': 3})
     self.assertDictContainsKeyWithValue(serialized, 'basicAuthCredentials',
                                         {
                                             'username': '******',
                                             'password': '******'
                                         })
     self.assertDictContainsKeyWithValue(serialized, 'browserProxyRequest',
                                         False)
     self.assertDictContainsKeyWithValue(serialized, 'loggedDate', 12345)
     self.assertDictContainsKeyWithValue(serialized, 'loggedDateString',
                                         '1/1/2017 00:00:00+0000')
コード例 #3
0
async def ingest_lines_output(expected_ingest_output_file):
    await async_dynatrace_gcp_extension()
    reqeusts_gcp_timeseries_pattern = NearMissMatchPatternRequest(
        url_path_pattern=
        "/v3/projects/dynatrace-gcp-extension/timeSeries?([\d\w\W]*)",
        method="GET")
    reqeusts_gcp_timeseries: RequestResponseFindResponse = Requests.get_matching_requests(
        reqeusts_gcp_timeseries_pattern)
    gce_instance_filter = "resource.labels.instance_name%3Dstarts_with(%22test%22)"
    requests_with_filter = [
        reqeust_gcp_timeseries
        for reqeust_gcp_timeseries in reqeusts_gcp_timeseries.requests
        if gce_instance_filter in reqeust_gcp_timeseries.url
    ]
    assert_that(requests_with_filter).is_length(3)

    sent_requests = Requests.get_all_received_requests().get_json_data().get(
        'requests')
    urls = {sent_request["request"]["url"] for sent_request in sent_requests}
    apigee_url_prefix = "/v3/projects/dynatrace-gcp-extension/timeSeries?filter=metric.type+%3D+%22apigee.googleapis.com/environment/anomaly_count"
    request_for_apigee_metric_was_sent = any(
        url.startswith(apigee_url_prefix) for url in urls)
    assert not request_for_apigee_metric_was_sent

    request_metrics_ingest_pattern = NearMissMatchPatternRequest(
        url_path_pattern="/api/v2/metrics/ingest", method="POST")
    request_metrics_ingest: RequestResponseFindResponse = Requests.get_matching_requests(
        request_metrics_ingest_pattern)
    assert_that(request_metrics_ingest.requests).is_not_empty()
    result: RequestResponseRequest = request_metrics_ingest.requests[0]

    body = result.body

    with open(expected_ingest_output_file) as ingest:
        expected_ingest_lines = ingest.read().split("\n")
        actual_ingest_lines = body.split("\n")

        assert_that(actual_ingest_lines).is_length(len(expected_ingest_lines))
        assert_that(actual_ingest_lines).contains_only(*expected_ingest_lines)
コード例 #4
0
async def test_metric_authorization_header():
    await async_dynatrace_gcp_extension()

    request = NearMissMatchPatternRequest(
        url_path_pattern="/api/v2/metrics/ingest", method="POST")

    matched_request: RequestResponseFindResponse = Requests.get_matching_requests(
        request)

    assert_that(matched_request.requests).is_not_empty()

    result: RequestResponseRequest = matched_request.requests[0]

    assert_that(result.headers['Authorization']).is_equal_to(
        f"Api-Token {AUTHORIZATION_KEY}")
コード例 #5
0
 def test_near_miss_match_pattern_request_deserialization(self):
     serialized = {
         'clientIp': '1.1.1.1',
         'cookies': {
             'chocolate': 'chip'
         },
         'loggedDate': 12345,
         'urlPattern': 'test2',
         'headers': {
             'Accept': 'json'
         },
         'url': 'test',
         'urlPath': 'test3',
         'urlPathPattern': 'test4',
         'browserProxyRequest': False,
         'loggedDateString': '1/1/2017 00:00:00+0000',
         'bodyPatterns': {
             'test': 3
         },
         'queryParameters': {
             'test': 1
         },
         'basicAuthCredentials': {
             'username': '******',
             'password': '******'
         },
         'method': 'GET'
     }
     e = NearMissMatchPatternRequest.from_dict(serialized)
     self.assertIsInstance(e, NearMissMatchPatternRequest)
     self.assertEquals('test', e.url)
     self.assertEquals('test2', e.url_pattern)
     self.assertEquals('test3', e.url_path)
     self.assertEquals('test4', e.url_path_pattern)
     self.assertEquals('GET', e.method)
     self.assertEquals('1.1.1.1', e.client_ip)
     self.assertEquals({'Accept': 'json'}, e.headers)
     self.assertEquals({'test': 1}, e.query_parameters)
     self.assertEquals({'chocolate': 'chip'}, e.cookies)
     self.assertDictEqual({'test': 3}, e.body_patterns)
     self.assertIsInstance(e.basic_auth_credentials, BasicAuthCredentials)
     self.assertEquals('username', e.basic_auth_credentials.username)
     self.assertEquals('password', e.basic_auth_credentials.password)
     self.assertEquals(False, e.browser_proxy_request)
     self.assertEquals(12345, e.logged_date)
     self.assertEquals('1/1/2017 00:00:00+0000', e.logged_date_string)
コード例 #6
0
 def test_near_miss_match_pattern_request_deserialization(self):
     serialized = {
         "clientIp": "1.1.1.1",
         "cookies": {
             "chocolate": "chip"
         },
         "loggedDate": 12345,
         "urlPattern": "test2",
         "headers": {
             "Accept": "json"
         },
         "url": "test",
         "urlPath": "test3",
         "urlPathPattern": "test4",
         "browserProxyRequest": False,
         "loggedDateString": "1/1/2017 00:00:00+0000",
         "bodyPatterns": {
             "test": 3
         },
         "queryParameters": {
             "test": 1
         },
         "basicAuthCredentials": {
             "username": "******",
             "password": "******"
         },
         "method": "GET",
     }
     e = NearMissMatchPatternRequest.from_dict(serialized)
     self.assertIsInstance(e, NearMissMatchPatternRequest)
     self.assertEquals("test", e.url)
     self.assertEquals("test2", e.url_pattern)
     self.assertEquals("test3", e.url_path)
     self.assertEquals("test4", e.url_path_pattern)
     self.assertEquals("GET", e.method)
     self.assertEquals("1.1.1.1", e.client_ip)
     self.assertEquals({"Accept": "json"}, e.headers)
     self.assertEquals({"test": 1}, e.query_parameters)
     self.assertEquals({"chocolate": "chip"}, e.cookies)
     self.assertDictEqual({"test": 3}, e.body_patterns)
     self.assertIsInstance(e.basic_auth_credentials, BasicAuthCredentials)
     self.assertEquals("username", e.basic_auth_credentials.username)
     self.assertEquals("password", e.basic_auth_credentials.password)
     self.assertEquals(False, e.browser_proxy_request)
     self.assertEquals(12345, e.logged_date)
     self.assertEquals("1/1/2017 00:00:00+0000", e.logged_date_string)