danielcweeks commented on code in PR #6951:
URL: https://github.com/apache/iceberg/pull/6951#discussion_r1125333065


##########
aws/src/test/java/org/apache/iceberg/aws/TestRESTSigV4Signer.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.aws;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockserver.model.Header.header;
+import static org.mockserver.model.HttpRequest.request;
+
+import java.io.IOException;
+import java.util.Map;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.iceberg.CatalogProperties;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.rest.HTTPClient;
+import org.apache.iceberg.rest.auth.OAuth2Util;
+import org.apache.iceberg.rest.responses.ConfigResponse;
+import org.apache.iceberg.rest.responses.OAuthTokenResponse;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockserver.integration.ClientAndServer;
+import org.mockserver.model.HttpRequest;
+import org.mockserver.model.HttpResponse;
+import org.mockserver.verify.VerificationTimes;
+import software.amazon.awssdk.auth.signer.internal.SignerConstant;
+
+public class TestRESTSigV4Signer {
+  private static ClientAndServer mockServer;
+  private static HTTPClient client;
+
+  @BeforeClass
+  public static void beforeClass() {
+    mockServer = ClientAndServer.startClientAndServer();
+
+    System.setProperty("aws.region", "us-west-2");
+    System.setProperty("aws.accessKeyId", "fake_id");
+    System.setProperty("aws.secretAccessKey", "fake_secret");
+
+    Map<String, String> properties =
+        ImmutableMap.of(
+            CatalogProperties.URI,
+            "http://localhost:"; + mockServer.getLocalPort(),
+            "http.request.interceptor-impl",
+            RESTSigV4Signer.class.getName());
+    client = HTTPClient.buildFrom(properties);
+  }
+
+  @AfterClass
+  public static void afterClass() throws IOException {
+    System.getProperties().remove("aws.region");
+    System.getProperties().remove("aws.accessKeyId");
+    System.getProperties().remove("aws.secretAccessKey");
+
+    mockServer.stop();
+    client.close();
+  }
+
+  @Before
+  public void before() {
+    mockServer.reset();
+  }
+
+  @Test
+  public void signRequestWithoutBody() {

Review Comment:
   We're not actually testing the signature itself, but rather that the 
interceptor calculated a signature and added the appropriate header, which is 
determined by the match header:
   ```
   .withHeader(Header.header(HttpHeaders.AUTHORIZATION, "AWS4-HMAC-SHA256.*"));
   ```
   
   Based on what I've seen in example requests, the spec says that the checksum 
is required with the described value, for empty bodies, but that appears not to 
be a requirement as omitting the value is allowed.  The only requirement is 
that the `Authorization` header matches per the above.
   
   We're also not trying to validate the content of the signature because that 
would just be using the SDK for both the expected and actual value, which is 
already covered in the SDK tests and wouldn't add value here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to