Search in sources :

Example 6 with Authorization

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");
}
Also used : Authorization(org.apache.jmeter.protocol.http.control.Authorization) BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) AuthManager(org.apache.jmeter.protocol.http.control.AuthManager) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 7 with Authorization

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);
}
Also used : Authorization(org.apache.jmeter.protocol.http.control.Authorization) AuthPanel(org.apache.jmeter.protocol.http.gui.AuthPanel)

Example 8 with Authorization

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();
}
Also used : Authorization(org.apache.jmeter.protocol.http.control.Authorization)

Aggregations

Authorization (org.apache.jmeter.protocol.http.control.Authorization)8 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)3 AuthManager (org.apache.jmeter.protocol.http.control.AuthManager)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Header (org.apache.jmeter.protocol.http.control.Header)2 HeaderManager (org.apache.jmeter.protocol.http.control.HeaderManager)2 BasicCurlParser (org.apache.jmeter.protocol.http.curl.BasicCurlParser)2 Request (org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request)2 ParseCurlCommandAction (org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction)2 TestElement (org.apache.jmeter.testelement.TestElement)2 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)2 Test (org.junit.jupiter.api.Test)2 MalformedURLException (java.net.MalformedURLException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 Collection (java.util.Collection)1 Subject (javax.security.auth.Subject)1 HttpHost (org.apache.http.HttpHost)1 AuthCache (org.apache.http.client.AuthCache)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1