Skip to content
Snippets Groups Projects
Commit 8e7e1f9d authored by Zdeněk Sedláček's avatar Zdeněk Sedláček
Browse files

Merge branch 'showcase-develop' into 'develop'

added auth headers to showcase

See merge request xpitak/PA165-Banking-System!29
parents c59382a7 48c374b0
No related branches found
No related tags found
No related merge requests found
...@@ -34,11 +34,19 @@ class BankingUser(HttpUser): ...@@ -34,11 +34,19 @@ class BankingUser(HttpUser):
host = f"http://{managementHost}:8080" host = f"http://{managementHost}:8080"
customer_token = "" customer_token = ""
employee_token = "" employee_token = ""
customer_header = {}
employee_header = {}
wait_time = between(1, 3) wait_time = between(1, 3)
def on_start(self): def on_start(self):
self.customer_token = self.environment.parsed_options.customer_token self.customer_token = self.environment.parsed_options.customer_token
self.employee_token = self.environment.parsed_options.employee_token self.employee_token = self.environment.parsed_options.employee_token
self.customer_header = {
"Authorization": f"Bearer {self.customer_token}"
}
self.employee_header = {
"Authorization": f"Bearer {self.employee_token}"
}
print(f"CUSTOMER TOKEN: {self.customer_token}") print(f"CUSTOMER TOKEN: {self.customer_token}")
print(f"EMPLOYEE TOKEN: {self.employee_token}") print(f"EMPLOYEE TOKEN: {self.employee_token}")
...@@ -52,7 +60,7 @@ class BankingUser(HttpUser): ...@@ -52,7 +60,7 @@ class BankingUser(HttpUser):
"lastName": "Anderson", "lastName": "Anderson",
"userType": "REGULAR" "userType": "REGULAR"
} }
response = self.client.post("/user", json=user_data) response = self.client.post("/user", json=user_data, headers=self.employee_header)
if response.status_code == 201: if response.status_code == 201:
self.user_id = response.json()["id"] self.user_id = response.json()["id"]
else: else:
...@@ -65,7 +73,7 @@ class BankingUser(HttpUser): ...@@ -65,7 +73,7 @@ class BankingUser(HttpUser):
"maxSpendingLimit": 1000, "maxSpendingLimit": 1000,
"currency": "USD" "currency": "USD"
} }
response = self.client.post("/account", json=account_data) response = self.client.post("/account", json=account_data, headers=self.employee_header)
if response.status_code == 201: if response.status_code == 201:
self.account1 = response.json() self.account1 = response.json()
else: else:
...@@ -78,14 +86,14 @@ class BankingUser(HttpUser): ...@@ -78,14 +86,14 @@ class BankingUser(HttpUser):
"maxSpendingLimit": 1000, "maxSpendingLimit": 1000,
"currency": "USD" "currency": "USD"
} }
response = self.client.post("/account", json=account_data) response = self.client.post("/account", json=account_data, headers=self.employee_header)
if response.status_code == 201: if response.status_code == 201:
self.account2 = response.json() self.account2 = response.json()
else: else:
raise Exception("Failed to create account2") raise Exception("Failed to create account2")
# check account balance # check account balance
assert(self.client.get(f"http://{queryHost}:8081/balance/status", params={"id":self.account1["number"]}).json() == 0) self.assert_balance(self.account1["number"], 0)
# deposit to account1 balance # deposit to account1 balance
deposit_data = { deposit_data = {
...@@ -95,7 +103,7 @@ class BankingUser(HttpUser): ...@@ -95,7 +103,7 @@ class BankingUser(HttpUser):
"type": "DEPOSIT" "type": "DEPOSIT"
} }
response = self.client.post(f"http://{queryHost}:8081/balance/add", params=deposit_data) response = self.client.post(f"http://{queryHost}:8081/balance/add", params=deposit_data, headers=self.customer_header)
if response.status_code != 200: if response.status_code != 200:
raise Exception("Failed to deposit money") raise Exception("Failed to deposit money")
...@@ -117,7 +125,7 @@ class BankingUser(HttpUser): ...@@ -117,7 +125,7 @@ class BankingUser(HttpUser):
}, },
"detail": "Transfer to savings account" "detail": "Transfer to savings account"
} }
response = self.client.put(f"http://{processHost}:8082/transaction/v1/process", json=payment_data) response = self.client.put(f"http://{processHost}:8082/transaction/v1/process", json=payment_data, headers=self.customer_header)
if response.status_code == 200: if response.status_code == 200:
transaction_id = response.json()["identifier"] transaction_id = response.json()["identifier"]
else: else:
...@@ -135,7 +143,7 @@ class BankingUser(HttpUser): ...@@ -135,7 +143,7 @@ class BankingUser(HttpUser):
"lastName": "Smith", "lastName": "Smith",
"userType": "EMPLOYEE" "userType": "EMPLOYEE"
} }
response = self.client.post("/user", json=employee_data) response = self.client.post("/user", json=employee_data, headers=self.employee_header)
if response.status_code == 201: if response.status_code == 201:
self.employee_id = response.json()["id"] self.employee_id = response.json()["id"]
else: else:
...@@ -143,11 +151,12 @@ class BankingUser(HttpUser): ...@@ -143,11 +151,12 @@ class BankingUser(HttpUser):
# revert transaction # revert transaction
revert_data = { revert_data = {
"x-process-uuid": transaction_id "x-process-uuid": transaction_id,
'Authorization': f"Bearer {self.employee_token}"
} }
response = self.client.post(f"http://{processHost}:8082/transaction/v1/revert", headers=revert_data) response = self.client.post(f"http://{processHost}:8082/transaction/v1/revert", headers=revert_data)
if response.status_code != 200: if response.status_code != 200:
raise Exception("Failed to revert transaction: "+str(transaction_id)) raise Exception("Failed to revert transaction")
# check account balances after transaction revert # check account balances after transaction revert
self.assert_balance(self.account1["number"], 500) self.assert_balance(self.account1["number"], 500)
...@@ -159,7 +168,7 @@ class BankingUser(HttpUser): ...@@ -159,7 +168,7 @@ class BankingUser(HttpUser):
"beginning": "2024-01-01", "beginning": "2024-01-01",
"end": "2024-12-31" "end": "2024-12-31"
} }
response = self.client.get(f"http://{queryHost}:8081/balance/account/report", params=report_data) response = self.client.get(f"http://{queryHost}:8081/balance/account/report", params=report_data, headers=self.employee_header)
if response.status_code != 200: if response.status_code != 200:
raise Exception("Failed to get account report: "+self.account1["number"]+str(response.content)) raise Exception("Failed to get account report: "+self.account1["number"]+str(response.content))
...@@ -167,7 +176,7 @@ class BankingUser(HttpUser): ...@@ -167,7 +176,7 @@ class BankingUser(HttpUser):
balance_data = { balance_data = {
"id": account_id "id": account_id
} }
response = self.client.get(f"http://{queryHost}:8081/balance/status", params=balance_data) response = self.client.get(f"http://{queryHost}:8081/balance/status", params=balance_data, headers=self.customer_header)
if response.status_code != 200: if response.status_code != 200:
raise Exception("Failed to get account balance") raise Exception("Failed to get account balance")
......
...@@ -75,8 +75,8 @@ public class TransactionProcessesService { ...@@ -75,8 +75,8 @@ public class TransactionProcessesService {
} }
Transaction revertingTransaction = new Transaction( Transaction revertingTransaction = new Transaction(
processTransaction.getTarget(),
processTransaction.getSource(), processTransaction.getSource(),
processTransaction.getTarget(),
TransactionType.REFUND, TransactionType.REFUND,
processTransaction.getMoney(), processTransaction.getMoney(),
String.format("Admin reversal of executed %s transaction {%s}", processTransaction.getType(), uuid) String.format("Admin reversal of executed %s transaction {%s}", processTransaction.getType(), uuid)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment