-
Notifications
You must be signed in to change notification settings - Fork 3k
Auth Manager API part 1: HTTPRequest, HTTPHeader #11769
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
Changes from 1 commit
7db53d8
e486e0d
0449744
d9a05fb
4c0e650
56ff7b2
ca6eb1e
2848e42
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 { | ||
danielcweeks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| final HTTPHeaders headers = | ||
| private final HTTPHeaders headers = | ||
| HTTPHeaders.of( | ||
| HTTPHeader.of("header1", "value1a"), | ||
danielcweeks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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); | ||
|
||
| } | ||
|
|
||
| @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); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.