|
@@ -1,4 +1,4 @@
|
|
-/* Copyright 2004 Acegi Technology Pty Limited
|
|
|
|
|
|
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -19,15 +19,13 @@ import junit.framework.TestCase;
|
|
|
|
|
|
import org.acegisecurity.ConfigAttributeDefinition;
|
|
import org.acegisecurity.ConfigAttributeDefinition;
|
|
import org.acegisecurity.MockFilterChain;
|
|
import org.acegisecurity.MockFilterChain;
|
|
-
|
|
|
|
-
|
|
|
|
import org.acegisecurity.SecurityConfig;
|
|
import org.acegisecurity.SecurityConfig;
|
|
|
|
|
|
-import java.util.Iterator;
|
|
|
|
-
|
|
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
import org.springframework.mock.web.MockHttpServletResponse;
|
|
import org.springframework.mock.web.MockHttpServletResponse;
|
|
|
|
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* Tests {@link FilterInvocationDefinitionSourceEditor} and its associated
|
|
* Tests {@link FilterInvocationDefinitionSourceEditor} and its associated
|
|
@@ -49,14 +47,14 @@ public class FilterInvocationDefinitionSourceEditorTests extends TestCase {
|
|
|
|
|
|
//~ Methods ================================================================
|
|
//~ Methods ================================================================
|
|
|
|
|
|
- public final void setUp() throws Exception {
|
|
|
|
- super.setUp();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
junit.textui.TestRunner.run(FilterInvocationDefinitionSourceEditorTests.class);
|
|
junit.textui.TestRunner.run(FilterInvocationDefinitionSourceEditorTests.class);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public final void setUp() throws Exception {
|
|
|
|
+ super.setUp();
|
|
|
|
+ }
|
|
|
|
+
|
|
public void testConvertUrlToLowercaseDefaultSettingUnchangedByEditor() {
|
|
public void testConvertUrlToLowercaseDefaultSettingUnchangedByEditor() {
|
|
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor();
|
|
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor();
|
|
editor.setAsText(
|
|
editor.setAsText(
|
|
@@ -67,6 +65,19 @@ public class FilterInvocationDefinitionSourceEditorTests extends TestCase {
|
|
assertFalse(map.isConvertUrlToLowercaseBeforeComparison());
|
|
assertFalse(map.isConvertUrlToLowercaseBeforeComparison());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void testConvertUrlToLowercaseDetectsUppercaseEntries() {
|
|
|
|
+ FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ editor.setAsText(
|
|
|
|
+ "CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON\r\nPATTERN_TYPE_APACHE_ANT\r\n\\/secUre/super/**=ROLE_WE_DONT_HAVE");
|
|
|
|
+ fail("Should have thrown IllegalArgumentException");
|
|
|
|
+ } catch (IllegalArgumentException expected) {
|
|
|
|
+ assertTrue(expected.getMessage()
|
|
|
|
+ .lastIndexOf("you have specified an uppercase character in line") != -1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public void testConvertUrlToLowercaseSettingApplied() {
|
|
public void testConvertUrlToLowercaseSettingApplied() {
|
|
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor();
|
|
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor();
|
|
editor.setAsText(
|
|
editor.setAsText(
|
|
@@ -87,6 +98,45 @@ public class FilterInvocationDefinitionSourceEditorTests extends TestCase {
|
|
assertTrue(map instanceof RegExpBasedFilterInvocationDefinitionMap);
|
|
assertTrue(map instanceof RegExpBasedFilterInvocationDefinitionMap);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void testDetectsDuplicateDirectivesOnSameLineSituation1() {
|
|
|
|
+ FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ editor.setAsText(
|
|
|
|
+ "CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON PATTERN_TYPE_APACHE_ANT\r\n\\/secure/super/**=ROLE_WE_DONT_HAVE");
|
|
|
|
+ fail("Should have thrown IllegalArgumentException");
|
|
|
|
+ } catch (IllegalArgumentException expected) {
|
|
|
|
+ assertTrue(expected.getMessage()
|
|
|
|
+ .lastIndexOf("Line appears to be malformed") != -1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void testDetectsDuplicateDirectivesOnSameLineSituation2() {
|
|
|
|
+ FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ editor.setAsText(
|
|
|
|
+ "CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON\r\nPATTERN_TYPE_APACHE_ANT /secure/super/**=ROLE_WE_DONT_HAVE");
|
|
|
|
+ fail("Should have thrown IllegalArgumentException");
|
|
|
|
+ } catch (IllegalArgumentException expected) {
|
|
|
|
+ assertTrue(expected.getMessage()
|
|
|
|
+ .lastIndexOf("Line appears to be malformed") != -1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void testDetectsDuplicateDirectivesOnSameLineSituation3() {
|
|
|
|
+ FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ editor.setAsText(
|
|
|
|
+ "PATTERN_TYPE_APACHE_ANT\r\nCONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON /secure/super/**=ROLE_WE_DONT_HAVE");
|
|
|
|
+ fail("Should have thrown IllegalArgumentException");
|
|
|
|
+ } catch (IllegalArgumentException expected) {
|
|
|
|
+ assertTrue(expected.getMessage()
|
|
|
|
+ .lastIndexOf("Line appears to be malformed") != -1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public void testEmptyStringReturnsEmptyMap() {
|
|
public void testEmptyStringReturnsEmptyMap() {
|
|
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor();
|
|
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor();
|
|
editor.setAsText("");
|
|
editor.setAsText("");
|
|
@@ -158,7 +208,7 @@ public class FilterInvocationDefinitionSourceEditorTests extends TestCase {
|
|
Class clazz = RegExpBasedFilterInvocationDefinitionMap.EntryHolder.class;
|
|
Class clazz = RegExpBasedFilterInvocationDefinitionMap.EntryHolder.class;
|
|
|
|
|
|
try {
|
|
try {
|
|
- clazz.getDeclaredConstructor((Class[])null);
|
|
|
|
|
|
+ clazz.getDeclaredConstructor((Class[]) null);
|
|
fail("Should have thrown NoSuchMethodException");
|
|
fail("Should have thrown NoSuchMethodException");
|
|
} catch (NoSuchMethodException expected) {
|
|
} catch (NoSuchMethodException expected) {
|
|
assertTrue(true);
|
|
assertTrue(true);
|