|
24 | 24 | package org.opengrok.indexer.authorization;
|
25 | 25 |
|
26 | 26 | import java.util.Arrays;
|
| 27 | +import java.util.HashMap; |
27 | 28 | import java.util.List;
|
28 | 29 | import java.util.Locale;
|
29 | 30 | import java.util.Map;
|
@@ -69,6 +70,14 @@ public static StackSetup[][] params() {
|
69 | 70 | NewTest(true, createUnallowedProject()),
|
70 | 71 | NewTest(true, createUnallowedGroup()))
|
71 | 72 | },
|
| 73 | + // Test that null entities will result in denial. |
| 74 | + { |
| 75 | + new StackSetup( |
| 76 | + NewStack(AuthControlFlag.REQUIRED), |
| 77 | + // no plugins should return true however we have null entities here |
| 78 | + NewTest(false, (Project) null), |
| 79 | + NewTest(false, (Group) null)) |
| 80 | + }, |
72 | 81 | // -------------------------------------------------------------- //
|
73 | 82 | //
|
74 | 83 | // Test authorization flags for plugins. Both plugins do not fail
|
@@ -657,14 +666,15 @@ public void testPluginsGeneric() {
|
657 | 666 | String format = "%s <%s> was <%s> for entity %s";
|
658 | 667 |
|
659 | 668 | for (TestCase innerSetup : setup.setup) {
|
| 669 | + String entityName = (innerSetup.entity == null ? "null" : innerSetup.entity.getName()); |
660 | 670 | try {
|
661 | 671 | actual = framework.isAllowed(innerSetup.request, (Group) innerSetup.entity);
|
662 |
| - Assert.assertEquals(String.format(format, setup.toString(), innerSetup.expected, actual, innerSetup.entity.getName()), |
| 672 | + Assert.assertEquals(String.format(format, setup.toString(), innerSetup.expected, actual, entityName), |
663 | 673 | innerSetup.expected,
|
664 | 674 | actual);
|
665 | 675 | } catch (ClassCastException ex) {
|
666 | 676 | actual = framework.isAllowed(innerSetup.request, (Project) innerSetup.entity);
|
667 |
| - Assert.assertEquals(String.format(format, setup.toString(), innerSetup.expected, actual, innerSetup.entity.getName()), |
| 677 | + Assert.assertEquals(String.format(format, setup.toString(), innerSetup.expected, actual, entityName), |
668 | 678 | innerSetup.expected,
|
669 | 679 | actual);
|
670 | 680 | }
|
@@ -692,7 +702,12 @@ static private Group createUnallowedGroup() {
|
692 | 702 | }
|
693 | 703 |
|
694 | 704 | static private HttpServletRequest createRequest() {
|
695 |
| - return new DummyHttpServletRequest(); |
| 705 | + return new DummyHttpServletRequest() { |
| 706 | + @Override |
| 707 | + public Map<String, String[]> getParameterMap() { |
| 708 | + return new HashMap<>(); |
| 709 | + } |
| 710 | + }; |
696 | 711 | }
|
697 | 712 |
|
698 | 713 | static private IAuthorizationPlugin createAllowedPrefixPlugin() {
|
@@ -792,7 +807,7 @@ public TestCase(boolean expected, HttpServletRequest request, Nameable entity) {
|
792 | 807 |
|
793 | 808 | @Override
|
794 | 809 | public String toString() {
|
795 |
| - return "expected <" + expected + "> for entity " + entity.getName(); |
| 810 | + return "expected <" + expected + "> for entity " + (entity == null ? "null" : entity.getName()); |
796 | 811 | }
|
797 | 812 | }
|
798 | 813 |
|
|
0 commit comments