geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r579867 [3/3] - in /geronimo/sandbox/AsyncHttpClient/src: main/java/org/apache/ahc/auth/ main/java/org/apache/ahc/codec/ main/java/org/apache/ahc/util/ test/catalina/webapps/auth_basic/ test/catalina/webapps/auth_basic/WEB-INF/ test/catalin...
Date Thu, 27 Sep 2007 02:01:57 GMT
Modified: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java?rev=579867&r1=579866&r2=579867&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java Wed Sep
26 19:01:53 2007
@@ -27,8 +27,10 @@
 import org.apache.catalina.Context;
 import org.apache.catalina.Engine;
 import org.apache.catalina.Host;
+import org.apache.catalina.realm.MemoryRealm;
 import org.apache.catalina.connector.Connector;
 import org.apache.catalina.core.StandardHost;
+import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.Embedded;
 
 public class AbstractTest extends TestCase {
@@ -38,6 +40,8 @@
     protected static final File KEYSTORE = new File(CATALINAHOME, "conf/keystore");
     protected static final File WEBAPPS = new File(CATALINAHOME, "webapps");
     protected static final File ROOT = new File(WEBAPPS, "ROOT");
+    protected static final File AUTH_BASIC = new File(WEBAPPS, "auth_basic");
+    protected static final File AUTH_DIGEST = new File(WEBAPPS, "auth_digest");
     protected static Object semaphore = new Object();
     protected static final File WORK = new File(BASEDIR, "target/work");
     protected Embedded server;
@@ -54,10 +58,25 @@
         ((StandardHost)host).setWorkDir(WORK.getAbsolutePath());
         engine.addChild(host);
 
-        Context context = server.createContext("", ROOT.getAbsolutePath());
+        //Ass the Root context
+        StandardContext context = (StandardContext)server.createContext("", ROOT.getAbsolutePath());
         context.setParentClassLoader(Thread.currentThread().getContextClassLoader());
         host.addChild(context);
 
+        //Add the auth basic context
+        context = (StandardContext)server.createContext("", AUTH_BASIC.getAbsolutePath());
+        context.setParentClassLoader(Thread.currentThread().getContextClassLoader());
+        context.setRealm(new FakeRealm());
+        context.setPath("/authbasic");
+        host.addChild(context);
+
+        //Add the auth digest context
+        context = (StandardContext)server.createContext("", AUTH_DIGEST.getAbsolutePath());
+        context.setParentClassLoader(Thread.currentThread().getContextClassLoader());
+        context.setRealm(new FakeRealm());
+        context.setPath("/authdigest");
+        host.addChild(context);
+
         server.addEngine(engine);
 
         //Http
@@ -124,6 +143,7 @@
             synchronized (semaphore) {
                 semaphore.notify();
             }
+            cause.printStackTrace();
         }
 
         public void onClosed() {

Added: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AuthTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AuthTest.java?rev=579867&view=auto
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AuthTest.java (added)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AuthTest.java Wed Sep 26
19:01:53 2007
@@ -0,0 +1,75 @@
+/*
+ *  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.ahc;
+
+import java.net.URL;
+
+import org.apache.ahc.codec.HttpRequestMessage;
+import org.apache.ahc.auth.UsernamePasswordCredentials;
+import org.apache.ahc.auth.AuthScope;
+
+public class AuthTest extends AbstractTest {
+
+    AsyncHttpClient ahc;
+
+    public void testBasicAuth() throws Exception {
+        TestCallback callback = new TestCallback();
+        HttpRequestMessage request = new HttpRequestMessage(
+            new URL("http://localhost:8282/authbasic/secure.jsp"), callback);
+
+        UsernamePasswordCredentials creds = new UsernamePasswordCredentials("test","password");
+        request.addCredentials(AuthScope.ANY, creds);
+        ahc.sendRequest(request);
+
+        synchronized (semaphore) {
+            //5 second timeout due to no response
+            semaphore.wait(5000);
+        }
+
+        System.out.println(callback.getMessage().getStatusCode());
+    }
+
+    public void testDigestAuth() throws Exception {
+        TestCallback callback = new TestCallback();
+        HttpRequestMessage request = new HttpRequestMessage(
+            new URL("http://localhost:8282/authdigest/secure.jsp"), callback);
+
+        UsernamePasswordCredentials creds = new UsernamePasswordCredentials("test","password");
+        request.addCredentials(AuthScope.ANY, creds);
+        ahc.sendRequest(request);
+
+        synchronized (semaphore) {
+            //5 second timeout due to no response
+            semaphore.wait(5000);
+        }
+
+        System.out.println(callback.getMessage().getStatusCode());
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        ahc = new AsyncHttpClient();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        ahc.destroyAll();
+    }
+}

Added: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeRealm.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeRealm.java?rev=579867&view=auto
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeRealm.java (added)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeRealm.java Wed Sep 26
19:01:53 2007
@@ -0,0 +1,57 @@
+/*
+ *  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.ahc;
+
+import java.security.Principal;
+import java.util.ArrayList;
+
+import org.apache.catalina.realm.GenericPrincipal;
+import org.apache.catalina.realm.RealmBase;
+
+public class FakeRealm extends RealmBase {
+    protected String getName() {
+        return "test";
+    }
+
+    protected String getPassword(String string) {
+        return "password";
+    }
+
+    protected Principal getPrincipal(String user) {
+        if (user.equals("test")) {
+            ArrayList roles = new ArrayList();
+            roles.add("test");
+            Principal principal = new GenericPrincipal(this, user, "password", roles);
+            return principal;
+        }
+
+        return null;
+    }
+
+
+    public Principal authenticate(String user, String password) {
+        if (user.equals("test") && password.equals("password")) {
+            return getPrincipal(user);
+        }
+
+        return null;
+    }
+
+}



Mime
View raw message