shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r732915 - in /incubator/jsecurity/trunk: core/test/org/jsecurity/authc/credential/ core/test/org/jsecurity/authc/pam/ core/test/org/jsecurity/authz/permission/ core/test/org/jsecurity/realm/activedirectory/ web/test/org/jsecurity/web/attr/ ...
Date Fri, 09 Jan 2009 03:12:46 GMT
Author: lhazlewood
Date: Thu Jan  8 19:12:45 2009
New Revision: 732915

URL: http://svn.apache.org/viewvc?rev=732915&view=rev
Log:
replaced missing Test cases that were not copied during the src dir restructuring.  All tests
are now back in place.

Added:
    incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/
    incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/AllowAllCredentialsMatcherTest.java
    incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/HashedCredentialsMatcherTest.java
    incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Md2CredentialsMatcherTest.java
    incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Md5CredentialsMatcherTest.java
    incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha1CredentialsMatcherTest.java
    incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha256CredentialsMatcherTest.java
    incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha384CredentialsMatcherTest.java
    incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha512CredentialsMatcherTest.java
    incubator/jsecurity/trunk/core/test/org/jsecurity/authc/pam/
    incubator/jsecurity/trunk/core/test/org/jsecurity/authc/pam/AllSuccessfulModularAuthenticationStrategyTest.java
    incubator/jsecurity/trunk/core/test/org/jsecurity/authz/permission/
    incubator/jsecurity/trunk/core/test/org/jsecurity/authz/permission/AllPermissionTest.java
    incubator/jsecurity/trunk/core/test/org/jsecurity/authz/permission/WildcardPermissionTest.java
    incubator/jsecurity/trunk/core/test/org/jsecurity/realm/activedirectory/
    incubator/jsecurity/trunk/core/test/org/jsecurity/realm/activedirectory/ActiveDirectoryRealmTest.java
    incubator/jsecurity/trunk/web/test/org/jsecurity/web/attr/
    incubator/jsecurity/trunk/web/test/org/jsecurity/web/attr/CookieAttributeTest.java
    incubator/jsecurity/trunk/web/test/org/jsecurity/web/servlet/
    incubator/jsecurity/trunk/web/test/org/jsecurity/web/servlet/JSecurityFilterTest.java

Added: incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/AllowAllCredentialsMatcherTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/AllowAllCredentialsMatcherTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/AllowAllCredentialsMatcherTest.java
(added)
+++ incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/AllowAllCredentialsMatcherTest.java
Thu Jan  8 19:12:45 2009
@@ -0,0 +1,35 @@
+/*
+ * 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.jsecurity.authc.credential;
+
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+/**
+ * @author Les Hazlewood
+ * @since Jun 10, 2008 4:35:27 PM
+ */
+public class AllowAllCredentialsMatcherTest {
+
+    @Test
+    public void testBasic() {
+        assertTrue(new AllowAllCredentialsMatcher().doCredentialsMatch(null, null));
+    }
+
+}

Added: incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/HashedCredentialsMatcherTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/HashedCredentialsMatcherTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/HashedCredentialsMatcherTest.java
(added)
+++ incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/HashedCredentialsMatcherTest.java
Thu Jan  8 19:12:45 2009
@@ -0,0 +1,48 @@
+/*
+ * 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.jsecurity.authc.credential;
+
+import junit.framework.TestCase;
+import org.jsecurity.authc.AuthenticationInfo;
+import org.jsecurity.authc.AuthenticationToken;
+import org.jsecurity.authc.SimpleAuthenticationInfo;
+import org.jsecurity.authc.UsernamePasswordToken;
+import org.jsecurity.crypto.hash.AbstractHash;
+import org.jsecurity.util.ClassUtils;
+import org.junit.Test;
+
+/**
+ * @author Les Hazlewood
+ * @since Jun 10, 2008 4:47:09 PM
+ */
+public abstract class HashedCredentialsMatcherTest extends TestCase {
+
+    public abstract Class<? extends HashedCredentialsMatcher> getMatcherClass();
+
+    public abstract AbstractHash hash(Object credentials);
+
+    @Test
+    public void testBasic() {
+        CredentialsMatcher matcher = (CredentialsMatcher) ClassUtils.newInstance(getMatcherClass());
+        byte[] hashed = hash("password").getBytes();
+        AuthenticationInfo account = new SimpleAuthenticationInfo("username", hashed, "realmName");
+        AuthenticationToken token = new UsernamePasswordToken("username", "password");
+        assertTrue(matcher.doCredentialsMatch(token, account));
+    }
+}

Added: incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Md2CredentialsMatcherTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Md2CredentialsMatcherTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Md2CredentialsMatcherTest.java
(added)
+++ incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Md2CredentialsMatcherTest.java
Thu Jan  8 19:12:45 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.jsecurity.authc.credential;
+
+import org.jsecurity.crypto.hash.AbstractHash;
+import org.jsecurity.crypto.hash.Md2Hash;
+
+/**
+ * @author Les Hazlewood
+ * @since Jun 10, 2008 4:38:16 PM
+ */
+public class Md2CredentialsMatcherTest extends HashedCredentialsMatcherTest {
+
+    public Class<? extends HashedCredentialsMatcher> getMatcherClass() {
+        return Md2CredentialsMatcher.class;
+    }
+
+    public AbstractHash hash(Object credentials) {
+        return new Md2Hash(credentials);
+    }
+}
+
+

Added: incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Md5CredentialsMatcherTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Md5CredentialsMatcherTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Md5CredentialsMatcherTest.java
(added)
+++ incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Md5CredentialsMatcherTest.java
Thu Jan  8 19:12:45 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.jsecurity.authc.credential;
+
+import org.jsecurity.crypto.hash.AbstractHash;
+import org.jsecurity.crypto.hash.Md5Hash;
+
+/**
+ * @author Les Hazlewood
+ * @since Jun 10, 2008 4:59:36 PM
+ */
+public class Md5CredentialsMatcherTest extends HashedCredentialsMatcherTest {
+
+    public Class<? extends HashedCredentialsMatcher> getMatcherClass() {
+        return Md5CredentialsMatcher.class;
+    }
+
+    public AbstractHash hash(Object credentials) {
+        return new Md5Hash(credentials);
+    }
+}
\ No newline at end of file

Added: incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha1CredentialsMatcherTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha1CredentialsMatcherTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha1CredentialsMatcherTest.java
(added)
+++ incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha1CredentialsMatcherTest.java
Thu Jan  8 19:12:45 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.jsecurity.authc.credential;
+
+import org.jsecurity.crypto.hash.AbstractHash;
+import org.jsecurity.crypto.hash.Sha1Hash;
+
+/**
+ * @author Les Hazlewood
+ * @since Jun 10, 2008 5:00:30 PM
+ */
+public class Sha1CredentialsMatcherTest extends HashedCredentialsMatcherTest {
+
+    public Class<? extends HashedCredentialsMatcher> getMatcherClass() {
+        return Sha1CredentialsMatcher.class;
+    }
+
+    public AbstractHash hash(Object credentials) {
+        return new Sha1Hash(credentials);
+    }
+}

Added: incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha256CredentialsMatcherTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha256CredentialsMatcherTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha256CredentialsMatcherTest.java
(added)
+++ incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha256CredentialsMatcherTest.java
Thu Jan  8 19:12:45 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.jsecurity.authc.credential;
+
+import org.jsecurity.crypto.hash.AbstractHash;
+import org.jsecurity.crypto.hash.Sha256Hash;
+
+/**
+ * @author Les Hazlewood
+ * @since Jun 10, 2008 5:01:00 PM
+ */
+public class Sha256CredentialsMatcherTest extends HashedCredentialsMatcherTest {
+
+    public Class<? extends HashedCredentialsMatcher> getMatcherClass() {
+        return Sha256CredentialsMatcher.class;
+    }
+
+    public AbstractHash hash(Object credentials) {
+        return new Sha256Hash(credentials);
+    }
+}

Added: incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha384CredentialsMatcherTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha384CredentialsMatcherTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha384CredentialsMatcherTest.java
(added)
+++ incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha384CredentialsMatcherTest.java
Thu Jan  8 19:12:45 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.jsecurity.authc.credential;
+
+import org.jsecurity.crypto.hash.AbstractHash;
+import org.jsecurity.crypto.hash.Sha384Hash;
+
+/**
+ * @author Les Hazlewood
+ * @since Jun 10, 2008 5:02:27 PM
+ */
+public class Sha384CredentialsMatcherTest extends HashedCredentialsMatcherTest {
+
+    public Class<? extends HashedCredentialsMatcher> getMatcherClass() {
+        return Sha384CredentialsMatcher.class;
+    }
+
+    public AbstractHash hash(Object credentials) {
+        return new Sha384Hash(credentials);
+    }
+}

Added: incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha512CredentialsMatcherTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha512CredentialsMatcherTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha512CredentialsMatcherTest.java
(added)
+++ incubator/jsecurity/trunk/core/test/org/jsecurity/authc/credential/Sha512CredentialsMatcherTest.java
Thu Jan  8 19:12:45 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.jsecurity.authc.credential;
+
+import org.jsecurity.crypto.hash.AbstractHash;
+import org.jsecurity.crypto.hash.Sha512Hash;
+
+/**
+ * @author Les Hazlewood
+ * @since Jun 10, 2008 5:02:58 PM
+ */
+public class Sha512CredentialsMatcherTest extends HashedCredentialsMatcherTest {
+
+    public Class<? extends HashedCredentialsMatcher> getMatcherClass() {
+        return Sha512CredentialsMatcher.class;
+    }
+
+    public AbstractHash hash(Object credentials) {
+        return new Sha512Hash(credentials);
+    }
+}

Added: incubator/jsecurity/trunk/core/test/org/jsecurity/authc/pam/AllSuccessfulModularAuthenticationStrategyTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/test/org/jsecurity/authc/pam/AllSuccessfulModularAuthenticationStrategyTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/test/org/jsecurity/authc/pam/AllSuccessfulModularAuthenticationStrategyTest.java
(added)
+++ incubator/jsecurity/trunk/core/test/org/jsecurity/authc/pam/AllSuccessfulModularAuthenticationStrategyTest.java
Thu Jan  8 19:12:45 2009
@@ -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.jsecurity.authc.pam;
+
+import org.jsecurity.authc.AuthenticationException;
+import org.jsecurity.authc.AuthenticationInfo;
+import org.jsecurity.authc.AuthenticationToken;
+import org.jsecurity.authz.AuthorizationInfo;
+import org.jsecurity.realm.AuthorizingRealm;
+import org.jsecurity.realm.Realm;
+import org.jsecurity.realm.SimpleAccountRealm;
+import org.jsecurity.subject.PrincipalCollection;
+import static org.junit.Assert.assertNotNull;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AllSuccessfulModularAuthenticationStrategyTest {
+
+    private AllSuccessfulModularAuthenticationStrategy strategy;
+
+    @Before
+    public void setUp() {
+        strategy = new AllSuccessfulModularAuthenticationStrategy();
+    }
+
+    @Test
+    public void beforeAllAttempts() {
+        AuthenticationInfo info = strategy.beforeAllAttempts(null, null);
+        assertNotNull(info);
+    }
+
+    @Test
+    public void beforeAttemptSupportingToken() {
+        new SimpleAccountRealm();
+    }
+
+    @Test(expected = UnsupportedTokenException.class)
+    public void beforeAttemptRealmDoesntSupportToken() {
+        Realm notSupportingRealm = new AuthorizingRealm() {
+
+            public boolean supports(AuthenticationToken token) {
+                return false;
+            }
+
+            protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
throws AuthenticationException {
+                return null;
+            }
+
+            protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal)
{
+                return null;
+            }
+
+        };
+
+        strategy.beforeAttempt(notSupportingRealm, null, null);
+    }
+
+
+}

Added: incubator/jsecurity/trunk/core/test/org/jsecurity/authz/permission/AllPermissionTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/test/org/jsecurity/authz/permission/AllPermissionTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/test/org/jsecurity/authz/permission/AllPermissionTest.java
(added)
+++ incubator/jsecurity/trunk/core/test/org/jsecurity/authz/permission/AllPermissionTest.java
Thu Jan  8 19:12:45 2009
@@ -0,0 +1,38 @@
+/*
+ * 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.jsecurity.authz.permission;
+
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+/**
+ * @author Les Hazlewood
+ */
+public class AllPermissionTest {
+
+    @Test
+    public void testNullArgument() {
+        assertTrue(new AllPermission().implies(null));
+    }
+
+    @Test
+    public void testNonNullArgument() {
+        assertTrue(new AllPermission().implies(new AllPermission()));
+    }
+}

Added: incubator/jsecurity/trunk/core/test/org/jsecurity/authz/permission/WildcardPermissionTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/test/org/jsecurity/authz/permission/WildcardPermissionTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/test/org/jsecurity/authz/permission/WildcardPermissionTest.java
(added)
+++ incubator/jsecurity/trunk/core/test/org/jsecurity/authz/permission/WildcardPermissionTest.java
Thu Jan  8 19:12:45 2009
@@ -0,0 +1,199 @@
+/*
+ * 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.jsecurity.authz.permission;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+/**
+ * @author Jeremy Haile
+ * @since 0.9
+ */
+public class WildcardPermissionTest {
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testNull() {
+        new WildcardPermission(null);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testEmpty() {
+        new WildcardPermission("");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testBlank() {
+        new WildcardPermission("   ");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testOnlyDelimiters() {
+        new WildcardPermission("::,,::,:");
+    }
+
+    @Test
+    public void testNamed() {
+        WildcardPermission p1, p2;
+
+        // Case insensitive, same
+        p1 = new WildcardPermission("something");
+        p2 = new WildcardPermission("something");
+        assertTrue(p1.implies(p2));
+        assertTrue(p2.implies(p1));
+
+        // Case insensitive, different case
+        p1 = new WildcardPermission("something");
+        p2 = new WildcardPermission("SOMETHING");
+        assertTrue(p1.implies(p2));
+        assertTrue(p2.implies(p1));
+
+        // Case insensitive, different word
+        p1 = new WildcardPermission("something");
+        p2 = new WildcardPermission("else");
+        assertFalse(p1.implies(p2));
+        assertFalse(p2.implies(p1));
+
+        // Case sensitive same
+        p1 = new WildcardPermission("BLAHBLAH", false);
+        p2 = new WildcardPermission("BLAHBLAH", false);
+        assertTrue(p1.implies(p2));
+        assertTrue(p2.implies(p1));
+
+        // Case sensitive, different case
+        p1 = new WildcardPermission("BLAHBLAH", false);
+        p2 = new WildcardPermission("bLAHBLAH", false);
+        assertTrue(p1.implies(p2));
+        assertTrue(p2.implies(p1));
+
+        // Case sensitive, different word
+        p1 = new WildcardPermission("BLAHBLAH", false);
+        p2 = new WildcardPermission("whatwhat", false);
+        assertFalse(p1.implies(p2));
+        assertFalse(p2.implies(p1));
+
+    }
+
+    @Test
+    public void testLists() {
+        WildcardPermission p1, p2, p3;
+
+        p1 = new WildcardPermission("one,two");
+        p2 = new WildcardPermission("one");
+        assertTrue(p1.implies(p2));
+        assertFalse(p2.implies(p1));
+
+        p1 = new WildcardPermission("one,two,three");
+        p2 = new WildcardPermission("one,three");
+        assertTrue(p1.implies(p2));
+        assertFalse(p2.implies(p1));
+
+        p1 = new WildcardPermission("one,two:one,two,three");
+        p2 = new WildcardPermission("one:three");
+        p3 = new WildcardPermission("one:two,three");
+        assertTrue(p1.implies(p2));
+        assertFalse(p2.implies(p1));
+        assertTrue(p1.implies(p3));
+        assertFalse(p2.implies(p3));
+        assertTrue(p3.implies(p2));
+
+        p1 = new WildcardPermission("one,two,three:one,two,three:one,two");
+        p2 = new WildcardPermission("one:three:two");
+        assertTrue(p1.implies(p2));
+        assertFalse(p2.implies(p1));
+
+        p1 = new WildcardPermission("one");
+        p2 = new WildcardPermission("one:two,three,four");
+        p3 = new WildcardPermission("one:two,three,four:five:six:seven");
+        assertTrue(p1.implies(p2));
+        assertTrue(p1.implies(p3));
+        assertFalse(p2.implies(p1));
+        assertFalse(p3.implies(p1));
+        assertTrue(p2.implies(p3));
+
+    }
+
+    @Test
+    public void testWildcards() {
+        WildcardPermission p1, p2, p3, p4, p5, p6, p7, p8;
+
+        p1 = new WildcardPermission("*");
+        p2 = new WildcardPermission("one");
+        p3 = new WildcardPermission("one:two");
+        p4 = new WildcardPermission("one,two:three,four");
+        p5 = new WildcardPermission("one,two:three,four,five:six:seven,eight");
+        assertTrue(p1.implies(p2));
+        assertTrue(p1.implies(p3));
+        assertTrue(p1.implies(p4));
+        assertTrue(p1.implies(p5));
+
+        p1 = new WildcardPermission("newsletter:*");
+        p2 = new WildcardPermission("newsletter:read");
+        p3 = new WildcardPermission("newsletter:read,write");
+        p4 = new WildcardPermission("newsletter:*");
+        p5 = new WildcardPermission("newsletter:*:*");
+        p6 = new WildcardPermission("newsletter:*:read");
+        p7 = new WildcardPermission("newsletter:write:*");
+        p8 = new WildcardPermission("newsletter:read,write:*");
+        assertTrue(p1.implies(p2));
+        assertTrue(p1.implies(p3));
+        assertTrue(p1.implies(p4));
+        assertTrue(p1.implies(p5));
+        assertTrue(p1.implies(p6));
+        assertTrue(p1.implies(p7));
+        assertTrue(p1.implies(p8));
+
+
+        p1 = new WildcardPermission("newsletter:*:*");
+        assertTrue(p1.implies(p2));
+        assertTrue(p1.implies(p3));
+        assertTrue(p1.implies(p4));
+        assertTrue(p1.implies(p5));
+        assertTrue(p1.implies(p6));
+        assertTrue(p1.implies(p7));
+        assertTrue(p1.implies(p8));
+
+        p1 = new WildcardPermission("newsletter:*:*:*");
+        assertTrue(p1.implies(p2));
+        assertTrue(p1.implies(p3));
+        assertTrue(p1.implies(p4));
+        assertTrue(p1.implies(p5));
+        assertTrue(p1.implies(p6));
+        assertTrue(p1.implies(p7));
+        assertTrue(p1.implies(p8));
+
+        p1 = new WildcardPermission("newsletter:*:read");
+        p2 = new WildcardPermission("newsletter:123:read");
+        p3 = new WildcardPermission("newsletter:123,456:read,write");
+        p4 = new WildcardPermission("newsletter:read");
+        p5 = new WildcardPermission("newsletter:read,write");
+        p6 = new WildcardPermission("newsletter:123:read:write");
+        assertTrue(p1.implies(p2));
+        assertFalse(p1.implies(p3));
+        assertFalse(p1.implies(p4));
+        assertFalse(p1.implies(p5));
+        assertTrue(p1.implies(p6));
+
+        p1 = new WildcardPermission("newsletter:*:read:*");
+        assertTrue(p1.implies(p2));
+        assertTrue(p1.implies(p6));
+
+    }
+
+}
\ No newline at end of file

Added: incubator/jsecurity/trunk/core/test/org/jsecurity/realm/activedirectory/ActiveDirectoryRealmTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/test/org/jsecurity/realm/activedirectory/ActiveDirectoryRealmTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/core/test/org/jsecurity/realm/activedirectory/ActiveDirectoryRealmTest.java
(added)
+++ incubator/jsecurity/trunk/core/test/org/jsecurity/realm/activedirectory/ActiveDirectoryRealmTest.java
Thu Jan  8 19:12:45 2009
@@ -0,0 +1,152 @@
+/*
+ * 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.jsecurity.realm.activedirectory;
+
+import org.jsecurity.authc.*;
+import org.jsecurity.authc.credential.CredentialsMatcher;
+import org.jsecurity.authz.AuthorizationInfo;
+import org.jsecurity.authz.SimpleAuthorizationInfo;
+import org.jsecurity.mgt.DefaultSecurityManager;
+import org.jsecurity.realm.AuthorizingRealm;
+import org.jsecurity.realm.UserIdPrincipal;
+import org.jsecurity.realm.UsernamePrincipal;
+import org.jsecurity.realm.ldap.LdapContextFactory;
+import org.jsecurity.subject.PrincipalCollection;
+import org.jsecurity.subject.SimplePrincipalCollection;
+import org.jsecurity.subject.Subject;
+import org.junit.After;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.naming.NamingException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Simple test case for ActiveDirectoryRealm.
+ *
+ * todo:  While the original incarnation of this test case does not actually test the
+ * heart of ActiveDirectoryRealm (no meaningful implemenation of queryForLdapAccount, etc)
it obviously should.
+ * This version was intended to mimic my current usage scenario in an effort to debug upgrade
issues which were not related
+ * to LDAP connectivity.
+ *
+ * @author Tim Veil
+ */
+public class ActiveDirectoryRealmTest {
+
+    DefaultSecurityManager securityManager = null;
+    AuthorizingRealm realm;
+
+    private static final String USERNAME = "testuser";
+    private static final String PASSWORD = "password";
+    private static final int USER_ID = 12345;
+    private static final String ROLE = "admin";
+
+    @Before
+    public void setup() {
+        realm = new TestActiveDirectoryRealm();
+        securityManager = new DefaultSecurityManager(realm);
+
+    }
+
+    @After
+    public void tearDown() {
+        if (securityManager != null) {
+            securityManager.destroy();
+        }
+    }
+
+    @Test
+    public void testDefaultConfig() {
+        InetAddress localhost = null;
+        try {
+            localhost = InetAddress.getLocalHost();
+        } catch (UnknownHostException e) {
+            e.printStackTrace();
+        }
+        Subject subject = securityManager.login(new UsernamePasswordToken(USERNAME, PASSWORD,
localhost));
+        assertTrue(subject.isAuthenticated());
+        assertTrue(subject.hasRole(ROLE));
+
+
+        UsernamePrincipal usernamePrincipal = subject.getPrincipals().oneByType(UsernamePrincipal.class);
+        assertTrue(usernamePrincipal.getUsername().equals(USERNAME));
+
+        UserIdPrincipal userIdPrincipal = subject.getPrincipals().oneByType(UserIdPrincipal.class);
+        assertTrue(userIdPrincipal.getUserId() == USER_ID);
+
+        Object principals = subject.getPrincipal();
+
+        assertTrue(realm.hasRole(subject.getPrincipals(), ROLE));
+
+        subject.logout();
+    }
+
+    public class TestActiveDirectoryRealm extends ActiveDirectoryRealm {
+
+        /*--------------------------------------------
+        |         C O N S T R U C T O R S           |
+            ============================================*/
+        CredentialsMatcher credentialsMatcher;
+
+        public TestActiveDirectoryRealm() {
+            super();
+
+
+            credentialsMatcher = new CredentialsMatcher() {
+                public boolean doCredentialsMatch(AuthenticationToken object, AuthenticationInfo
object1) {
+                    return true;
+                }
+            };
+
+            setCredentialsMatcher(credentialsMatcher);
+        }
+
+
+        protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws
AuthenticationException {
+            SimpleAccount account = (SimpleAccount) super.doGetAuthenticationInfo(token);
+
+            if (account != null) {
+                SimplePrincipalCollection principals = new SimplePrincipalCollection();
+                principals.add(new UserIdPrincipal(USER_ID), getName());
+                principals.add(new UsernamePrincipal(USERNAME), getName());
+                account.setPrincipals(principals);
+            }
+
+            return account;
+
+        }
+
+        protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
{
+            Set<String> roles = new HashSet<String>();
+            roles.add(ROLE);
+            return new SimpleAuthorizationInfo(roles);
+        }
+
+        // override ldap query because i don't care about testing that piece in this case
+        protected AuthenticationInfo queryForAuthenticationInfo(AuthenticationToken token,
LdapContextFactory ldapContextFactory) throws NamingException {
+            return new SimpleAccount(token.getPrincipal(), token.getCredentials(), getName());
+        }
+
+    }
+
+}
\ No newline at end of file

Added: incubator/jsecurity/trunk/web/test/org/jsecurity/web/attr/CookieAttributeTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/web/test/org/jsecurity/web/attr/CookieAttributeTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/web/test/org/jsecurity/web/attr/CookieAttributeTest.java (added)
+++ incubator/jsecurity/trunk/web/test/org/jsecurity/web/attr/CookieAttributeTest.java Thu
Jan  8 19:12:45 2009
@@ -0,0 +1,70 @@
+/*
+ * 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.jsecurity.web.attr;
+
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.*;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author Les Hazlewood
+ * @since 0.9
+ */
+public class CookieAttributeTest extends TestCase {
+
+    private CookieAttribute<String> cookieAttribute;
+    private HttpServletRequest mockRequest;
+    private HttpServletResponse mockResponse;
+
+    @Before
+    public void setUp() throws Exception {
+        this.mockRequest = createMock(HttpServletRequest.class);
+        this.mockResponse = createMock(HttpServletResponse.class);
+        this.cookieAttribute = new CookieAttribute<String>("test");
+    }
+
+    @Test
+    //Verifies fix for JSEC-94
+    public void testRemoveValue() throws Exception {
+
+        Cookie cookie = new Cookie("test", "blah");
+        cookie.setMaxAge(2351234); //doesn't matter what the time is
+        Cookie[] cookies = new Cookie[]{cookie};
+
+        expect(mockRequest.getCookies()).andReturn(cookies);
+        //no path set on the cookie, so we expect to retrieve it from the context path
+        expect(mockRequest.getContextPath()).andReturn("/somepath");
+        mockResponse.addCookie(cookie);
+        replay(mockRequest);
+        replay(mockResponse);
+
+        cookieAttribute.removeValue(mockRequest, mockResponse);
+
+        verify(mockRequest);
+        verify(mockResponse);
+
+        assertTrue(cookie.getMaxAge() == 0);
+        assertTrue(cookie.getPath().equals("/somepath"));
+    }
+}

Added: incubator/jsecurity/trunk/web/test/org/jsecurity/web/servlet/JSecurityFilterTest.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/web/test/org/jsecurity/web/servlet/JSecurityFilterTest.java?rev=732915&view=auto
==============================================================================
--- incubator/jsecurity/trunk/web/test/org/jsecurity/web/servlet/JSecurityFilterTest.java
(added)
+++ incubator/jsecurity/trunk/web/test/org/jsecurity/web/servlet/JSecurityFilterTest.java
Thu Jan  8 19:12:45 2009
@@ -0,0 +1,84 @@
+/*
+ * 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.jsecurity.web.servlet;
+
+import static org.easymock.EasyMock.*;
+import org.junit.Test;
+
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+
+/**
+ * @author Les Hazlewood
+ * @since 0.9
+ */
+public class JSecurityFilterTest {
+
+    private JSecurityFilter filter;
+    private FilterConfig mockFilterConfig;
+    private ServletContext mockServletContext;
+
+    protected void setUp(String config) {
+        mockFilterConfig = createMock(FilterConfig.class);
+        mockServletContext = createMock(ServletContext.class);
+
+        expect(mockFilterConfig.getServletContext()).andReturn(mockServletContext);
+        expect(mockFilterConfig.getInitParameter(JSecurityFilter.CONFIG_CLASS_NAME_INIT_PARAM_NAME)).andReturn(null).once();
+        expect(mockFilterConfig.getInitParameter(JSecurityFilter.CONFIG_INIT_PARAM_NAME)).andReturn(config).once();
+        expect(mockFilterConfig.getInitParameter(JSecurityFilter.CONFIG_URL_INIT_PARAM_NAME)).andReturn(null).once();
+    }
+
+    public void tearDown() throws Exception {
+        reset(mockServletContext);
+        reset(mockFilterConfig);
+
+        replay(mockServletContext);
+
+        //this.filter.destroy();
+
+        verify(mockServletContext);
+        verify(mockFilterConfig);
+    }
+
+    protected void replayAndVerify() throws Exception {
+        replay(mockServletContext);
+        replay(mockFilterConfig);
+
+        this.filter = new JSecurityFilter();
+        this.filter.init(mockFilterConfig);
+
+
+        verify(mockFilterConfig);
+        verify(mockServletContext);
+    }
+
+
+    @Test
+    public void testDefaultConfig() throws Exception {
+        setUp(null);
+        replayAndVerify();
+    }
+
+    @Test
+    public void testSimpleConfig() throws Exception {
+        setUp("[filters]\n" +
+                "authc.successUrl = /index.jsp");
+        replayAndVerify();
+    }
+}



Mime
View raw message