< prev index next >
test/jdk/java/net/httpclient/http2/jdk.incubator.httpclient/jdk/incubator/http/internal/hpack/DecoderTest.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 22,33 ****
*/
package jdk.incubator.http.internal.hpack;
import org.testng.annotations.Test;
import java.io.UncheckedIOException;
- import java.net.ProtocolException;
import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;
--- 22,33 ----
*/
package jdk.incubator.http.internal.hpack;
import org.testng.annotations.Test;
+ import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;
*** 398,408 ****
//
// This test is missing in the spec
//
@Test
! public void sizeUpdate() {
Decoder d = new Decoder(4096);
assertEquals(d.getTable().maxSize(), 4096);
d.decode(ByteBuffer.wrap(new byte[]{0b00111110}), true, nopCallback()); // newSize = 30
assertEquals(d.getTable().maxSize(), 30);
}
--- 398,408 ----
//
// This test is missing in the spec
//
@Test
! public void sizeUpdate() throws IOException {
Decoder d = new Decoder(4096);
assertEquals(d.getTable().maxSize(), 4096);
d.decode(ByteBuffer.wrap(new byte[]{0b00111110}), true, nopCallback()); // newSize = 30
assertEquals(d.getTable().maxSize(), 30);
}
*** 419,456 ****
e.header("a", "b");
e.encode(b);
b.flip();
{
Decoder d = new Decoder(4096);
! UncheckedIOException ex = assertVoidThrows(UncheckedIOException.class,
() -> d.decode(b, true, (name, value) -> { }));
-
- assertNotNull(ex.getCause());
- assertEquals(ex.getCause().getClass(), ProtocolException.class);
}
b.flip();
{
Decoder d = new Decoder(4096);
! UncheckedIOException ex = assertVoidThrows(UncheckedIOException.class,
() -> d.decode(b, false, (name, value) -> { }));
-
- assertNotNull(ex.getCause());
- assertEquals(ex.getCause().getClass(), ProtocolException.class);
}
}
@Test
public void corruptedHeaderBlockInteger() {
Decoder d = new Decoder(4096);
ByteBuffer data = ByteBuffer.wrap(new byte[]{
(byte) 0b11111111, // indexed
(byte) 0b10011010 // 25 + ...
});
! UncheckedIOException e = assertVoidThrows(UncheckedIOException.class,
() -> d.decode(data, true, nopCallback()));
- assertNotNull(e.getCause());
- assertEquals(e.getCause().getClass(), ProtocolException.class);
assertExceptionMessageContains(e, "Unexpected end of header block");
}
// 5.1. Integer Representation
// ...
--- 419,448 ----
e.header("a", "b");
e.encode(b);
b.flip();
{
Decoder d = new Decoder(4096);
! assertVoidThrows(IOException.class,
() -> d.decode(b, true, (name, value) -> { }));
}
b.flip();
{
Decoder d = new Decoder(4096);
! assertVoidThrows(IOException.class,
() -> d.decode(b, false, (name, value) -> { }));
}
}
@Test
public void corruptedHeaderBlockInteger() {
Decoder d = new Decoder(4096);
ByteBuffer data = ByteBuffer.wrap(new byte[]{
(byte) 0b11111111, // indexed
(byte) 0b10011010 // 25 + ...
});
! IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Unexpected end of header block");
}
// 5.1. Integer Representation
// ...
*** 469,482 ****
(byte) 0b11111111,
(byte) 0b11111111,
(byte) 0b00000111
});
! IllegalArgumentException e = assertVoidThrows(IllegalArgumentException.class,
() -> d.decode(data, true, nopCallback()));
! assertExceptionMessageContains(e, "index=2147483647");
}
@Test
public void headerBlockIntegerOverflow() {
Decoder d = new Decoder(4096);
--- 461,474 ----
(byte) 0b11111111,
(byte) 0b11111111,
(byte) 0b00000111
});
! IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
! assertExceptionMessageContains(e.getCause(), "index=2147483647");
}
@Test
public void headerBlockIntegerOverflow() {
Decoder d = new Decoder(4096);
*** 488,498 ****
(byte) 0b11111111,
(byte) 0b11111111,
(byte) 0b00000111
});
! IllegalArgumentException e = assertVoidThrows(IllegalArgumentException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Integer overflow");
}
--- 480,490 ----
(byte) 0b11111111,
(byte) 0b11111111,
(byte) 0b00000111
});
! IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Integer overflow");
}
*** 505,518 ****
0b00001000, // huffman=false, length=8
0b00000000, // \
0b00000000, // but only 3 octets available...
0b00000000 // /
});
! UncheckedIOException e = assertVoidThrows(UncheckedIOException.class,
() -> d.decode(data, true, nopCallback()));
- assertNotNull(e.getCause());
- assertEquals(e.getCause().getClass(), ProtocolException.class);
assertExceptionMessageContains(e, "Unexpected end of header block");
}
@Test
public void corruptedHeaderBlockString2() {
--- 497,508 ----
0b00001000, // huffman=false, length=8
0b00000000, // \
0b00000000, // but only 3 octets available...
0b00000000 // /
});
! IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Unexpected end of header block");
}
@Test
public void corruptedHeaderBlockString2() {
*** 525,538 ****
0b00000000, // \
0b00000000, // but only 5 octets available...
0b00000000, // /
0b00000000 // /
});
! UncheckedIOException e = assertVoidThrows(UncheckedIOException.class,
() -> d.decode(data, true, nopCallback()));
- assertNotNull(e.getCause());
- assertEquals(e.getCause().getClass(), ProtocolException.class);
assertExceptionMessageContains(e, "Unexpected end of header block");
}
// 5.2. String Literal Representation
// ...A Huffman-encoded string literal containing the EOS symbol MUST be
--- 515,526 ----
0b00000000, // \
0b00000000, // but only 5 octets available...
0b00000000, // /
0b00000000 // /
});
! IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Unexpected end of header block");
}
// 5.2. String Literal Representation
// ...A Huffman-encoded string literal containing the EOS symbol MUST be
*** 545,555 ****
0b00000000,
(byte) 0b10000110, // huffman=true, length=6
0b00011001, 0b01001101, (byte) 0b11111111,
(byte) 0b11111111, (byte) 0b11111111, (byte) 0b11111100
});
! IllegalArgumentException e = assertVoidThrows(IllegalArgumentException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Encountered EOS");
}
--- 533,543 ----
0b00000000,
(byte) 0b10000110, // huffman=true, length=6
0b00011001, 0b01001101, (byte) 0b11111111,
(byte) 0b11111111, (byte) 0b11111111, (byte) 0b11111100
});
! IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Encountered EOS");
}
*** 564,574 ****
0b00000000,
(byte) 0b10000011, // huffman=true, length=3
0b00011001, 0b01001101, (byte) 0b11111111
// len("aei") + len(padding) = (5 + 5 + 5) + (9)
});
! IllegalArgumentException e = assertVoidThrows(IllegalArgumentException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Padding is too long", "len=9");
}
--- 552,562 ----
0b00000000,
(byte) 0b10000011, // huffman=true, length=3
0b00011001, 0b01001101, (byte) 0b11111111
// len("aei") + len(padding) = (5 + 5 + 5) + (9)
});
! IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Padding is too long", "len=9");
}
*** 595,605 ****
0b00001111, // literal, index=15
0b00000000,
(byte) 0b10000011, // huffman=true, length=3
0b00011001, 0b01111010, (byte) 0b11111110
});
! IllegalArgumentException e = assertVoidThrows(IllegalArgumentException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Not a EOS prefix");
}
--- 583,593 ----
0b00001111, // literal, index=15
0b00000000,
(byte) 0b10000011, // huffman=true, length=3
0b00011001, 0b01111010, (byte) 0b11111110
});
! IOException e = assertVoidThrows(IOException.class,
() -> d.decode(data, true, nopCallback()));
assertExceptionMessageContains(e, "Not a EOS prefix");
}
*** 646,662 ****
--- 634,654 ----
return;
}
Decoder d = supplier.get();
do {
ByteBuffer n = i.next();
+ try {
d.decode(n, !i.hasNext(), (name, value) -> {
if (value == null) {
actual.add(name.toString());
} else {
actual.add(name + ": " + value);
}
});
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
} while (i.hasNext());
assertEquals(d.getTable().getStateString(), expectedHeaderTable);
assertEquals(actual.stream().collect(Collectors.joining("\n")), expectedHeaderList);
});
}
*** 669,685 ****
--- 661,681 ----
String expectedHeaderTable, String expectedHeaderList) {
ByteBuffer source = SpecHelper.toBytes(hexdump);
List<String> actual = new LinkedList<>();
+ try {
d.decode(source, true, (name, value) -> {
if (value == null) {
actual.add(name.toString());
} else {
actual.add(name + ": " + value);
}
});
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
assertEquals(d.getTable().getStateString(), expectedHeaderTable);
assertEquals(actual.stream().collect(Collectors.joining("\n")), expectedHeaderList);
}
< prev index next >