You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2015/12/12 16:16:48 UTC
svn commit: r1719699 - in /jmeter/trunk:
src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java
test/src/org/apache/jmeter/protocol/http/control/AuthManagerTest.java
xdocs/changes.xml
Author: fschumacher
Date: Sat Dec 12 15:16:48 2015
New Revision: 1719699
URL: http://svn.apache.org/viewvc?rev=1719699&view=rev
Log:
Bug 58698: Correct parsing of auth-files in HTTP Authorization Manager.
Bugzilla Id: 58698
Added:
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/AuthManagerTest.java
Modified:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java?rev=1719699&r1=1719698&r2=1719699&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java Sat Dec 12 15:16:48 2015
@@ -30,7 +30,6 @@ import java.net.URL;
import java.security.Principal;
import java.util.ArrayList;
import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
import javax.security.auth.Subject;
@@ -378,24 +377,29 @@ public class AuthManager extends ConfigT
if (line.startsWith("#") || JOrphanUtils.isBlank(line)) { //$NON-NLS-1$
continue;
}
- StringTokenizer st = new StringTokenizer(line, "\t"); //$NON-NLS-1$
- String url = st.nextToken();
- String user = st.nextToken();
- String pass = st.nextToken();
- String domain = "";
- String realm = "";
- if (st.hasMoreTokens()){// Allow for old format file without the extra columnns
- domain = st.nextToken();
- realm = st.nextToken();
+ String[] tokens = line.split("\t"); //$NON-NLS-1$
+ String url = tokens[0];
+ String user = tokens[1];
+ String pass = tokens[2];
+ String domain;
+ String realm;
+ if (tokens.length > 2){ // Allow for old format file without the extra columnns
+ domain = tokens[3];
+ realm = tokens[4];
+ } else {
+ domain = "";
+ realm = "";
}
- Mechanism mechanism = Mechanism.BASIC_DIGEST;
- if (st.hasMoreTokens()){// Allow for old format file without mechanism support
- mechanism = Mechanism.valueOf(st.nextToken());
+ Mechanism mechanism;
+ if (tokens.length > 4) { // Allow for old format file without mechanism support
+ mechanism = Mechanism.valueOf(tokens[5]);
+ } else {
+ mechanism = Mechanism.BASIC_DIGEST;
}
Authorization auth = new Authorization(url, user, pass, domain, realm, mechanism);
getAuthObjects().addItem(auth);
} catch (NoSuchElementException e) {
- log.error("Error parsing auth line: '" + line + "'");
+ log.error("Error parsing auth line: '" + line + "'", e);
ok = false;
}
}
Added: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/AuthManagerTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/AuthManagerTest.java?rev=1719699&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/AuthManagerTest.java (added)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/AuthManagerTest.java Sat Dec 12 15:16:48 2015
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.jmeter.protocol.http.control;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.Files;
+
+import junit.framework.TestCase;
+
+import org.junit.Test;
+
+public class AuthManagerTest extends TestCase {
+
+ @Test
+ public void testAddFileWithoutDomainAndRealm() throws IOException {
+ File authFile = File.createTempFile("auth", ".txt");
+ Files.write(authFile.toPath(), "http://example.com\tuser\tpassword\t\t\tBASIC_DIGEST".getBytes());
+ AuthManager manager = new AuthManager();
+ manager.addFile(authFile.getAbsolutePath());
+ Authorization authForURL = manager.getAuthForURL(new URL("http://example.com"));
+ assertEquals("password", authForURL.getPass());
+ }
+
+ @Test
+ public void testAddFileWithDomainAndRealm() throws IOException {
+ File authFile = File.createTempFile("auth", ".txt");
+ Files.write(authFile.toPath(), "http://example.com\tuser\tpassword\tdomain\tEXAMPLE.COM\tBASIC_DIGEST".getBytes());
+ AuthManager manager = new AuthManager();
+ manager.addFile(authFile.getAbsolutePath());
+ Authorization authForURL = manager.getAuthForURL(new URL("http://example.com"));
+ assertEquals("password", authForURL.getPass());
+ assertEquals("domain", authForURL.getDomain());
+ }
+
+ @Test
+ public void testAddFileWithDomainAndRealmAndMechanism() throws IOException {
+ File authFile = File.createTempFile("auth", ".txt");
+ Files.write(authFile.toPath(), "http://example.com\tuser\tpassword\tdomain\tEXAMPLE.COM\tKERBEROS".getBytes());
+ AuthManager manager = new AuthManager();
+ manager.addFile(authFile.getAbsolutePath());
+ Authorization authForURL = manager.getAuthForURL(new URL("http://example.com"));
+ assertEquals("password", authForURL.getPass());
+ assertEquals("domain", authForURL.getDomain());
+ assertEquals(AuthManager.Mechanism.KERBEROS, authForURL.getMechanism());
+ }
+
+}
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1719699&r1=1719698&r2=1719699&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sat Dec 12 15:16:48 2015
@@ -119,6 +119,7 @@ Summary
<ul>
<li><bug>58303</bug>Change usage of bouncycastle api in SMIMEAssertion to get rid of deprecation warnings.</li>
<li><bug>58515</bug>New JSON related components : JSON-PATH Extractor and JSON-PATH Renderer in View Results Tree. Donated by Ubik Load Pack (support at ubikloadpack.com).</li>
+ <li><bug>58698</bug>Correct parsing of auth-files in HTTP Authorization Manager.</li>
</ul>
<h3>Functions</h3>