Skip to content

Conversation

selectiveduplicate
Copy link
Contributor

@selectiveduplicate selectiveduplicate commented Sep 26, 2024

Edit: Updated with more tests after the most recent commit.

Test results

From the tests inside moesif_aws_lambda/tests/ directory.

TestProcessBody.test_request_with_valid_base64_body

(myenv) ;; python -m unittest -k TestProcessBody.test_process_body_for_valid_base64_body
[moesif] start init - config
[moesif] end init - config
[moesif] : [before] Incoming Event:
{"version": "2.0", "routeKey": "$default", "rawPath": "/path/to/resource", "rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value", "cookies": ["cookie1", "cookie2"], "headers": {"Header1": "value1", "Header2": "value1,value2"}, "queryStringParameters": {"parameter1": "value1,value2", "parameter2": "value"}, "requestContext": {"accountId": "123456789012", "apiId": "api-id", "authentication": {"clientCert": {"clientCertPem": "CERT_CONTENT", "subjectDN": "www.example.com", "issuerDN": "Example issuer", "serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1", "validity": {"notBefore": "May 28 12:30:02 2019 GMT", "notAfter": "Aug  5 09:36:04 2021 GMT"}}}, "authorizer": {"jwt": {"claims": {"claim1": "value1", "claim2": "value2"}, "scopes": ["scope1", "scope2"]}}, "domainName": "id.execute-api.us-east-1.amazonaws.com", "domainPrefix": "id", "http": {"method": "POST", "path": "/path/to/resource", "protocol": "HTTP/1.1", "sourceIp": "192.168.0.1/32", "userAgent": "agent"}, "requestId": "id", "routeKey": "$default", "stage": "$default"}, "body": "eyJ0ZXN0IjoiYm9keSJ9", "pathParameters": {"parameter1": "value1"}, "isBase64Encoded": true, "stageVariables": {"stageVariable1": "value1", "stageVariable2": "value2"}}
[moesif] cannot fetch default function_name and request_context from aws context, setting metadata to None.
[moesif] Time took in fetching metadata in millisecond - 0.009000000000000001
[moesif] Time took in fetching user id in millisecond - 0.001
[moesif] Time took in identifying the user in millisecond - 0.005
[moesif] Time took in fetching company id in millisecond - 0.0
[moesif] Time took in identifying the company in millisecond - 0.003
[moesif] cannot execute GET_API_VERSION function, please check moesif settings.
'dict' object has no attribute 'function_version'
[moesif] Time took before the handler is invoked in millisecond - 0.449
[moesif] : [after] Moesif Event Model:
{"version": "2.0", "routeKey": "$default", "rawPath": "/path/to/resource", "rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value", "cookies": ["cookie1", "cookie2"], "headers": {"Header1": "value1", "Header2": "value1,value2"}, "queryStringParameters": {"parameter1": "value1,value2", "parameter2": "value"}, "requestContext": {"accountId": "123456789012", "apiId": "api-id", "authentication": {"clientCert": {"clientCertPem": "CERT_CONTENT", "subjectDN": "www.example.com", "issuerDN": "Example issuer", "serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1", "validity": {"notBefore": "May 28 12:30:02 2019 GMT", "notAfter": "Aug  5 09:36:04 2021 GMT"}}}, "authorizer": {"jwt": {"claims": {"claim1": "value1", "claim2": "value2"}, "scopes": ["scope1", "scope2"]}}, "domainName": "id.execute-api.us-east-1.amazonaws.com", "domainPrefix": "id", "http": {"method": "POST", "path": "/path/to/resource", "protocol": "HTTP/1.1", "sourceIp": "192.168.0.1/32", "userAgent": "agent"}, "requestId": "id", "routeKey": "$default", "stage": "$default"}, "body": "eyJ0ZXN0IjoiYm9keSJ9", "pathParameters": {"parameter1": "value1"}, "isBase64Encoded": true, "stageVariables": {"stageVariable1": "value1", "stageVariable2": "value2"}}
/home/sakib/Documents/Programming/python/venvs/myenv/lib/python3.10/site-packages/urllib3/util/ssl_.py:263: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated
  context = SSLContext(ssl_version or PROTOCOL_TLS)
/home/sakib/Documents/Programming/python/venvs/myenv/lib/python3.10/site-packages/urllib3/connection.py:400: DeprecationWarning: ssl.match_hostname() is deprecated
  match_hostname(cert, asserted_hostname)
[moesif] Time took after the handler is invoked in millisecond - 870.207
.
----------------------------------------------------------------------
Ran 1 test in 0.872s

OK

TestProcessBody.test_request_with_invalid_base64_body_types

[moesif] start init - config
[moesif] end init - config
[moesif] : [before] Incoming Event:
{"version": "2.0", "routeKey": "$default", "rawPath": "/path/to/resource", "rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value", "cookies": ["cookie1", "cookie2"], "headers": {"Header1": "value1", "Header2": "value1,value2"}, "queryStringParameters": {"parameter1": "value1,value2", "parameter2": "value"}, "requestContext": {"accountId": "123456789012", "apiId": "api-id", "authentication": {"clientCert": {"clientCertPem": "CERT_CONTENT", "subjectDN": "www.example.com", "issuerDN": "Example issuer", "serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1", "validity": {"notBefore": "May 28 12:30:02 2019 GMT", "notAfter": "Aug  5 09:36:04 2021 GMT"}}}, "authorizer": {"jwt": {"claims": {"claim1": "value1", "claim2": "value2"}, "scopes": ["scope1", "scope2"]}}, "domainName": "id.execute-api.us-east-1.amazonaws.com", "domainPrefix": "id", "http": {"method": "POST", "path": "/path/to/resource", "protocol": "HTTP/1.1", "sourceIp": "192.168.0.1/32", "userAgent": "agent"}, "requestId": "id", "routeKey": "$default", "stage": "$default"}, "body": {"foo": "bar"}, "pathParameters": {"parameter1": "value1"}, "isBase64Encoded": true, "stageVariables": {"stageVariable1": "value1", "stageVariable2": "value2"}}
[moesif] cannot fetch default function_name and request_context from aws context, setting metadata to None.
[moesif] Time took in fetching metadata in millisecond - 0.006
[moesif] Time took in fetching user id in millisecond - 0.001
[moesif] Time took in identifying the user in millisecond - 0.006
[moesif] Time took in fetching company id in millisecond - 0.001
[moesif] Time took in identifying the company in millisecond - 0.005
[moesif] cannot execute GET_API_VERSION function, please check moesif settings.
'dict' object has no attribute 'function_version'
[moesif] Time took before the handler is invoked in millisecond - 0.156
[moesif] : [after] Moesif Event Model:
{"version": "2.0", "routeKey": "$default", "rawPath": "/path/to/resource", "rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value", "cookies": ["cookie1", "cookie2"], "headers": {"Header1": "value1", "Header2": "value1,value2"}, "queryStringParameters": {"parameter1": "value1,value2", "parameter2": "value"}, "requestContext": {"accountId": "123456789012", "apiId": "api-id", "authentication": {"clientCert": {"clientCertPem": "CERT_CONTENT", "subjectDN": "www.example.com", "issuerDN": "Example issuer", "serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1", "validity": {"notBefore": "May 28 12:30:02 2019 GMT", "notAfter": "Aug  5 09:36:04 2021 GMT"}}}, "authorizer": {"jwt": {"claims": {"claim1": "value1", "claim2": "value2"}, "scopes": ["scope1", "scope2"]}}, "domainName": "id.execute-api.us-east-1.amazonaws.com", "domainPrefix": "id", "http": {"method": "POST", "path": "/path/to/resource", "protocol": "HTTP/1.1", "sourceIp": "192.168.0.1/32", "userAgent": "agent"}, "requestId": "id", "routeKey": "$default", "stage": "$default"}, "body": {"foo": "bar"}, "pathParameters": {"parameter1": "value1"}, "isBase64Encoded": true, "stageVariables": {"stageVariable1": "value1", "stageVariable2": "value2"}}
/home/sakib/Documents/Programming/python/venvs/myenv/lib/python3.10/site-packages/urllib3/util/ssl_.py:263: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated
  context = SSLContext(ssl_version or PROTOCOL_TLS)
/home/sakib/Documents/Programming/python/venvs/myenv/lib/python3.10/site-packages/urllib3/connection.py:400: DeprecationWarning: ssl.match_hostname() is deprecated
  match_hostname(cert, asserted_hostname)
[moesif] Time took after the handler is invoked in millisecond - 608.0029999999999
[moesif] : [before] Incoming Event:
{"version": "2.0", "routeKey": "$default", "rawPath": "/path/to/resource", "rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value", "cookies": ["cookie1", "cookie2"], "headers": {"Header1": "value1", "Header2": "value1,value2"}, "queryStringParameters": {"parameter1": "value1,value2", "parameter2": "value"}, "requestContext": {"accountId": "123456789012", "apiId": "api-id", "authentication": {"clientCert": {"clientCertPem": "CERT_CONTENT", "subjectDN": "www.example.com", "issuerDN": "Example issuer", "serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1", "validity": {"notBefore": "May 28 12:30:02 2019 GMT", "notAfter": "Aug  5 09:36:04 2021 GMT"}}}, "authorizer": {"jwt": {"claims": {"claim1": "value1", "claim2": "value2"}, "scopes": ["scope1", "scope2"]}}, "domainName": "id.execute-api.us-east-1.amazonaws.com", "domainPrefix": "id", "http": {"method": "POST", "path": "/path/to/resource", "protocol": "HTTP/1.1", "sourceIp": "192.168.0.1/32", "userAgent": "agent"}, "requestId": "id", "routeKey": "$default", "stage": "$default"}, "body": 10, "pathParameters": {"parameter1": "value1"}, "isBase64Encoded": true, "stageVariables": {"stageVariable1": "value1", "stageVariable2": "value2"}}
[moesif] cannot fetch default function_name and request_context from aws context, setting metadata to None.
[moesif] Time took in fetching metadata in millisecond - 0.019
[moesif] Time took in fetching user id in millisecond - 0.002
[moesif] Time took in identifying the user in millisecond - 0.012
[moesif] Time took in fetching company id in millisecond - 0.001
[moesif] Time took in identifying the company in millisecond - 0.009000000000000001
[moesif] cannot execute GET_API_VERSION function, please check moesif settings.
'dict' object has no attribute 'function_version'
[moesif] Time took before the handler is invoked in millisecond - 0.319
[moesif] : [after] Moesif Event Model:
{"version": "2.0", "routeKey": "$default", "rawPath": "/path/to/resource", "rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value", "cookies": ["cookie1", "cookie2"], "headers": {"Header1": "value1", "Header2": "value1,value2"}, "queryStringParameters": {"parameter1": "value1,value2", "parameter2": "value"}, "requestContext": {"accountId": "123456789012", "apiId": "api-id", "authentication": {"clientCert": {"clientCertPem": "CERT_CONTENT", "subjectDN": "www.example.com", "issuerDN": "Example issuer", "serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1", "validity": {"notBefore": "May 28 12:30:02 2019 GMT", "notAfter": "Aug  5 09:36:04 2021 GMT"}}}, "authorizer": {"jwt": {"claims": {"claim1": "value1", "claim2": "value2"}, "scopes": ["scope1", "scope2"]}}, "domainName": "id.execute-api.us-east-1.amazonaws.com", "domainPrefix": "id", "http": {"method": "POST", "path": "/path/to/resource", "protocol": "HTTP/1.1", "sourceIp": "192.168.0.1/32", "userAgent": "agent"}, "requestId": "id", "routeKey": "$default", "stage": "$default"}, "body": 10, "pathParameters": {"parameter1": "value1"}, "isBase64Encoded": true, "stageVariables": {"stageVariable1": "value1", "stageVariable2": "value2"}}
[moesif] Time took after the handler is invoked in millisecond - 614.518
[moesif] : [before] Incoming Event:
{"version": "2.0", "routeKey": "$default", "rawPath": "/path/to/resource", "rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value", "cookies": ["cookie1", "cookie2"], "headers": {"Header1": "value1", "Header2": "value1,value2"}, "queryStringParameters": {"parameter1": "value1,value2", "parameter2": "value"}, "requestContext": {"accountId": "123456789012", "apiId": "api-id", "authentication": {"clientCert": {"clientCertPem": "CERT_CONTENT", "subjectDN": "www.example.com", "issuerDN": "Example issuer", "serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1", "validity": {"notBefore": "May 28 12:30:02 2019 GMT", "notAfter": "Aug  5 09:36:04 2021 GMT"}}}, "authorizer": {"jwt": {"claims": {"claim1": "value1", "claim2": "value2"}, "scopes": ["scope1", "scope2"]}}, "domainName": "id.execute-api.us-east-1.amazonaws.com", "domainPrefix": "id", "http": {"method": "POST", "path": "/path/to/resource", "protocol": "HTTP/1.1", "sourceIp": "192.168.0.1/32", "userAgent": "agent"}, "requestId": "id", "routeKey": "$default", "stage": "$default"}, "body": "{'foo': 'bar'}", "pathParameters": {"parameter1": "value1"}, "isBase64Encoded": true, "stageVariables": {"stageVariable1": "value1", "stageVariable2": "value2"}}
[moesif] cannot fetch default function_name and request_context from aws context, setting metadata to None.
[moesif] Time took in fetching metadata in millisecond - 0.02
[moesif] Time took in fetching user id in millisecond - 0.003
[moesif] Time took in identifying the user in millisecond - 0.012
[moesif] Time took in fetching company id in millisecond - 0.001
[moesif] Time took in identifying the company in millisecond - 0.01
[moesif] cannot execute GET_API_VERSION function, please check moesif settings.
'dict' object has no attribute 'function_version'
[moesif] Time took before the handler is invoked in millisecond - 0.361
[moesif] : [after] Moesif Event Model:
{"version": "2.0", "routeKey": "$default", "rawPath": "/path/to/resource", "rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value", "cookies": ["cookie1", "cookie2"], "headers": {"Header1": "value1", "Header2": "value1,value2"}, "queryStringParameters": {"parameter1": "value1,value2", "parameter2": "value"}, "requestContext": {"accountId": "123456789012", "apiId": "api-id", "authentication": {"clientCert": {"clientCertPem": "CERT_CONTENT", "subjectDN": "www.example.com", "issuerDN": "Example issuer", "serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1", "validity": {"notBefore": "May 28 12:30:02 2019 GMT", "notAfter": "Aug  5 09:36:04 2021 GMT"}}}, "authorizer": {"jwt": {"claims": {"claim1": "value1", "claim2": "value2"}, "scopes": ["scope1", "scope2"]}}, "domainName": "id.execute-api.us-east-1.amazonaws.com", "domainPrefix": "id", "http": {"method": "POST", "path": "/path/to/resource", "protocol": "HTTP/1.1", "sourceIp": "192.168.0.1/32", "userAgent": "agent"}, "requestId": "id", "routeKey": "$default", "stage": "$default"}, "body": "{'foo': 'bar'}", "pathParameters": {"parameter1": "value1"}, "isBase64Encoded": true, "stageVariables": {"stageVariable1": "value1", "stageVariable2": "value2"}}
[moesif] Time took after the handler is invoked in millisecond - 577.4399999999999
.
----------------------------------------------------------------------
Ran 1 test in 1.803s

OK

TestStrIsBase64.test_valid_base64_encoded_str

[moesif] start init - config
[moesif] end init - config
test_valid_base64_encoded_str (moesif_aws_lambda.tests.tests.TestStrIsBase64)
Tests that `is_str_base64` returns `True` for a valid base64-encoded ... ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

TestStrIsBase64.test_invalid_base64_encoded_str

[moesif] start init - config
[moesif] end init - config
test_invalid_base64_encoded_str (moesif_aws_lambda.tests.tests.TestStrIsBase64)
Tests that `is_str_base64` returns `False` for an invalid base64-encoded ... ok

----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

TestProcessBody.test_response_with_json_body

[moesif] start init - config
[moesif] end init - config
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

TestProcessBody.test_response_with_b64_body

[moesif] start init - config
[moesif] end init - config
.
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

Portal screenshots

For TestProcessBody.test_request_with_valid_base64_body

See screenshots

image

image

For TestProcessBody.test_request_with_invalid_base64_body_types

Just request screenshots since responses are the same.

See screenshots

image

image

image

@praves77
Copy link

@selectiveduplicate please include test results also, like:

  1. screenshot
  2. logs

@xinghengwang xinghengwang requested a review from keyur9 September 27, 2024 16:41
@xinghengwang
Copy link
Member

@keyur9 this is python. please take a look.

@selectiveduplicate
Copy link
Contributor Author

selectiveduplicate commented Sep 27, 2024

@praves77 I think I've found a better way to write the tests so we can more of what's going on. Included the local test results in the PR description with DEBUG enabled in Moesif.

@praves77
Copy link

praves77 commented Oct 1, 2024

@keyur9

Copy link
Member

@keyur9 keyur9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@praves77 praves77 merged commit f231c10 into master Oct 31, 2024
2 checks passed
@praves77 praves77 deleted the base64-check branch October 31, 2024 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants