use of org.apache.jmeter.protocol.http.control.Authorization in project jmeter by apache.
the class ParseCurlCommandActionTest method testCanUpdateAuthManagerInThreadGroupt.
@Test
public void testCanUpdateAuthManagerInThreadGroupt() throws Exception {
ParseCurlCommandAction p = new ParseCurlCommandAction();
AuthManager authManager = new AuthManager();
Authorization authorization = new Authorization();
authorization.setPass("passwd");
authorization.setUser("user");
authorization.setURL("http://jmeter.apache.org/");
authorization.setMechanism(Mechanism.BASIC);
authManager.addAuth(authorization);
BasicCurlParser basicCurlParser = new BasicCurlParser();
Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -u 'user:passwd'");
Method method = getMethodFor("canUpdateAuthManagerInThreadGroup", Request.class, AuthManager.class);
assertFalse((boolean) method.invoke(p, request, authManager), "When AuthManager contains this url, shouldn't add a AuthManager in ThreadGroup");
request = basicCurlParser.parse("curl 'http://jmeter.apache.fr/' -u 'user:passwd'");
assertTrue((boolean) method.invoke(p, request, authManager), "The AuthManager doesn't contain this url , should add a AuthManager in ThreadGroup");
}
use of org.apache.jmeter.protocol.http.control.Authorization in project jmeter by apache.
the class ParseCurlCommandAction method createAuthManager.
/**
* Create Authorization manager
*
* @param request {@link Request}
*/
private void createAuthManager(Request request, AuthManager authManager) {
Authorization auth = request.getAuthorization();
authManager.setProperty(TestElement.GUI_CLASS, AuthPanel.class.getName());
authManager.setProperty(TestElement.NAME, "HTTP AuthorizationManager");
authManager.setProperty(TestElement.COMMENTS, getDefaultComment());
authManager.getAuthObjects().addItem(auth);
}
use of org.apache.jmeter.protocol.http.control.Authorization in project jmeter by apache.
the class HTTPJavaImpl method setConnectionAuthorization.
/**
* Extracts all the required authorization for that particular URL request
* and sets it in the <code>HttpURLConnection</code> passed in.
*
* @param conn
* <code>HttpUrlConnection</code> which represents the URL
* request
* @param u
* <code>URL</code> of the URL request
* @param authManager
* the <code>AuthManager</code> containing all the cookies for
* this <code>UrlConfig</code>
* @return String Authorization header value or null if not set
*/
private Map<String, String> setConnectionAuthorization(HttpURLConnection conn, URL u, AuthManager authManager) {
if (authManager != null) {
Authorization auth = authManager.getAuthForURL(u);
if (auth != null) {
String headerValue = auth.toBasicHeader();
conn.setRequestProperty(HTTPConstants.HEADER_AUTHORIZATION, headerValue);
// keep trace of it
return Collections.singletonMap(HTTPConstants.HEADER_AUTHORIZATION, headerValue);
}
}
return Collections.emptyMap();
}
Aggregations