mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

matthew_swift
17.05.2007 f42bb1f095f0b3eac12684f5f0794ae5d61a9db5
Fix issue 1960: restrict the allowed values of boolean properties.

Before this change we allowed all sorts of boolean-like values for boolean properties, eg. true, false, yes, no, 1, 0, enabled, etc. These are always normalized to one of true or false. However, this normalization may confuse users, since they might expect that if they set a property to "yes" then the next time they view its value they might expect to see "yes", when in fact they'll see "true". This change restricts the set of permitted boolean values to just true or false.
3 files modified
42 ■■■■■ changed files
opends/src/server/org/opends/server/admin/BooleanPropertyDefinition.java 12 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/admin/PropertyDefinitionUsageBuilder.java 6 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/admin/BooleanPropertyDefinitionTest.java 24 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/admin/BooleanPropertyDefinition.java
@@ -52,19 +52,9 @@
  static {
    VALUE_MAP = new HashMap<String, Boolean>();
    VALUE_MAP.put("0", Boolean.FALSE);
    VALUE_MAP.put("no", Boolean.FALSE);
    VALUE_MAP.put("off", Boolean.FALSE);
    // We could have more possibilities but decided against in issue 1960.
    VALUE_MAP.put("false", Boolean.FALSE);
    VALUE_MAP.put("disable", Boolean.FALSE);
    VALUE_MAP.put("disabled", Boolean.FALSE);
    VALUE_MAP.put("1", Boolean.TRUE);
    VALUE_MAP.put("yes", Boolean.TRUE);
    VALUE_MAP.put("on", Boolean.TRUE);
    VALUE_MAP.put("true", Boolean.TRUE);
    VALUE_MAP.put("enable", Boolean.TRUE);
    VALUE_MAP.put("enabled", Boolean.TRUE);
  }
opends/src/server/org/opends/server/admin/PropertyDefinitionUsageBuilder.java
@@ -83,7 +83,11 @@
     */
    @Override
    public String visitBoolean(BooleanPropertyDefinition d, Void p) {
      return "BOOLEAN";
      if (isDetailed) {
        return "false | true";
      } else {
        return "BOOLEAN";
      }
    }
opends/tests/unit-tests-testng/src/server/org/opends/server/admin/BooleanPropertyDefinitionTest.java
@@ -29,6 +29,7 @@
import static org.testng.Assert.*;
import org.opends.server.TestCaseUtils;
import org.opends.server.admin.std.meta.RootCfgDefn;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
@@ -42,10 +43,17 @@
  BooleanPropertyDefinition.Builder builder = null;
  /**
   * Sets up tests
   * Sets up tests.
   *
   * @throws Exception
   *           If the server could not be initialized.
   */
  @BeforeClass
  public void setUp() {
  public void setUp() throws Exception {
    // This test suite depends on having the schema available, so
    // we'll start the server.
    TestCaseUtils.startServer();
    builder = BooleanPropertyDefinition.createBuilder(
        RootCfgDefn.getInstance(), "test-property");
  }
@@ -74,18 +82,8 @@
  @DataProvider(name = "testDecodeValueData")
  public Object[][] createvalidateValueData() {
    return new Object[][]{
            {"0", Boolean.FALSE},
            {"no", Boolean.FALSE},
            {"off", Boolean.FALSE},
            {"false", Boolean.FALSE},
            {"disable", Boolean.FALSE},
            {"disabled", Boolean.FALSE},
            {"1", Boolean.TRUE},
            {"yes", Boolean.TRUE},
            {"on", Boolean.TRUE},
            {"true", Boolean.TRUE},
            {"enable", Boolean.TRUE},
            {"enabled", Boolean.TRUE},
            {"true", Boolean.TRUE}
    };
  }