Skip to content

Commit cf454fc

Browse files
committed
test(destination): add DestinationHttpClient integration test
1 parent b50794c commit cf454fc

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

tests/destination/integration/destination.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ Feature: Destination Service Integration
227227
# And I clean up the instance destination "test-v2-full-options"
228228
# And I clean up the instance fragment "test-v2-full-fragment"
229229

230+
Scenario: DestinationHttpClient sends an authenticated request using token fetched from BTP
231+
Given I have a destination named "sdk-test-http-client" of type "HTTP"
232+
And the destination has URL "https://httpbin.org"
233+
And the destination has authentication "OAuth2ClientCredentials"
234+
And the destination has OAuth2 credentials from environment
235+
When I create the destination at instance level
236+
Then the destination creation should be successful
237+
When I fetch the destination using the v2 API
238+
And I create a DestinationHttpClient from the destination
239+
And I send a GET request to "/headers"
240+
Then the response contains an Authorization header
241+
And I clean up the instance destination "sdk-test-http-client"
242+
230243
Scenario: Manage labels for subaccount destination
231244
Given I have a destination named "test-dest-labels" of type "HTTP"
232245
And the destination has URL "https://labels.example.com"
@@ -303,3 +316,4 @@ Feature: Destination Service Integration
303316
# Then the destination creation should be successful
304317
# When I get subaccount destination "test-dest-sub-isolation" with "PROVIDER_ONLY" access strategy
305318
# Then the destination should not be found
319+

tests/destination/integration/test_destination_bdd.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""BDD step definitions for Destination integration tests."""
22

33
import concurrent.futures
4+
import os
45
from typing import List, Optional
56

67
import pytest
@@ -17,6 +18,7 @@
1718
ConsumptionOptions,
1819
PatchLabels,
1920
)
21+
from sap_cloud_sdk.destination._destination_http_client import DestinationHttpClient
2022
from sap_cloud_sdk.destination.exceptions import (
2123
HttpError,
2224
DestinationOperationError,
@@ -57,6 +59,8 @@ def __init__(self):
5759
self.updated_certificate_content: Optional[str] = None
5860
self.tenant: Optional[str] = None
5961
self.retrieved_labels: List[Label] = []
62+
self.http_client: Optional[DestinationHttpClient] = None
63+
self.http_response = None
6064

6165

6266
@pytest.fixture
@@ -1572,3 +1576,38 @@ def certificate_should_have_label(context, key, value):
15721576
lbl.key == key and value in lbl.values
15731577
for lbl in context.retrieved_labels
15741578
), f"Expected label key='{key}' value='{value}' in {context.retrieved_labels}"
1579+
1580+
1581+
# ==================== DESTINATION HTTP CLIENT STEPS ====================
1582+
1583+
@given("the destination has OAuth2 credentials from environment")
1584+
def destination_has_oauth2_credentials(context):
1585+
context.destination.properties.update({
1586+
"clientId": os.environ["CLOUD_SDK_CFG_DESTINATION_DEFAULT_CLIENTID"],
1587+
"clientSecret": os.environ["CLOUD_SDK_CFG_DESTINATION_DEFAULT_CLIENTSECRET"],
1588+
"tokenServiceURL": os.environ["CLOUD_SDK_CFG_DESTINATION_DEFAULT_URL"] + "/oauth/token",
1589+
})
1590+
1591+
1592+
@when("I fetch the destination using the v2 API")
1593+
def fetch_destination_v2(context, destination_client):
1594+
context.retrieved_destination = destination_client.get_destination(context.destination.name)
1595+
1596+
1597+
@when("I create a DestinationHttpClient from the destination")
1598+
def create_http_client(context):
1599+
context.http_client = DestinationHttpClient(context.retrieved_destination)
1600+
1601+
1602+
@when(parsers.parse('I send a GET request to "{path}"'))
1603+
def send_get_request(context, path):
1604+
context.http_response = context.http_client.request("GET", path)
1605+
1606+
1607+
@then("the response contains an Authorization header")
1608+
def assert_authorization_header_present(context):
1609+
echoed = context.http_response.json().get("headers", {})
1610+
assert "Authorization" in echoed, (
1611+
f"Expected Authorization header in response, got: {list(echoed.keys())}. "
1612+
"Check that BTP returned an auth token for the destination."
1613+
)

0 commit comments

Comments
 (0)