-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auth Manager API part 1: HTTPRequest, HTTPHeader #11769
base: main
Are you sure you want to change the base?
Changes from 1 commit
7db53d8
e486e0d
0449744
d9a05fb
4c0e650
56ff7b2
ca6eb1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,17 +19,20 @@ | |
package org.apache.iceberg.rest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableListMultimap; | ||
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; | ||
import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
import org.apache.iceberg.relocated.com.google.common.collect.Maps; | ||
import org.apache.iceberg.rest.HTTPHeaders.HTTPHeader; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class TestHTTPHeaders { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to add a test for duplicate behavior as well. |
||
|
||
final HTTPHeaders headers = | ||
private final HTTPHeaders headers = | ||
HTTPHeaders.of( | ||
HTTPHeader.of("header1", "value1a"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please also add a test where the key/value is null |
||
HTTPHeader.of("HEADER1", "value1b"), | ||
|
@@ -71,6 +74,7 @@ void entries() { | |
assertThat(headers.entries("HEADER2")).containsExactly(HTTPHeader.of("header2", "value2")); | ||
assertThat(headers.entries("header3")).isEmpty(); | ||
assertThat(headers.entries("HEADER3")).isEmpty(); | ||
assertThat(headers.entries(null)).isEmpty(); | ||
} | ||
|
||
@Test | ||
|
@@ -81,6 +85,7 @@ void contains() { | |
assertThat(headers.contains("HEADER2")).isTrue(); | ||
assertThat(headers.contains("header3")).isFalse(); | ||
assertThat(headers.contains("HEADER3")).isFalse(); | ||
assertThat(headers.contains(null)).isFalse(); | ||
} | ||
|
||
@Test | ||
|
@@ -95,6 +100,9 @@ void addIfAbsentHTTPHeader() { | |
"header1", List.of("value1a", "value1b"), | ||
"header2", List.of("value2"), | ||
"header3", List.of("value3"))); | ||
|
||
assertThatThrownBy(() -> headers.addIfAbsent((HTTPHeaders) null)) | ||
.isInstanceOf(NullPointerException.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checks like this should always have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The message is generated by Immutables and will be rather cryptic. But OK. |
||
} | ||
|
||
@Test | ||
|
@@ -117,6 +125,9 @@ void addIfAbsentHTTPHeaders() { | |
HTTPHeader.of("header2", "value2"), | ||
HTTPHeader.of("header3", "value3")) | ||
.build()); | ||
|
||
assertThatThrownBy(() -> headers.addIfAbsent((HTTPHeaders) null)) | ||
.isInstanceOf(NullPointerException.class); | ||
} | ||
|
||
@Test | ||
|
@@ -133,6 +144,29 @@ void fromMap() { | |
.addEntry(HTTPHeader.of("header1", "value1b")) | ||
.addEntry(HTTPHeader.of("header2", "value2")) | ||
.build()); | ||
|
||
// invalid input (null name or value) | ||
assertThatThrownBy( | ||
() -> { | ||
Map<String, List<String>> map = Maps.newHashMap(); | ||
map.put(null, Lists.newArrayList("value1")); | ||
HTTPHeaders.fromMap(map); | ||
}) | ||
.isInstanceOf(NullPointerException.class); | ||
assertThatThrownBy( | ||
() -> { | ||
Map<String, List<String>> map = Maps.newHashMap(); | ||
map.put("header", null); | ||
HTTPHeaders.fromMap(map); | ||
}) | ||
.isInstanceOf(NullPointerException.class); | ||
assertThatThrownBy( | ||
() -> HTTPHeaders.fromMap(Map.of("header1", Lists.newArrayList("value1", null)))) | ||
.isInstanceOf(NullPointerException.class); | ||
|
||
// invalid input (empty name) | ||
assertThatThrownBy(() -> HTTPHeaders.fromMap(Map.of("", List.of("value1")))) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
|
@@ -148,6 +182,26 @@ void fromSimpleMap() { | |
.addEntry(HTTPHeader.of("header1", "value1a")) | ||
.addEntry(HTTPHeader.of("header2", "value2")) | ||
.build()); | ||
|
||
// invalid input (null name or value) | ||
assertThatThrownBy( | ||
() -> { | ||
Map<String, String> map = Maps.newHashMap(); | ||
map.put(null, "value1"); | ||
HTTPHeaders.fromSimpleMap(map); | ||
}) | ||
.isInstanceOf(NullPointerException.class); | ||
assertThatThrownBy( | ||
() -> { | ||
Map<String, String> map = Maps.newHashMap(); | ||
map.put("header", null); | ||
HTTPHeaders.fromSimpleMap(map); | ||
}) | ||
.isInstanceOf(NullPointerException.class); | ||
|
||
// invalid input (empty name) | ||
assertThatThrownBy(() -> HTTPHeaders.fromSimpleMap(Map.of("", "value1"))) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
|
@@ -163,5 +217,22 @@ void fromMultiMap() { | |
.addEntry(HTTPHeader.of("header1", "value1b")) | ||
.addEntry(HTTPHeader.of("header2", "value2")) | ||
.build()); | ||
|
||
// invalid input (empty name) | ||
assertThatThrownBy(() -> HTTPHeaders.fromMultiMap(ImmutableListMultimap.of("", "value1"))) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
void invalidHeader() { | ||
// invalid input (null name or value) | ||
assertThatThrownBy(() -> HTTPHeader.of(null, "value1")) | ||
.isInstanceOf(NullPointerException.class); | ||
assertThatThrownBy(() -> HTTPHeader.of("header1", null)) | ||
.isInstanceOf(NullPointerException.class); | ||
|
||
// invalid input (empty name) | ||
assertThatThrownBy(() -> HTTPHeader.of("", "value1")) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that we redact all header values? Maybe I don't fully understand the Immutable behavior here, but that's a bit problematic because we probably only want to redact sensitive headers (like
AUTHORIZATION
).