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.
| | |
| | | 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); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public String visitBoolean(BooleanPropertyDefinition d, Void p) { |
| | | return "BOOLEAN"; |
| | | if (isDetailed) { |
| | | return "false | true"; |
| | | } else { |
| | | return "BOOLEAN"; |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | 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; |
| | |
| | | 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"); |
| | | } |
| | |
| | | @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} |
| | | }; |
| | | } |
| | | |