From ae0d496e99d0b67425c3b48ec55c6e8417df9850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20M=C3=A9lois?= Date: Tue, 19 Mar 2024 11:52:09 +0100 Subject: [PATCH] Trim profiles before saving them in a map --- CHANGELOG.md | 1 + .../src/smithy4s/aws/AwsCredentialsFile.scala | 6 +++--- .../smithy4s/aws/AwsCredentialsFileTest.scala | 20 ++++++++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82a164fb4..dcd853aff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 0.18.15 * Add support for injecting endpoint-specific middlewares in AWS clients +* Fixes a bug in the parsing of AWS credentials files # 0.18.14 diff --git a/modules/aws-http4s/src/smithy4s/aws/AwsCredentialsFile.scala b/modules/aws-http4s/src/smithy4s/aws/AwsCredentialsFile.scala index dc2382c73..92db8b3c8 100644 --- a/modules/aws-http4s/src/smithy4s/aws/AwsCredentialsFile.scala +++ b/modules/aws-http4s/src/smithy4s/aws/AwsCredentialsFile.scala @@ -168,7 +168,7 @@ object AwsCredentialsFile { } private object Profile { - private val profileMatch = "([\\w_-]*)" + private val profileMatch = "(.*)" object Default { def unapply(s: String): Option[String] = if (s == "[default]") Some("default") else None @@ -177,7 +177,7 @@ private object Profile { object Prefixed { private val reg = s"^\\[profile $profileMatch\\]$$".r def unapply(s: String): Option[String] = s match { - case reg(first) => Some(first) + case reg(first) => Some(first.trim()) case _ => None } } @@ -185,7 +185,7 @@ private object Profile { object NonPrefixed { private val reg = s"^\\[$profileMatch\\]$$".r def unapply(s: String): Option[String] = s match { - case reg(first) => Some(first) + case reg(first) => Some(first.trim()) case _ => None } } diff --git a/modules/aws-http4s/test/src/smithy4s/aws/AwsCredentialsFileTest.scala b/modules/aws-http4s/test/src/smithy4s/aws/AwsCredentialsFileTest.scala index b985fd86d..7c62b690f 100644 --- a/modules/aws-http4s/test/src/smithy4s/aws/AwsCredentialsFileTest.scala +++ b/modules/aws-http4s/test/src/smithy4s/aws/AwsCredentialsFileTest.scala @@ -26,7 +26,10 @@ object AwsCredentialsFileTest extends FunSuite { e: Either[Throwable, A] )(f: A => Expectations): Expectations = e.fold( - err => failure(s"Got Left but expected a Right. ${err.getMessage}"), + err => { + err.printStackTrace() + failure(s"Got Left but expected a Right. ${err.getMessage}") + }, f ) @@ -144,5 +147,20 @@ object AwsCredentialsFileTest extends FunSuite { } } + test("profiles can have special characters in them") { + expectRight( + AwsCredentialsFile.processFileLines( + asLines( + """|[Namespace/User@USER_ID] + |aws_access_key_id = key + |aws_secret_access_key = sec + |aws_session_token = token""".stripMargin + ) + ) + ) { res => + expect.same(creds, res.profiles("Namespace/User@USER_ID")) + } + } + private def asLines(s: String) = s.split("\\n").toList }