-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Jose JWE with certificates (#317)
- Loading branch information
1 parent
efb476f
commit 1034191
Showing
3 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
larky/src/test/resources/quick_tests/test_customer_usecase.star
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
load("@stdlib//larky", "larky") | ||
load("@stdlib//unittest","unittest") | ||
load("@stdlib//json","json") | ||
load("@stdlib//types", "types") | ||
load("@stdlib//builtins", builtins="builtins") | ||
|
||
load("@vendor//asserts","asserts") | ||
|
||
load("@vgs//http/request", "VGSHttpRequest") | ||
|
||
def process(input_http, ctx): | ||
# Extract card BIN and add it to the body | ||
body = json.loads(input_http.body.decode("utf-8")) | ||
BIN = body['cardNumber'][:6] | ||
body['BIN'] = BIN | ||
|
||
# Add the BIN to the headers and change the X-Custom-Header | ||
headers = input_http.headers | ||
headers['X-BIN-Header'] = BIN | ||
headers['X-Custom-Header'] = "I am a changed header" | ||
|
||
# Set the body as builtins.bytes of the updated body and update the headers | ||
input_http.body = builtins.bytes(json.dumps(body)) | ||
input_http.headers = headers | ||
|
||
return input_http | ||
|
||
def test_customer_case(): | ||
req_body = b'{"cardNumber": "4111111111111111"}' | ||
headers = {"X-Custom-Header":"Header Value"} | ||
request = VGSHttpRequest("http://example.com", data=req_body, headers=headers, method='POST') | ||
context_variables = {} | ||
larky_output = process(request, context_variables) | ||
|
||
body = json.loads(larky_output._data.decode("utf-8")) | ||
headers = larky_output.headers | ||
|
||
# Test that the code has executed properly on your request | ||
asserts.assert_that(body['BIN']).is_equal_to("411111") | ||
asserts.assert_that(headers['X-Custom-Header']).is_equal_to("I am a changed header") | ||
asserts.assert_that(headers['X-BIN-Header']).is_equal_to("411111") | ||
|
||
|
||
def _testsuite(): | ||
_suite = unittest.TestSuite() | ||
_suite.addTest(unittest.FunctionTestCase(test_customer_case)) | ||
return _suite | ||
|
||
|
||
_runner = unittest.TextTestRunner() | ||
_runner.run(_testsuite()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters