jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1719702 - in /jmeter/trunk: src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java test/src/org/apache/jmeter/protocol/http/control/AuthManagerTest.java test/src/org/apache/jmeter/protocol/http/control/TestAuthManager.java
Date Sat, 12 Dec 2015 15:35:52 GMT
Author: fschumacher
Date: Sat Dec 12 15:35:52 2015
New Revision: 1719702

URL: http://svn.apache.org/viewvc?rev=1719702&view=rev
Log:
Followup to r1719699

There was already a test case for AuthManager, so use that one.
Correct offset for length of splitted array, so that old auth infos can be read.

Bugzilla Id: 58698


Removed:
    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/test/src/org/apache/jmeter/protocol/http/control/TestAuthManager.java

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=1719702&r1=1719701&r2=1719702&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:35:52 2015
@@ -378,26 +378,28 @@ public class AuthManager extends ConfigT
                         continue;
                     }
                     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 = "";
+                    if (tokens.length >= 3) {
+                        String url = tokens[0];
+                        String user = tokens[1];
+                        String pass = tokens[2];
+                        String domain;
+                        String realm;
+                        if (tokens.length > 3){ // Allow for old format file without the
extra columnns
+                            domain = tokens[3];
+                            realm = tokens[4];
+                        } else {
+                            domain = "";
+                            realm = "";
+                        }
+                        Mechanism mechanism;
+                        if (tokens.length > 5) { // 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);
                     }
-                    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 + "'", e);
                     ok = false;

Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/TestAuthManager.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/TestAuthManager.java?rev=1719702&r1=1719701&r2=1719702&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/TestAuthManager.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/TestAuthManager.java Sat
Dec 12 15:35:52 2015
@@ -18,7 +18,10 @@
 
 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 org.apache.jmeter.junit.JMeterTestCase;
 import org.apache.jmeter.testelement.property.CollectionProperty;
@@ -77,4 +80,34 @@ public class TestAuthManager extends JMe
             assertEquals("lmn8443", at.getUser());
             assertEquals("pass", at.getPass());
         }
+
+        public void testAddFileWithoutDomainAndRealmWithMechanism() 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());
+        }
+
+        public void testAddFileWithDomainAndRealmAndDefaultMechanism() 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());
+        }
+
+        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());
+        }
 }



Mime
View raw message