Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case for validating WWW-Authorization header when invocating an API with API Keys using invalid Authorization header #13523

Merged
merged 1 commit into from
Sep 2, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,40 @@ public void testInvocationWithApiKeysWithoutSubscription() throws Exception {
", but got " + invocationResponseAfterSubscriptionRemoved.getResponseCode());
}

@Test(description = "Testing the WWW-Authorization header when invocating an API with API Keys using invalid Authorization header",
dependsOnMethods = {"testCreateAndPublishAPIWithOAuth2"})
public void testWWWAuthorizationHeaderForApiWithApiKeys() throws Exception{

String expectedValue = "API Key realm=\"WSO2 API Manager\"";

// Validate WWW-Authenticate response header when request is made without Authorization header
Map<String, String> requestHeaders1 = new HashMap<>();
requestHeaders1.put("accept", "application/json");

HttpResponse response1 =
HTTPSClientUtils.doGet(getAPIInvocationURLHttps(mutualSSLandOAuthMandatoryAPIContext, API_VERSION_1_0_0) +
API_END_POINT_METHOD, requestHeaders1);

String wwwAuthenticateHeader = response1.getHeaders().get("WWW-Authenticate");

Assert.assertTrue(wwwAuthenticateHeader.contains(expectedValue),
"The WWW-Authenticate header does not contain the expected API Key value.");

// Validate WWW-Authenticate response header when request is made with invalid Authorization header
Map<String, String> requestHeaders2 = new HashMap<>();
requestHeaders2.put("accept", "application/json");
requestHeaders2.put("Authorization", null);

HttpResponse response2 =
HTTPSClientUtils.doGet(getAPIInvocationURLHttps(mutualSSLandOAuthMandatoryAPIContext, API_VERSION_1_0_0) +
API_END_POINT_METHOD, requestHeaders2);

wwwAuthenticateHeader = response2.getHeaders().get("WWW-Authenticate");

Assert.assertTrue(wwwAuthenticateHeader.contains(expectedValue),
"The WWW-Authenticate header does not contain the expected API Key value.");
}

@AfterClass(alwaysRun = true)
public void cleanUpArtifacts() throws Exception {
restAPIStore.deleteApplication(applicationId);
Expand Down
Loading