-
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.
update url_parse based on package urlparse development (#874)
* allow parse to handle all edge cases identified in urlparse https://github.com/DyfanJones/urlparse/blob/main/tests/testthat/test-url_parse.R * simplify * set host to lower case before signing * revert * ensure path isn't empty * add base function bindings for mocking * test rds_build_auth_token_v2 new method
- Loading branch information
1 parent
50cd4f1
commit 858e5e2
Showing
7 changed files
with
209 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
################################################################ | ||
# Base function binding for mocking: | ||
# https://testthat.r-lib.org/reference/local_mocked_bindings.html#base-functions | ||
################################################################ | ||
|
||
Sys.time <- NULL |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,81 @@ | ||
test_that("rds_build_auth_token", { | ||
actual <- rds_build_auth_token( | ||
"prod-instance.us-east-1.rds.amazonaws.com:3306", | ||
"us-west-2", | ||
"mysqlUser", | ||
test_that("check rds_build_auth_token", { | ||
testthat::local_mocked_bindings( | ||
Sys.time = function() as.POSIXct("2025/01/01 00:00:01 UTC"), | ||
get_config = function() list(credentials = list(creds = list( | ||
access_key_id = "AKIA", | ||
secret_access_key = "SECRET", | ||
session_token = "SESSION" | ||
))), | ||
.package = "paws.common" | ||
) | ||
expected <- "prod-instance.us-east-1.rds.amazonaws.com:3306/?Action=connect&DBUser=mysqlUser&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA%2F20250101%2Fus-west-2%2Frds-db%2Faws4_request&X-Amz-Date=20250101T000001Z&X-Amz-Expires=900&X-Amz-Security-Token=SESSION&X-Amz-Signature=4e4ce10c7b3710decae757df60ba2519348dcb4db802f15646dce1bf5e17c3ed&X-Amz-SignedHeaders=host" | ||
expected_signature <- "X-Amz-Signature=4e4ce10c7b3710decae757df60ba2519348dcb4db802f15646dce1bf5e17c3ed" | ||
|
||
client <- list( | ||
build_auth_token = paws.common:::rds_build_auth_token, | ||
build_auth_token_v2 = paws.common:::rds_build_auth_token_v2 | ||
) | ||
actual_v1 <- client$build_auth_token( | ||
endpoint = "prod-instance.us-east-1.rds.amazonaws.com:3306", | ||
region = "us-west-2", | ||
user = "mysqlUser", | ||
creds = list( | ||
access_key_id = "AKIA", | ||
secret_access_key = "SECRET", | ||
session_token = "SESSION" | ||
) | ||
) | ||
expect_match(actual, "^prod-instance\\.us-east-1\\.rds\\.amazonaws\\.com:3306/\\?Action=connect.*?DBUser=mysqlUser.*") | ||
|
||
actual_v2 <- client$build_auth_token_v2( | ||
DBHostname = "prod-instance.us-east-1.rds.amazonaws.com", | ||
Port = 3306, | ||
DBUsername = "mysqlUser", | ||
Region = "us-west-2" | ||
) | ||
expect_equal(actual_v1, expected) | ||
expect_equal(actual_v2, expected) | ||
expect_match(actual_v1, expected_signature) | ||
expect_match(actual_v2, expected_signature) | ||
}) | ||
|
||
test_that("check rds_build_auth_token upper case host", { | ||
local_mocked_bindings( | ||
Sys.time = function() as.POSIXct("2025/01/01 00:00:01 UTC"), | ||
get_config = function() list(credentials = list(creds = list( | ||
access_key_id = "AKIA", | ||
secret_access_key = "SECRET", | ||
session_token = "SESSION" | ||
))), | ||
.package = "paws.common" | ||
) | ||
|
||
expected <- "XXXXX.US-EAST-2.RDS.AMAZONAWS.COM:3306/?Action=connect&DBUser=user1&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA%2F20250101%2Fus-east-2%2Frds-db%2Faws4_request&X-Amz-Date=20250101T000001Z&X-Amz-Expires=900&X-Amz-Security-Token=SESSION&X-Amz-Signature=c57093ec8c5c9a668ceab511fe2d72df1794936673fec2418744f71496eed913&X-Amz-SignedHeaders=host" | ||
expected_signature <- "X-Amz-Signature=c57093ec8c5c9a668ceab511fe2d72df1794936673fec2418744f71496eed913" | ||
|
||
client <- list( | ||
build_auth_token = paws.common:::rds_build_auth_token, | ||
build_auth_token_v2 = paws.common:::rds_build_auth_token_v2 | ||
) | ||
|
||
actual_v1 <- client$build_auth_token( | ||
endpoint = "XXXXX.US-EAST-2.RDS.AMAZONAWS.COM:3306", | ||
region = "us-east-2", | ||
user = "user1", | ||
creds = list( | ||
access_key_id = "AKIA", | ||
secret_access_key = "SECRET", | ||
session_token = "SESSION" | ||
) | ||
) | ||
|
||
actual_v2 <- client$build_auth_token_v2( | ||
DBHostname='XXXXX.US-EAST-2.RDS.AMAZONAWS.COM', | ||
Port = 3306, | ||
DBUsername="user1", | ||
Region="us-east-2" | ||
) | ||
expect_equal(actual_v1, expected) | ||
expect_equal(actual_v2, expected) | ||
expect_match(actual_v1, expected_signature) | ||
expect_match(actual_v2, expected_signature) | ||
}) |