Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ $RECYCLE.BIN/
**/*.swo
**/.env.local

# Credentials files
.github/test/creds.json

# DrawIO files
**/*.drawio.bkp
gen/**
23 changes: 12 additions & 11 deletions backend/grpc-server/tests/aci_payment_flows_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#![allow(clippy::panic)]

use grpc_server::{app, configs};
use hyperswitch_masking::{ExposeInterface, Secret};
mod common;
mod utils;

use std::{
collections::HashMap,
env,
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};
Expand All @@ -26,16 +27,11 @@ use grpc_api_types::{
PaymentServiceVoidRequest, PaymentStatus, RefundStatus,
},
};
use hyperswitch_masking::Secret;
use tonic::{transport::Channel, Request};

// Constants for aci connector
const CONNECTOR_NAME: &str = "aci";

// Environment variable names for API credentials
const TEST_ACI_API_KEY_ENV: &str = "TEST_ACI_API_KEY";
const TEST_ACI_KEY1_ENV: &str = "TEST_ACI_KEY1";

const TEST_AMOUNT: i64 = 1000;
const TEST_CARD_NUMBER: &str = "4111111111111111";
const TEST_CARD_EXP_MONTH: &str = "10";
Expand All @@ -54,11 +50,16 @@ fn get_timestamp() -> u64 {

// Helper function to add aci metadata headers to a request
fn add_aci_metadata<T>(request: &mut Request<T>) {
// Get API credentials from environment variables
let api_key = env::var(TEST_ACI_API_KEY_ENV)
.unwrap_or_else(|_| panic!("Environment variable TEST_ACI_API_KEY_ENV must be set"));
let key1 = env::var(TEST_ACI_KEY1_ENV)
.unwrap_or_else(|_| panic!("Environment variable TEST_ACI_KEY1_ENV must be set"));
// Get API credentials using the common credential loading utility
let auth = utils::credential_utils::load_connector_auth(CONNECTOR_NAME)
.expect("Failed to load ACI credentials");

let (api_key, key1) = match auth {
domain_types::router_data::ConnectorAuthType::BodyKey { api_key, key1 } => {
(api_key.expose(), key1.expose())
}
_ => panic!("Expected BodyKey auth type for ACI"),
};

request.metadata_mut().append(
"x-connector",
Expand Down
18 changes: 13 additions & 5 deletions backend/grpc-server/tests/adyen_dispute_webhook_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![allow(clippy::expect_used)]

use grpc_server::{app, configs};
use hyperswitch_masking::ExposeInterface;
mod common;
mod utils;
use grpc_api_types::payments::{
payment_service_client::PaymentServiceClient,
webhook_response_content::Content as GrpcWebhookContent, DisputeStage as GrpcDisputeStage,
Expand Down Expand Up @@ -81,11 +83,17 @@ async fn process_webhook_and_get_response(
state: None,
});

let api_key = std::env::var("API_KEY").unwrap_or_else(|_| "test_adyen_api_key".to_string());
let key1 =
std::env::var("ADYEN_MERCHANT_ACCOUNT").unwrap_or_else(|_| "test_merchant_acc".to_string());
let api_secret =
std::env::var("ADYEN_WEBHOOK_HMAC_KEY").unwrap_or_else(|_| "test_hmac_key".to_string());
let auth = utils::credential_utils::load_connector_auth("adyen")
.expect("Failed to load adyen credentials");

let (api_key, key1, api_secret) = match auth {
domain_types::router_data::ConnectorAuthType::SignatureKey {
api_key,
key1,
api_secret,
} => (api_key.expose(), key1.expose(), api_secret.expose()),
_ => panic!("Expected SignatureKey auth type for adyen"),
};

request.metadata_mut().append(
"x-connector",
Expand Down
27 changes: 13 additions & 14 deletions backend/grpc-server/tests/authorizedotnet_payment_flows_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#![allow(dead_code)]

use grpc_server::{app, configs};
use hyperswitch_masking::Secret;
use hyperswitch_masking::{ExposeInterface, Secret};
mod common;
mod utils;

use std::{
any::Any,
collections::HashMap,
env,
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};
Expand Down Expand Up @@ -47,12 +47,6 @@ fn random_name() -> String {
// Constants for AuthorizeDotNet connector
const CONNECTOR_NAME: &str = "authorizedotnet";

// Environment variable names for API credentials (can be set or overridden with provided values)
const AUTHORIZENET_API_KEY_ENV: &str = "AUTHORIZENET_API_KEY";
const AUTHORIZENET_KEY1_ENV: &str = "AUTHORIZENET_KEY1";

// No default values - environment variables are required

// Test card data matching working grpcurl payload
const TEST_AMOUNT: i64 = 102; // Amount from working grpcurl
const TEST_CARD_NUMBER: &str = "5123456789012346"; // Mastercard from working grpcurl
Expand Down Expand Up @@ -91,11 +85,16 @@ fn generate_unique_request_ref_id(prefix: &str) -> String {

// Helper function to add AuthorizeDotNet metadata headers to a request
fn add_authorizenet_metadata<T>(request: &mut Request<T>) {
// Get API credentials from environment variables (required)
let api_key = env::var(AUTHORIZENET_API_KEY_ENV)
.expect("AUTHORIZENET_API_KEY environment variable must be set to run tests");
let key1 = env::var(AUTHORIZENET_KEY1_ENV)
.expect("AUTHORIZENET_KEY1 environment variable must be set to run tests");
// Get API credentials using the common credential loading utility
let auth = utils::credential_utils::load_connector_auth(CONNECTOR_NAME)
.expect("Failed to load Authorize.Net credentials");

let (api_key, key1) = match auth {
domain_types::router_data::ConnectorAuthType::BodyKey { api_key, key1 } => {
(api_key.expose(), key1.expose())
}
_ => panic!("Expected BodyKey auth type for Authorize.Net"),
};

request.metadata_mut().append(
"x-connector",
Expand Down Expand Up @@ -447,7 +446,7 @@ fn create_void_request(transaction_id: &str) -> PaymentServiceVoidRequest {
all_keys_required: None,
browser_info: None,
amount: None,
currency: None,
currency: Some(146),
..Default::default()
}
}
Expand Down
103 changes: 77 additions & 26 deletions backend/grpc-server/tests/authorizedotnet_webhook_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![allow(clippy::expect_used, clippy::indexing_slicing)]

use grpc_server::{app, configs};
use hyperswitch_masking::ExposeInterface;
mod common;
mod utils;
use std::fmt::Write;

use common_utils::crypto::{HmacSha512, SignMessage};
Expand Down Expand Up @@ -149,17 +151,19 @@ async fn process_webhook_request(

let mut headers = std::collections::HashMap::new();

// Get webhook_secret from metadata
let metadata = utils::credential_utils::load_connector_metadata("authorizedotnet")
.expect("Failed to load authorizedotnet metadata");
let webhook_secret = metadata
.get("webhook_secret")
.expect("webhook_secret not found in authorizedotnet metadata")
.clone();

if include_signature {
let webhook_secret = std::env::var("AUTHORIZEDOTNET_WEBHOOK_SECRET")
.unwrap_or_else(|_| "test_webhook_secret".to_string());
let signature = generate_webhook_signature(&request_body_bytes, &webhook_secret);
headers.insert("X-ANET-Signature".to_string(), signature);
}

// Add webhook secrets to the request
let webhook_secret = std::env::var("AUTHORIZEDOTNET_WEBHOOK_SECRET")
.unwrap_or_else(|_| "test_webhook_secret".to_string());

let webhook_secrets = Some(grpc_api_types::payments::WebhookSecrets {
secret: webhook_secret.clone(),
additional_secret: None,
Expand All @@ -183,9 +187,15 @@ async fn process_webhook_request(
});

// Use the same metadata pattern as the payment flows test
let api_key =
std::env::var("AUTHORIZENET_API_KEY").unwrap_or_else(|_| "test_api_key".to_string());
let key1 = std::env::var("AUTHORIZENET_KEY1").unwrap_or_else(|_| "test_key1".to_string());
let auth = utils::credential_utils::load_connector_auth("authorizedotnet")
.expect("Failed to load authorizedotnet credentials");

let (api_key, key1) = match auth {
domain_types::router_data::ConnectorAuthType::BodyKey { api_key, key1 } => {
(api_key.expose(), key1.expose())
}
_ => panic!("Expected BodyKey auth type for authorizedotnet"),
};

request.metadata_mut().append(
"x-connector",
Expand Down Expand Up @@ -735,10 +745,23 @@ async fn test_webhook_malformed_body() {
state: None,
});

let api_key =
std::env::var("AUTHORIZEDOTNET_API_KEY").unwrap_or_else(|_| "test_api_key".to_string());
let transaction_key = std::env::var("AUTHORIZEDOTNET_TRANSACTION_KEY")
.unwrap_or_else(|_| "test_transaction_key".to_string());
let auth = utils::credential_utils::load_connector_auth("authorizedotnet")
.expect("Failed to load authorizedotnet credentials");

let api_key = match auth {
domain_types::router_data::ConnectorAuthType::BodyKey { api_key, .. } => {
api_key.expose()
}
_ => panic!("Expected BodyKey auth type for authorizedotnet"),
};

// Get transaction_key from metadata
let metadata = utils::credential_utils::load_connector_metadata("authorizedotnet")
.expect("Failed to load authorizedotnet metadata");
let transaction_key = metadata
.get("transaction_key")
.expect("transaction_key not found in authorizedotnet metadata")
.clone();

request.metadata_mut().append(
"x-connector",
Expand Down Expand Up @@ -965,8 +988,13 @@ async fn test_webhook_source_verification_invalid_signature() {
"sha512=invalidhexsignature".to_string(),
);

let webhook_secret = std::env::var("AUTHORIZEDOTNET_WEBHOOK_SECRET")
.unwrap_or_else(|_| "test_webhook_secret".to_string());
// Get webhook_secret from metadata
let metadata = utils::credential_utils::load_connector_metadata("authorizedotnet")
.expect("Failed to load authorizedotnet metadata");
let webhook_secret = metadata
.get("webhook_secret")
.expect("webhook_secret not found in authorizedotnet metadata")
.clone();

let webhook_secrets = Some(grpc_api_types::payments::WebhookSecrets {
secret: webhook_secret.clone(),
Expand All @@ -990,9 +1018,15 @@ async fn test_webhook_source_verification_invalid_signature() {
state: None,
});

let api_key =
std::env::var("AUTHORIZENET_API_KEY").unwrap_or_else(|_| "test_api_key".to_string());
let key1 = std::env::var("AUTHORIZENET_KEY1").unwrap_or_else(|_| "test_key1".to_string());
let auth = utils::credential_utils::load_connector_auth("authorizedotnet")
.expect("Failed to load authorizedotnet credentials");

let (api_key, key1) = match auth {
domain_types::router_data::ConnectorAuthType::BodyKey { api_key, key1 } => {
(api_key.expose(), key1.expose())
}
_ => panic!("Expected BodyKey auth type for authorizedotnet"),
};

request.metadata_mut().append(
"x-connector",
Expand Down Expand Up @@ -1062,8 +1096,13 @@ async fn test_webhook_source_verification_missing_signature() {
// Don't add any signature header
let headers = std::collections::HashMap::new();

let webhook_secret = std::env::var("AUTHORIZEDOTNET_WEBHOOK_SECRET")
.unwrap_or_else(|_| "test_webhook_secret".to_string());
// Get webhook_secret from metadata
let metadata = utils::credential_utils::load_connector_metadata("authorizedotnet")
.expect("Failed to load authorizedotnet metadata");
let webhook_secret = metadata
.get("webhook_secret")
.expect("webhook_secret not found in authorizedotnet metadata")
.clone();

let webhook_secrets = Some(grpc_api_types::payments::WebhookSecrets {
secret: webhook_secret.clone(),
Expand All @@ -1087,9 +1126,15 @@ async fn test_webhook_source_verification_missing_signature() {
state: None,
});

let api_key =
std::env::var("AUTHORIZENET_API_KEY").unwrap_or_else(|_| "test_api_key".to_string());
let key1 = std::env::var("AUTHORIZENET_KEY1").unwrap_or_else(|_| "test_key1".to_string());
let auth = utils::credential_utils::load_connector_auth("authorizedotnet")
.expect("Failed to load authorizedotnet credentials");

let (api_key, key1) = match auth {
domain_types::router_data::ConnectorAuthType::BodyKey { api_key, key1 } => {
(api_key.expose(), key1.expose())
}
_ => panic!("Expected BodyKey auth type for authorizedotnet"),
};

request.metadata_mut().append(
"x-connector",
Expand Down Expand Up @@ -1182,9 +1227,15 @@ async fn test_webhook_source_verification_no_secret_provided() {
state: None,
});

let api_key =
std::env::var("AUTHORIZENET_API_KEY").unwrap_or_else(|_| "test_api_key".to_string());
let key1 = std::env::var("AUTHORIZENET_KEY1").unwrap_or_else(|_| "test_key1".to_string());
let auth = utils::credential_utils::load_connector_auth("authorizedotnet")
.expect("Failed to load authorizedotnet credentials");

let (api_key, key1) = match auth {
domain_types::router_data::ConnectorAuthType::BodyKey { api_key, key1 } => {
(api_key.expose(), key1.expose())
}
_ => panic!("Expected BodyKey auth type for authorizedotnet"),
};

request.metadata_mut().append(
"x-connector",
Expand Down
Loading
Loading