|
| 1 | +/* |
| 2 | + * The contents of this file are subject to the terms of the Common Development and |
| 3 | + * Distribution License (the License). You may not use this file except in compliance with the |
| 4 | + * License. |
| 5 | + * |
| 6 | + * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the |
| 7 | + * specific language governing permission and limitations under the License. |
| 8 | + * |
| 9 | + * When distributing Covered Software, include this CDDL Header Notice in each file and include |
| 10 | + * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL |
| 11 | + * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| 12 | + * information: "Portions Copyright [year] [name of copyright owner]". |
| 13 | + * |
| 14 | + * Copyright 2026 3A Systems, LLC. |
| 15 | + */ |
| 16 | +package org.opends.server.authorization.dseecompat; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.*; |
| 19 | + |
| 20 | +import org.forgerock.opendj.ldap.ByteString; |
| 21 | +import org.forgerock.opendj.ldap.DN; |
| 22 | +import org.opends.server.DirectoryServerTestCase; |
| 23 | +import org.opends.server.TestCaseUtils; |
| 24 | +import org.opends.server.types.DirectoryException; |
| 25 | +import org.testng.annotations.AfterClass; |
| 26 | +import org.testng.annotations.BeforeClass; |
| 27 | +import org.testng.annotations.DataProvider; |
| 28 | +import org.testng.annotations.Test; |
| 29 | + |
| 30 | +/** |
| 31 | + * Verifies that {@link BindRule#decode(String)} rejects a boolean ("and"/"or") |
| 32 | + * bind rule that is missing one of its operands, instead of throwing a |
| 33 | + * {@link NullPointerException}. An empty group such as "()" decodes to a null |
| 34 | + * bind rule; before this fix, using such a group as the left side, or leaving |
| 35 | + * the right side of the boolean empty (e.g. "(()or)"), dereferenced that null |
| 36 | + * while parsing and failed with an NPE rather than a diagnosable |
| 37 | + * {@link AciException} (issue #719). |
| 38 | + */ |
| 39 | +@SuppressWarnings("javadoc") |
| 40 | +public class BindRuleOperandTest extends DirectoryServerTestCase |
| 41 | +{ |
| 42 | + @BeforeClass |
| 43 | + public void setUp() throws Exception |
| 44 | + { |
| 45 | + TestCaseUtils.startFakeServer(); |
| 46 | + } |
| 47 | + |
| 48 | + @AfterClass |
| 49 | + public void tearDown() throws DirectoryException |
| 50 | + { |
| 51 | + TestCaseUtils.shutdownFakeServer(); |
| 52 | + } |
| 53 | + |
| 54 | + @DataProvider(name = "bindRulesWithMissingOperand") |
| 55 | + public Object[][] bindRulesWithMissingOperand() |
| 56 | + { |
| 57 | + return new Object[][] { |
| 58 | + // the exact bind rule from issue #719: "or" with no right operand and an |
| 59 | + // empty left group |
| 60 | + { "(()or)" }, |
| 61 | + // empty right operand after a valid left operand |
| 62 | + { "(userdn=\"ldap:///self\" or)" }, |
| 63 | + { "(userdn=\"ldap:///self\" and)" }, |
| 64 | + // empty left operand before a valid right operand |
| 65 | + { "()or userdn=\"ldap:///self\"" }, |
| 66 | + // an empty group is not a bind rule on its own |
| 67 | + { "()" }, |
| 68 | + // a nested empty group is still empty |
| 69 | + { "(())" }, |
| 70 | + // a whitespace-only group is empty once trimmed |
| 71 | + { "( )" }, |
| 72 | + // empty right *group*: reaches the decode-level guard from createBindRule |
| 73 | + { "(userdn=\"ldap:///self\" or ())" }, |
| 74 | + // "not" applied to an empty group |
| 75 | + { "not ()" }, |
| 76 | + }; |
| 77 | + } |
| 78 | + |
| 79 | + @Test(dataProvider = "bindRulesWithMissingOperand") |
| 80 | + public void rejectsMissingOperand(String bindRule) |
| 81 | + { |
| 82 | + assertThatThrownBy(() -> BindRule.decode(bindRule)).isInstanceOf(AciException.class); |
| 83 | + } |
| 84 | + |
| 85 | + @DataProvider(name = "validBindRules") |
| 86 | + public Object[][] validBindRules() |
| 87 | + { |
| 88 | + return new Object[][] { |
| 89 | + // a valid rule inside a nested group must still decode: guards must not |
| 90 | + // start over-rejecting non-empty groups |
| 91 | + { "((userdn=\"ldap:///self\"))" }, |
| 92 | + // a valid complex rule with both operands present |
| 93 | + { "(userdn=\"ldap:///self\" or userdn=\"ldap:///anyone\")" }, |
| 94 | + }; |
| 95 | + } |
| 96 | + |
| 97 | + @Test(dataProvider = "validBindRules") |
| 98 | + public void acceptsValidBindRule(String bindRule) throws Exception |
| 99 | + { |
| 100 | + assertThat(BindRule.decode(bindRule)).isNotNull(); |
| 101 | + } |
| 102 | + |
| 103 | + @DataProvider(name = "acisWithMissingOperand") |
| 104 | + public Object[][] acisWithMissingOperand() |
| 105 | + { |
| 106 | + return new Object[][] { |
| 107 | + // the full ACI from issue #719 |
| 108 | + { "(version 3.0; acl \"ac\"; allow (search)(()or) (userdn=\"ldap:///self\"); )" }, |
| 109 | + // missing *left* operand: previously accepted and stored with left == null, |
| 110 | + // then NPEd during evaluation. Must now be rejected at decode time. |
| 111 | + { "(version 3.0; acl \"ac\"; allow (search) ()or userdn=\"ldap:///self\"; )" }, |
| 112 | + }; |
| 113 | + } |
| 114 | + |
| 115 | + /** Reproduces missing-operand ACIs from issue #719 through {@link Aci#decode}. */ |
| 116 | + @Test(dataProvider = "acisWithMissingOperand") |
| 117 | + public void decodeOfAciWithMissingOperandThrowsAciException(String aci) |
| 118 | + { |
| 119 | + assertThatThrownBy(() -> Aci.decode(ByteString.valueOfUtf8(aci), DN.rootDN())) |
| 120 | + .isInstanceOf(AciException.class); |
| 121 | + } |
| 122 | +} |
0 commit comments