Skip to content

Commit

Permalink
W-15631658 Test NTLM with dynamic configs (#930)
Browse files Browse the repository at this point in the history
  • Loading branch information
aronee2008 authored Oct 29, 2024
1 parent 4fa2a31 commit ea8a2ae
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
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));
}
}
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>

0 comments on commit ea8a2ae

Please sign in to comment.