-
Notifications
You must be signed in to change notification settings - Fork 853
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c16ef04
commit 3124558
Showing
17 changed files
with
434 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...est/java/software/amazon/awssdk/http/auth/aws/internal/signer/DefaultChecksummerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.http.auth.aws.internal.signer; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.reactivex.Flowable; | ||
import java.io.ByteArrayInputStream; | ||
import java.net.URI; | ||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
import org.junit.jupiter.api.Test; | ||
import org.reactivestreams.Publisher; | ||
import software.amazon.awssdk.http.ContentStreamProvider; | ||
import software.amazon.awssdk.http.SdkHttpMethod; | ||
import software.amazon.awssdk.http.SdkHttpRequest; | ||
|
||
public class DefaultChecksummerTest { | ||
|
||
ContentStreamProvider payload = () -> new ByteArrayInputStream("foo".getBytes(StandardCharsets.UTF_8)); | ||
Publisher<ByteBuffer> payloadAsync = Flowable.just(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8))); | ||
|
||
|
||
SdkHttpRequest.Builder request = SdkHttpRequest.builder() | ||
.uri(URI.create("https://localhost")) | ||
.method(SdkHttpMethod.GET); | ||
|
||
@Test | ||
public void checksummer_shouldAddSha256ChecksumToAmzContentSha256Header() { | ||
DefaultChecksummer checksummer = new DefaultChecksummer(); | ||
SdkHttpRequest expectedRequest = request | ||
.putHeader("x-amz-content-sha256", "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae") | ||
.build(); | ||
|
||
checksummer.checksum(payload, request); | ||
|
||
assertEquals(expectedRequest.toString(), request.build().toString()); | ||
} | ||
|
||
@Test | ||
public void checksummerAsync_shouldAddSha256ChecksumToAmzContentSha256Header() { | ||
DefaultChecksummer checksummer = new DefaultChecksummer(); | ||
SdkHttpRequest expectedRequest = request | ||
.putHeader("x-amz-content-sha256", "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae") | ||
.build(); | ||
|
||
checksummer.checksum(payloadAsync, request); | ||
|
||
assertEquals(expectedRequest.toString(), request.build().toString()); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...t/java/software/amazon/awssdk/http/auth/aws/internal/signer/DefaultRequestSignerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.http.auth.aws.internal.signer; | ||
|
||
import static java.time.ZoneOffset.UTC; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static software.amazon.awssdk.utils.BinaryUtils.toHex; | ||
|
||
import java.net.URI; | ||
import java.time.Clock; | ||
import java.time.Instant; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.awssdk.http.SdkHttpMethod; | ||
import software.amazon.awssdk.http.SdkHttpRequest; | ||
import software.amazon.awssdk.http.auth.aws.signer.CredentialScope; | ||
import software.amazon.awssdk.http.auth.aws.signer.V4Context; | ||
import software.amazon.awssdk.http.auth.aws.signer.V4Properties; | ||
import software.amazon.awssdk.http.auth.aws.signer.V4RequestSigner; | ||
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity; | ||
|
||
public class DefaultRequestSignerTest { | ||
|
||
V4Properties v4Properties = V4Properties.builder() | ||
.credentials(AwsCredentialsIdentity.create("foo", "bar")) | ||
.credentialScope(new CredentialScope("baz", "qux", Instant.EPOCH)) | ||
.signingClock(Clock.fixed(Instant.EPOCH, UTC)) | ||
.doubleUrlEncode(true) | ||
.normalizePath(true) | ||
.build(); | ||
|
||
V4RequestSigner requestSigner = new DefaultV4RequestSigner(v4Properties); | ||
|
||
@Test | ||
public void requestSigner_sign_shouldReturnSignedContext_butNotAddAnyAuthInfoToRequest() { | ||
SdkHttpRequest.Builder request = SdkHttpRequest | ||
.builder() | ||
.uri(URI.create("https://localhost")) | ||
.method(SdkHttpMethod.GET) | ||
.putHeader("x-amz-content-sha256", "quux"); | ||
String expectedContentHash = "quux"; | ||
String expectedSigningKeyHex = "3d558b7a87b67996abc908071e0771a31b2a7977ab247144e60a6cba3356be1f"; | ||
String expectedSignature = "7557839280ea0ef5c4acc66e5670d0857ac4f491884b1b8031d4dea2fc33483c"; | ||
String expectedCanonicalRequestString = "GET\n/\n\n" | ||
+ "host:localhost\nx-amz-content-sha256:quux\n\n" | ||
+ "host;x-amz-content-sha256\nquux"; | ||
String expectedHost = "localhost"; | ||
|
||
V4Context v4Context = requestSigner.sign(request); | ||
|
||
assertEquals(expectedContentHash, v4Context.getContentHash()); | ||
assertEquals(expectedSigningKeyHex, toHex(v4Context.getSigningKey())); | ||
assertEquals(expectedSignature, v4Context.getSignature()); | ||
assertEquals(expectedCanonicalRequestString, v4Context.getCanonicalRequest().getCanonicalRequestString()); | ||
assertEquals(expectedHost, v4Context.getSignedRequest().firstMatchingHeader("Host").orElse("")); | ||
} | ||
} |
Oops, something went wrong.