Fixes a test bug for the DeprecationRestHandler where an empty string

could be randomly produced as a header to test against, which is rejected
by header validation as an invalid header.
This commit is contained in:
Ali Beyad 2016-09-21 13:07:40 -04:00
parent d55bd707a3
commit 86c3bdb8a5
1 changed files with 9 additions and 2 deletions

View File

@ -78,8 +78,15 @@ public class DeprecationRestHandlerTests extends ESTestCase {
ASCIIHeaderGenerator generator = new ASCIIHeaderGenerator();
String value = generator.ofCodeUnitsLength(random(), 1, 50);
assertTrue(DeprecationRestHandler.validHeaderValue(value));
assertSame(value, DeprecationRestHandler.requireValidHeader(value));
if (value.trim().length() == 0) {
// empty text, not a valid header
assertFalse(DeprecationRestHandler.validHeaderValue(value));
Exception e = expectThrows(IllegalArgumentException.class, () -> DeprecationRestHandler.requireValidHeader(value));
assertEquals("header value must contain only US ASCII text", e.getMessage());
} else {
assertTrue(DeprecationRestHandler.validHeaderValue(value));
assertSame(value, DeprecationRestHandler.requireValidHeader(value));
}
}
public void testInvalidHeaderValue() {