mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
feat: change admin api key auth to merchant api key auth in few connectors flow (#5572)
This commit is contained in:
@ -405,11 +405,16 @@ pub async fn connector_retrieve(
|
|||||||
state,
|
state,
|
||||||
&req,
|
&req,
|
||||||
payload,
|
payload,
|
||||||
|state, _, req, _| {
|
|state, auth, req, _| {
|
||||||
retrieve_connector(state, req.merchant_id, None, req.merchant_connector_id)
|
retrieve_connector(
|
||||||
|
state,
|
||||||
|
req.merchant_id,
|
||||||
|
auth.profile_id,
|
||||||
|
req.merchant_connector_id,
|
||||||
|
)
|
||||||
},
|
},
|
||||||
auth::auth_type(
|
auth::auth_type(
|
||||||
&auth::AdminApiAuth,
|
&auth::HeaderAuth(auth::ApiKeyAuth),
|
||||||
&auth::JWTAuthMerchantFromRoute {
|
&auth::JWTAuthMerchantFromRoute {
|
||||||
merchant_id,
|
merchant_id,
|
||||||
required_permission: Permission::MerchantConnectorAccountRead,
|
required_permission: Permission::MerchantConnectorAccountRead,
|
||||||
@ -518,9 +523,9 @@ pub async fn payment_connector_list(
|
|||||||
state,
|
state,
|
||||||
&req,
|
&req,
|
||||||
merchant_id.to_owned(),
|
merchant_id.to_owned(),
|
||||||
|state, _, merchant_id, _| list_payment_connectors(state, merchant_id, None),
|
|state, _auth, merchant_id, _| list_payment_connectors(state, merchant_id, None),
|
||||||
auth::auth_type(
|
auth::auth_type(
|
||||||
&auth::AdminApiAuth,
|
&auth::HeaderAuth(auth::ApiKeyAuth),
|
||||||
&auth::JWTAuthMerchantFromRoute {
|
&auth::JWTAuthMerchantFromRoute {
|
||||||
merchant_id,
|
merchant_id,
|
||||||
required_permission: Permission::MerchantConnectorAccountRead,
|
required_permission: Permission::MerchantConnectorAccountRead,
|
||||||
@ -570,9 +575,17 @@ pub async fn connector_update(
|
|||||||
state,
|
state,
|
||||||
&req,
|
&req,
|
||||||
json_payload.into_inner(),
|
json_payload.into_inner(),
|
||||||
|state, _, req, _| update_connector(state, &merchant_id, None, &merchant_connector_id, req),
|
|state, auth, req, _| {
|
||||||
|
update_connector(
|
||||||
|
state,
|
||||||
|
&merchant_id,
|
||||||
|
auth.profile_id,
|
||||||
|
&merchant_connector_id,
|
||||||
|
req,
|
||||||
|
)
|
||||||
|
},
|
||||||
auth::auth_type(
|
auth::auth_type(
|
||||||
&auth::AdminApiAuth,
|
&auth::HeaderAuth(auth::ApiKeyAuth),
|
||||||
&auth::JWTAuthMerchantFromRoute {
|
&auth::JWTAuthMerchantFromRoute {
|
||||||
merchant_id: merchant_id.clone(),
|
merchant_id: merchant_id.clone(),
|
||||||
required_permission: Permission::MerchantConnectorAccountWrite,
|
required_permission: Permission::MerchantConnectorAccountWrite,
|
||||||
|
|||||||
@ -484,7 +484,7 @@ Cypress.Commands.add("connectorRetrieveCall", (globalState) => {
|
|||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"api-key": globalState.get("adminApiKey"),
|
"api-key": globalState.get("apiKey"),
|
||||||
},
|
},
|
||||||
failOnStatusCode: false,
|
failOnStatusCode: false,
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
@ -530,7 +530,7 @@ Cypress.Commands.add(
|
|||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"api-key": globalState.get("adminApiKey"),
|
"api-key": globalState.get("apiKey"),
|
||||||
},
|
},
|
||||||
body: updateConnectorBody,
|
body: updateConnectorBody,
|
||||||
failOnStatusCode: false,
|
failOnStatusCode: false,
|
||||||
@ -554,7 +554,7 @@ Cypress.Commands.add("connectorListByMid", (globalState) => {
|
|||||||
url: `${globalState.get("baseUrl")}/account/${merchant_id}/connectors`,
|
url: `${globalState.get("baseUrl")}/account/${merchant_id}/connectors`,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"api-key": globalState.get("adminApiKey"),
|
"api-key": globalState.get("apiKey"),
|
||||||
},
|
},
|
||||||
failOnStatusCode: false,
|
failOnStatusCode: false,
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
@ -2060,7 +2060,7 @@ Cypress.Commands.add("ListMCAbyMID", (globalState) => {
|
|||||||
url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`,
|
url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"api-key": globalState.get("adminApiKey"),
|
"api-key": globalState.get("apiKey"),
|
||||||
},
|
},
|
||||||
failOnStatusCode: false,
|
failOnStatusCode: false,
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"childrenOrder": [
|
"childrenOrder": [
|
||||||
|
"API Key - Create",
|
||||||
"Payment Connector - Create",
|
"Payment Connector - Create",
|
||||||
"Payment Connector - Retrieve",
|
"Payment Connector - Retrieve",
|
||||||
"Payment Connector - Update",
|
"Payment Connector - Update",
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"eventOrder": ["event.test.js"]
|
||||||
|
}
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
// Validate status 2xx
|
||||||
|
pm.test("[POST]::/api_keys/:merchant_id - Status code is 2xx", function () {
|
||||||
|
pm.response.to.be.success;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Validate if response header has matching content-type
|
||||||
|
pm.test(
|
||||||
|
"[POST]::/api_keys/:merchant_id - Content-Type is application/json",
|
||||||
|
function () {
|
||||||
|
pm.expect(pm.response.headers.get("Content-Type")).to.include(
|
||||||
|
"application/json",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set response object as internal variable
|
||||||
|
let jsonData = {};
|
||||||
|
try {
|
||||||
|
jsonData = pm.response.json();
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
// pm.collectionVariables - Set api_key_id as variable for jsonData.key_id
|
||||||
|
if (jsonData?.key_id) {
|
||||||
|
pm.collectionVariables.set("api_key_id", jsonData.key_id);
|
||||||
|
console.log(
|
||||||
|
"- use {{api_key_id}} as collection variable for value",
|
||||||
|
jsonData.key_id,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
"INFO - Unable to assign variable {{api_key_id}}, as jsonData.key_id is undefined.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// pm.collectionVariables - Set api_key as variable for jsonData.api_key
|
||||||
|
if (jsonData?.api_key) {
|
||||||
|
pm.collectionVariables.set("api_key", jsonData.api_key);
|
||||||
|
console.log(
|
||||||
|
"- use {{api_key}} as collection variable for value",
|
||||||
|
jsonData.api_key,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
"INFO - Unable to assign variable {{api_key}}, as jsonData.api_key is undefined.",
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"auth": {
|
||||||
|
"type": "apikey",
|
||||||
|
"apikey": [
|
||||||
|
{
|
||||||
|
"key": "value",
|
||||||
|
"value": "{{admin_api_key}}",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "key",
|
||||||
|
"value": "api-key",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"method": "POST",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Content-Type",
|
||||||
|
"value": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw_json_formatted": {
|
||||||
|
"name": "API Key 1",
|
||||||
|
"description": null,
|
||||||
|
"expiration": "2069-09-23T01:02:03.000Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "{{baseUrl}}/api_keys/:merchant_id",
|
||||||
|
"host": ["{{baseUrl}}"],
|
||||||
|
"path": ["api_keys", ":merchant_id"],
|
||||||
|
"variable": [
|
||||||
|
{
|
||||||
|
"key": "merchant_id",
|
||||||
|
"value": "{{merchant_id}}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
[]
|
||||||
@ -4,7 +4,7 @@
|
|||||||
"apikey": [
|
"apikey": [
|
||||||
{
|
{
|
||||||
"key": "value",
|
"key": "value",
|
||||||
"value": "{{admin_api_key}}",
|
"value": "{{api_key}}",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
"apikey": [
|
"apikey": [
|
||||||
{
|
{
|
||||||
"key": "value",
|
"key": "value",
|
||||||
"value": "{{admin_api_key}}",
|
"value": "{{api_key}}",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
"apikey": [
|
"apikey": [
|
||||||
{
|
{
|
||||||
"key": "value",
|
"key": "value",
|
||||||
"value": "{{admin_api_key}}",
|
"value": "{{api_key}}",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
"apikey": [
|
"apikey": [
|
||||||
{
|
{
|
||||||
"key": "value",
|
"key": "value",
|
||||||
"value": "{{admin_api_key}}",
|
"value": "{{api_key}}",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1348,6 +1348,115 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "API Key - Create",
|
||||||
|
"event": [
|
||||||
|
{
|
||||||
|
"listen": "test",
|
||||||
|
"script": {
|
||||||
|
"exec": [
|
||||||
|
"// Validate status 2xx",
|
||||||
|
"pm.test(\"[POST]::/api_keys/:merchant_id - Status code is 2xx\", function () {",
|
||||||
|
" pm.response.to.be.success;",
|
||||||
|
"});",
|
||||||
|
"",
|
||||||
|
"// Validate if response header has matching content-type",
|
||||||
|
"pm.test(",
|
||||||
|
" \"[POST]::/api_keys/:merchant_id - Content-Type is application/json\",",
|
||||||
|
" function () {",
|
||||||
|
" pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(",
|
||||||
|
" \"application/json\",",
|
||||||
|
" );",
|
||||||
|
" },",
|
||||||
|
");",
|
||||||
|
"",
|
||||||
|
"// Set response object as internal variable",
|
||||||
|
"let jsonData = {};",
|
||||||
|
"try {",
|
||||||
|
" jsonData = pm.response.json();",
|
||||||
|
"} catch (e) {}",
|
||||||
|
"",
|
||||||
|
"// pm.collectionVariables - Set api_key_id as variable for jsonData.key_id",
|
||||||
|
"if (jsonData?.key_id) {",
|
||||||
|
" pm.collectionVariables.set(\"api_key_id\", jsonData.key_id);",
|
||||||
|
" console.log(",
|
||||||
|
" \"- use {{api_key_id}} as collection variable for value\",",
|
||||||
|
" jsonData.key_id,",
|
||||||
|
" );",
|
||||||
|
"} else {",
|
||||||
|
" console.log(",
|
||||||
|
" \"INFO - Unable to assign variable {{api_key_id}}, as jsonData.key_id is undefined.\",",
|
||||||
|
" );",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"// pm.collectionVariables - Set api_key as variable for jsonData.api_key",
|
||||||
|
"if (jsonData?.api_key) {",
|
||||||
|
" pm.collectionVariables.set(\"api_key\", jsonData.api_key);",
|
||||||
|
" console.log(",
|
||||||
|
" \"- use {{api_key}} as collection variable for value\",",
|
||||||
|
" jsonData.api_key,",
|
||||||
|
" );",
|
||||||
|
"} else {",
|
||||||
|
" console.log(",
|
||||||
|
" \"INFO - Unable to assign variable {{api_key}}, as jsonData.api_key is undefined.\",",
|
||||||
|
" );",
|
||||||
|
"}",
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"type": "text/javascript"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"request": {
|
||||||
|
"auth": {
|
||||||
|
"type": "apikey",
|
||||||
|
"apikey": [
|
||||||
|
{
|
||||||
|
"key": "value",
|
||||||
|
"value": "{{admin_api_key}}",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "key",
|
||||||
|
"value": "api-key",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"method": "POST",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Content-Type",
|
||||||
|
"value": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\"name\":\"API Key 1\",\"description\":null,\"expiration\":\"2069-09-23T01:02:03.000Z\"}"
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "{{baseUrl}}/api_keys/:merchant_id",
|
||||||
|
"host": [
|
||||||
|
"{{baseUrl}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api_keys",
|
||||||
|
":merchant_id"
|
||||||
|
],
|
||||||
|
"variable": [
|
||||||
|
{
|
||||||
|
"key": "merchant_id",
|
||||||
|
"value": "{{merchant_id}}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Payment Connector - Create",
|
"name": "Payment Connector - Create",
|
||||||
"event": [
|
"event": [
|
||||||
@ -1528,7 +1637,7 @@
|
|||||||
"apikey": [
|
"apikey": [
|
||||||
{
|
{
|
||||||
"key": "value",
|
"key": "value",
|
||||||
"value": "{{admin_api_key}}",
|
"value": "{{api_key}}",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1643,7 +1752,7 @@
|
|||||||
"apikey": [
|
"apikey": [
|
||||||
{
|
{
|
||||||
"key": "value",
|
"key": "value",
|
||||||
"value": "{{admin_api_key}}",
|
"value": "{{api_key}}",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1740,7 +1849,7 @@
|
|||||||
"apikey": [
|
"apikey": [
|
||||||
{
|
{
|
||||||
"key": "value",
|
"key": "value",
|
||||||
"value": "{{admin_api_key}}",
|
"value": "{{api_key}}",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -2575,7 +2684,7 @@
|
|||||||
"apikey": [
|
"apikey": [
|
||||||
{
|
{
|
||||||
"key": "value",
|
"key": "value",
|
||||||
"value": "{{admin_api_key}}",
|
"value": "{{api_key}}",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user