forked from linkedin/zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZOOKEEPER-3613: ZKConfig fails to return proper value on getBoolean()…
…when user accidentally includes spaces at the end of the value Author: sujithsimon22 <sujith.abraham.simon@huawei.com> Reviewers: Allan Lyu <fangmin@apache.org>,Justin Mao Ling <maoling199210191@sina.com>,Mohammad Arshad <arshad@apache.org> Closes apache#1190 from sujithsimon22/3613
- Loading branch information
1 parent
49ad75b
commit dcef1a6
Showing
2 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
zookeeper-server/src/test/java/org/apache/zookeeper/common/ZKConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.zookeeper.common; | ||
|
||
|
||
import static org.junit.Assert.assertEquals; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.After; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.Timeout; | ||
|
||
|
||
|
||
public class ZKConfigTest { | ||
|
||
X509Util x509Util = new ClientX509Util(); | ||
|
||
@Rule | ||
public Timeout timeout = new Timeout(10, TimeUnit.SECONDS); | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
System.clearProperty(x509Util.getSslProtocolProperty()); | ||
} | ||
|
||
// property is not set we should get the default value | ||
@Test | ||
public void testBooleanRetrievalFromPropertyDefault() { | ||
ZKConfig conf = new ZKConfig(); | ||
String prop = "UnSetProperty" + System.currentTimeMillis(); | ||
boolean defaultValue = false; | ||
boolean result = conf.getBoolean(prop, defaultValue); | ||
assertEquals(defaultValue, result); | ||
} | ||
|
||
// property is set to an valid boolean, we should get the set value | ||
@Test | ||
public void testBooleanRetrievalFromProperty() { | ||
boolean value = true; | ||
boolean defaultValue = false; | ||
System.setProperty(x509Util.getSslProtocolProperty(), Boolean.toString(value)); | ||
ZKConfig conf = new ZKConfig(); | ||
boolean result = conf.getBoolean(x509Util.getSslProtocolProperty(), defaultValue); | ||
assertEquals(value, result); | ||
} | ||
|
||
// property is set but with white spaces in the beginning | ||
@Test | ||
public void testBooleanRetrievalFromPropertyWithWhitespacesInBeginning() { | ||
boolean value = true; | ||
boolean defaultValue = false; | ||
System.setProperty(x509Util.getSslProtocolProperty(), " " + value); | ||
ZKConfig conf = new ZKConfig(); | ||
boolean result = conf.getBoolean(x509Util.getSslProtocolProperty(), defaultValue); | ||
assertEquals(value, result); | ||
} | ||
|
||
// property is set but with white spaces at the end | ||
@Test | ||
public void testBooleanRetrievalFromPropertyWithWhitespacesAtEnd() { | ||
boolean value = true; | ||
boolean defaultValue = false; | ||
System.setProperty(x509Util.getSslProtocolProperty(), value + " "); | ||
ZKConfig conf = new ZKConfig(); | ||
boolean result = conf.getBoolean(x509Util.getSslProtocolProperty(), defaultValue); | ||
assertEquals(value, result); | ||
} | ||
|
||
// property is set but with white spaces at the beginning and the end | ||
@Test | ||
public void testBooleanRetrievalFromPropertyWithWhitespacesAtBeginningAndEnd() { | ||
boolean value = true; | ||
boolean defaultValue = false; | ||
System.setProperty(x509Util.getSslProtocolProperty(), " " + value + " "); | ||
ZKConfig conf = new ZKConfig(); | ||
boolean result = conf.getBoolean(x509Util.getSslProtocolProperty(), defaultValue); | ||
assertEquals(value, result); | ||
} | ||
} |