|
| 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 | + }; |
| 69 | + } |
| 70 | + |
| 71 | + @Test(dataProvider = "bindRulesWithMissingOperand") |
| 72 | + public void rejectsMissingOperand(String bindRule) |
| 73 | + { |
| 74 | + assertThatThrownBy(() -> BindRule.decode(bindRule)).isInstanceOf(AciException.class); |
| 75 | + } |
| 76 | + |
| 77 | + /** Reproduces the full ACI from issue #719 through {@link Aci#decode}. */ |
| 78 | + @Test |
| 79 | + public void decodeOfAciWithMissingOperandThrowsAciException() |
| 80 | + { |
| 81 | + String aci = "(version 3.0; acl \"ac\"; allow (search)(()or) (userdn=\"ldap:///self\"); )"; |
| 82 | + assertThatThrownBy(() -> Aci.decode(ByteString.valueOfUtf8(aci), DN.rootDN())) |
| 83 | + .isInstanceOf(AciException.class); |
| 84 | + } |
| 85 | +} |
0 commit comments