-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
W-15631658 Test NTLM with dynamic configs (#930)
- Loading branch information
1 parent
4fa2a31
commit ea8a2ae
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
.../mule/test/http/functional/requester/proxy/HttpRequestNtlmProxyDynamicConfigTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2023 Salesforce, Inc. All rights reserved. | ||
* The software in this package is published under the terms of the CPAL v1.0 | ||
* license, a copy of which has been included with this distribution in the | ||
* LICENSE.txt file. | ||
*/ | ||
package org.mule.test.http.functional.requester.proxy; | ||
|
||
import static org.mule.runtime.http.api.HttpHeaders.Names.PROXY_AUTHENTICATE; | ||
import static org.mule.runtime.http.api.HttpHeaders.Names.PROXY_AUTHORIZATION; | ||
import static org.mule.test.http.functional.AllureConstants.HttpFeature.HttpStory.NTLM; | ||
import static org.mule.test.http.functional.AllureConstants.HttpFeature.HttpStory.PROXY; | ||
import static org.mule.test.http.functional.fips.DefaultTestConfiguration.isFipsTesting; | ||
|
||
import static javax.servlet.http.HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assume.assumeFalse; | ||
|
||
import org.mule.extension.http.api.HttpResponseAttributes; | ||
import org.mule.runtime.core.api.event.CoreEvent; | ||
import org.mule.test.http.functional.requester.ntlm.AbstractAuthNtlmTestCase; | ||
import org.mule.test.http.functional.requester.ntlm.AbstractNtlmTestCase; | ||
|
||
import io.qameta.allure.Description; | ||
import io.qameta.allure.Stories; | ||
import io.qameta.allure.Story; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
|
||
|
||
@Stories({@Story(PROXY), @Story(NTLM)}) | ||
public class HttpRequestNtlmProxyDynamicConfigTestCase extends AbstractAuthNtlmTestCase { | ||
|
||
private static final String PROXY_AUTHENTICATION_REQUIRED = "Proxy Authentication Required"; | ||
|
||
|
||
@BeforeClass | ||
public static void before() { | ||
assumeFalse("Ntlm is based on MD5. So this should not run on FIPS", isFipsTesting()); | ||
} | ||
|
||
@Before | ||
public void setup() { | ||
setupTestAuthorizer(PROXY_AUTHORIZATION, PROXY_AUTHENTICATE, SC_PROXY_AUTHENTICATION_REQUIRED); | ||
} | ||
|
||
@Override | ||
protected String getConfigFile() { | ||
return "http-request-ntlm-proxy-dynamic-config.xml"; | ||
} | ||
|
||
@Override | ||
@Description("Verifies that NTLM Auth is successfully performed using dynamic configs.") | ||
public void validNtlmAuth() | ||
throws Exception { | ||
CoreEvent response = flowRunner("ntlmFlowWithCorrectPassword").withVariable("ntlmPassword", "Beeblebrox").run(); | ||
assertThat(response.getMessage().getPayload().getValue(), equalTo(AbstractNtlmTestCase.AUTHORIZED)); | ||
|
||
CoreEvent unauthorizedResponse = flowRunner("ntlmFlowWithWrongPassword").withVariable("ntlmPassword", "wrongPassword").run(); | ||
HttpResponseAttributes httpResponseAttributes = | ||
(HttpResponseAttributes) unauthorizedResponse.getMessage().getAttributes().getValue(); | ||
assertThat(httpResponseAttributes.getStatusCode(), is(SC_PROXY_AUTHENTICATION_REQUIRED)); | ||
assertThat(httpResponseAttributes.getReasonPhrase(), is(PROXY_AUTHENTICATION_REQUIRED)); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
functional-tests/http/src/test/resources/http-request-ntlm-proxy-dynamic-config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<mule xmlns="http://www.mulesoft.org/schema/mule/core" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:http="http://www.mulesoft.org/schema/mule/http" | ||
xsi:schemaLocation=" | ||
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd | ||
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"> | ||
|
||
<http:request-config name="ntlmProxyConfig" basePath="basePath"> | ||
<http:request-connection host="localhost" port="9999"> | ||
<http:proxy-config> | ||
<http:ntlm-proxy host="localhost" port="${httpPort}" username="Zaphod" password="#[vars.ntlmPassword]" ntlmDomain="Ursa-Minor" /> | ||
</http:proxy-config> | ||
</http:request-connection> | ||
</http:request-config> | ||
|
||
<flow name="ntlmFlowWithCorrectPassword"> | ||
<http:request config-ref="ntlmProxyConfig" path="requestPath"/> | ||
<set-payload value="#[%dw 2.0 output application/java --- payload.^raw as String]"/> | ||
</flow> | ||
|
||
<flow name="ntlmFlowWithWrongPassword"> | ||
<http:request config-ref="ntlmProxyConfig" path="requestPath"> | ||
<http:response-validator> | ||
<http:success-status-code-validator values="0..599"/> | ||
</http:response-validator> | ||
</http:request> | ||
<set-payload value="#[%dw 2.0 output application/java --- payload.^raw as String]"/> | ||
</flow> | ||
</mule> |