-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Authorization header tests and fixing bug introduced in #40
- Loading branch information
1 parent
9e4d109
commit e3517a1
Showing
2 changed files
with
109 additions
and
1 deletion.
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
108 changes: 108 additions & 0 deletions
108
src/test/java/com/netspi/awssigner/signing/ParsedAuthHeaderTest.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,108 @@ | ||
package com.netspi.awssigner.signing; | ||
|
||
import java.util.Optional; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class ParsedAuthHeaderTest { | ||
|
||
@Test | ||
public void testTypical1CommaAnd1Space() { | ||
String testHeader = "Authorization: AWS4-HMAC-SHA256 Credential=ASIAXXXXXXXXXXXXXXXX/20230901/us-east-1/XXXX/aws4_request SignedHeaders=content-encoding;host;x-amz-date;x-amz-requestsupertrace;x-amz-target, Signature=64ed7bf1ee17050e2a38b4c878ca6471c341b78cdb428bcec52cc6b58f1a8464"; | ||
//Parse the header | ||
Optional<ParsedAuthHeader> result = ParsedAuthHeader.parseFromAuthorizationHeader(testHeader); | ||
//Ensure it parsed successfully. | ||
assertTrue(result.isPresent()); | ||
//Extract the result | ||
ParsedAuthHeader parsedHeader = result.get(); | ||
|
||
//Ensure all fields were extracted properly. | ||
assertEquals(SigningAlgorithm.SIGV4,parsedHeader.getAlgorithm()); | ||
assertEquals("ASIAXXXXXXXXXXXXXXXX",parsedHeader.getAccessKey()); | ||
assertEquals("20230901",parsedHeader.getDate()); | ||
assertEquals("us-east-1",parsedHeader.getRegion().get()); | ||
assertEquals("XXXX",parsedHeader.getService()); | ||
assertEquals("content-encoding;host;x-amz-date;x-amz-requestsupertrace;x-amz-target",parsedHeader.getSignedHeaders()); | ||
assertEquals("64ed7bf1ee17050e2a38b4c878ca6471c341b78cdb428bcec52cc6b58f1a8464",parsedHeader.getSignature()); | ||
} | ||
|
||
@Test | ||
public void testNoCommaAnd1Space() { | ||
String testHeader = "Authorization: AWS4-HMAC-SHA256 Credential=ASIAXXXXXXXXXXXXXXXX/20230901/us-east-1/XXXX/aws4_request SignedHeaders=content-encoding;host;x-amz-date;x-amz-requestsupertrace;x-amz-target Signature=64ed7bf1ee17050e2a38b4c878ca6471c341b78cdb428bcec52cc6b58f1a8464"; | ||
//Parse the header | ||
Optional<ParsedAuthHeader> result = ParsedAuthHeader.parseFromAuthorizationHeader(testHeader); | ||
//Ensure it parsed successfully. | ||
assertTrue(result.isPresent()); | ||
//Extract the result | ||
ParsedAuthHeader parsedHeader = result.get(); | ||
|
||
//Ensure all fields were extracted properly. | ||
assertEquals(SigningAlgorithm.SIGV4,parsedHeader.getAlgorithm()); | ||
assertEquals("ASIAXXXXXXXXXXXXXXXX",parsedHeader.getAccessKey()); | ||
assertEquals("20230901",parsedHeader.getDate()); | ||
assertEquals("us-east-1",parsedHeader.getRegion().get()); | ||
assertEquals("XXXX",parsedHeader.getService()); | ||
assertEquals("content-encoding;host;x-amz-date;x-amz-requestsupertrace;x-amz-target",parsedHeader.getSignedHeaders()); | ||
assertEquals("64ed7bf1ee17050e2a38b4c878ca6471c341b78cdb428bcec52cc6b58f1a8464",parsedHeader.getSignature()); | ||
} | ||
|
||
@Test | ||
public void test1CommaAndNoSpace() { | ||
String testHeader = "Authorization: AWS4-HMAC-SHA256 Credential=ASIAXXXXXXXXXXXXXXXX/20230901/us-east-1/XXXX/aws4_request SignedHeaders=content-encoding;host;x-amz-date;x-amz-requestsupertrace;x-amz-target,Signature=64ed7bf1ee17050e2a38b4c878ca6471c341b78cdb428bcec52cc6b58f1a8464"; | ||
//Parse the header | ||
Optional<ParsedAuthHeader> result = ParsedAuthHeader.parseFromAuthorizationHeader(testHeader); | ||
//Ensure it parsed successfully. | ||
assertTrue(result.isPresent()); | ||
//Extract the result | ||
ParsedAuthHeader parsedHeader = result.get(); | ||
|
||
//Ensure all fields were extracted properly. | ||
assertEquals(SigningAlgorithm.SIGV4,parsedHeader.getAlgorithm()); | ||
assertEquals("ASIAXXXXXXXXXXXXXXXX",parsedHeader.getAccessKey()); | ||
assertEquals("20230901",parsedHeader.getDate()); | ||
assertEquals("us-east-1",parsedHeader.getRegion().get()); | ||
assertEquals("XXXX",parsedHeader.getService()); | ||
assertEquals("content-encoding;host;x-amz-date;x-amz-requestsupertrace;x-amz-target",parsedHeader.getSignedHeaders()); | ||
assertEquals("64ed7bf1ee17050e2a38b4c878ca6471c341b78cdb428bcec52cc6b58f1a8464",parsedHeader.getSignature()); | ||
} | ||
@Test | ||
public void testManyCommasAnd1Space() { | ||
String testHeader = "Authorization: AWS4-HMAC-SHA256 Credential=ASIAXXXXXXXXXXXXXXXX/20230901/us-east-1/XXXX/aws4_request SignedHeaders=content-encoding;host;x-amz-date;x-amz-requestsupertrace;x-amz-target,,,,,,,,,,,,, Signature=64ed7bf1ee17050e2a38b4c878ca6471c341b78cdb428bcec52cc6b58f1a8464"; | ||
//Parse the header | ||
Optional<ParsedAuthHeader> result = ParsedAuthHeader.parseFromAuthorizationHeader(testHeader); | ||
//Ensure it parsed successfully. | ||
assertTrue(result.isPresent()); | ||
//Extract the result | ||
ParsedAuthHeader parsedHeader = result.get(); | ||
|
||
//Ensure all fields were extracted properly. | ||
assertEquals(SigningAlgorithm.SIGV4,parsedHeader.getAlgorithm()); | ||
assertEquals("ASIAXXXXXXXXXXXXXXXX",parsedHeader.getAccessKey()); | ||
assertEquals("20230901",parsedHeader.getDate()); | ||
assertEquals("us-east-1",parsedHeader.getRegion().get()); | ||
assertEquals("XXXX",parsedHeader.getService()); | ||
assertEquals("content-encoding;host;x-amz-date;x-amz-requestsupertrace;x-amz-target",parsedHeader.getSignedHeaders()); | ||
assertEquals("64ed7bf1ee17050e2a38b4c878ca6471c341b78cdb428bcec52cc6b58f1a8464",parsedHeader.getSignature()); | ||
} | ||
@Test | ||
public void testManyCommasAndNoSpace() { | ||
String testHeader = "Authorization: AWS4-HMAC-SHA256 Credential=ASIAXXXXXXXXXXXXXXXX/20230901/us-east-1/XXXX/aws4_request SignedHeaders=content-encoding;host;x-amz-date;x-amz-requestsupertrace;x-amz-target,,,,,,,,,,,,,Signature=64ed7bf1ee17050e2a38b4c878ca6471c341b78cdb428bcec52cc6b58f1a8464"; | ||
//Parse the header | ||
Optional<ParsedAuthHeader> result = ParsedAuthHeader.parseFromAuthorizationHeader(testHeader); | ||
//Ensure it parsed successfully. | ||
assertTrue(result.isPresent()); | ||
//Extract the result | ||
ParsedAuthHeader parsedHeader = result.get(); | ||
|
||
//Ensure all fields were extracted properly. | ||
assertEquals(SigningAlgorithm.SIGV4,parsedHeader.getAlgorithm()); | ||
assertEquals("ASIAXXXXXXXXXXXXXXXX",parsedHeader.getAccessKey()); | ||
assertEquals("20230901",parsedHeader.getDate()); | ||
assertEquals("us-east-1",parsedHeader.getRegion().get()); | ||
assertEquals("XXXX",parsedHeader.getService()); | ||
assertEquals("content-encoding;host;x-amz-date;x-amz-requestsupertrace;x-amz-target",parsedHeader.getSignedHeaders()); | ||
assertEquals("64ed7bf1ee17050e2a38b4c878ca6471c341b78cdb428bcec52cc6b58f1a8464",parsedHeader.getSignature()); | ||
} | ||
|
||
|
||
} |