Skip to content

Commit 982a946

Browse files
committed
Added skip in HeaderTransformsHelper too , to be consistent
1 parent d5cb049 commit 982a946

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

core/auth/src/main/java/software/amazon/awssdk/auth/signer/internal/util/HeaderTransformsHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
public final class HeaderTransformsHelper {
3333

3434
private static final List<String> LIST_OF_HEADERS_TO_IGNORE_IN_LOWER_CASE =
35-
Arrays.asList("connection", "x-amzn-trace-id", "user-agent", "expect");
35+
Arrays.asList("connection", "x-amzn-trace-id", "user-agent", "expect", "transfer-encoding");
3636

3737
private HeaderTransformsHelper() {
3838
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
17+
package software.amazon.awssdk.auth.signer.internal.util;
18+
import java.util.Arrays;
19+
import java.util.Collections;
20+
import java.util.HashMap;
21+
import java.util.List;
22+
import java.util.Map;
23+
import java.util.TreeMap;
24+
import org.junit.jupiter.api.Test;
25+
26+
import static org.junit.jupiter.api.Assertions.*;
27+
28+
class HeaderTransformsHelperTest {
29+
30+
@Test
31+
void shouldExcludeIgnoredHeadersWhenCanonicalizing() {
32+
Map<String, List<String>> headers = new HashMap<>();
33+
34+
// Ignored headers that should be excluded from signing
35+
headers.put("connection", Collections.singletonList("keep-alive"));
36+
headers.put("x-amzn-trace-id", Collections.singletonList("Root=1-234567890"));
37+
headers.put("user-agent", Collections.singletonList("md/user"));
38+
headers.put("expect", Collections.singletonList("100-continue"));
39+
headers.put("transfer-encoding", Collections.singletonList("chunked"));
40+
41+
// Headers that should be included in signing
42+
headers.put("Content-Type", Collections.singletonList("application/json"));
43+
headers.put("Host", Collections.singletonList("example.com"));
44+
45+
Map<String, List<String>> canonicalizedHeaders = HeaderTransformsHelper.canonicalizeSigningHeaders(headers);
46+
47+
assertEquals(2, canonicalizedHeaders.size(), "Should only contain non-ignored headers");
48+
49+
// Verify included headers
50+
assertTrue(canonicalizedHeaders.containsKey("content-type"), "Should contain content-type header");
51+
assertTrue(canonicalizedHeaders.containsKey("host"), "Should contain host header");
52+
53+
// Verify excluded headers
54+
assertFalse(canonicalizedHeaders.containsKey("connection"), "Should not contain connection header");
55+
assertFalse(canonicalizedHeaders.containsKey("x-amzn-trace-id"), "Should not contain x-amzn-trace-id header");
56+
assertFalse(canonicalizedHeaders.containsKey("user-agent"), "Should not contain user-agent header");
57+
assertFalse(canonicalizedHeaders.containsKey("expect"), "Should not contain expect header");
58+
assertFalse(canonicalizedHeaders.containsKey("transfer-encoding"), "Should not contain transfer-encoding header");
59+
}
60+
61+
}

0 commit comments

Comments
 (0)