diff --git a/service/src/test/resources/application.yaml b/service/src/test/resources/application.yaml index f38a574..492ded1 100644 --- a/service/src/test/resources/application.yaml +++ b/service/src/test/resources/application.yaml @@ -2,8 +2,9 @@ loginsvc: rest: # Rest General Config jwt: - exp-time: 4 - alg-name: "RS256" + generate-in-memory: + exp-time: 4 + alg-name: "RS256" config: some-key: "BETA" diff --git a/service/src/test/scala/za/co/absa/loginsvc/rest/config/JwtConfigTest.scala b/service/src/test/scala/za/co/absa/loginsvc/rest/config/JwtConfigTest.scala index 2654bde..6c69036 100644 --- a/service/src/test/scala/za/co/absa/loginsvc/rest/config/JwtConfigTest.scala +++ b/service/src/test/scala/za/co/absa/loginsvc/rest/config/JwtConfigTest.scala @@ -18,24 +18,30 @@ package za.co.absa.loginsvc.rest.config import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers +import za.co.absa.loginsvc.rest.config.provider.JwtConfigProvider import za.co.absa.loginsvc.rest.config.validation.ConfigValidationException import za.co.absa.loginsvc.rest.config.validation.ConfigValidationResult.{ConfigValidationError, ConfigValidationSuccess} class JwtConfigTest extends AnyFlatSpec with Matchers { - val jwtConfig = JwtConfig("RS256", 2) + val jwtConfig: JwtConfig = JwtConfig(Option(GenerateKeysConfig("RS256", 2)), None) + val inMemoryConfig: GenerateKeysConfig = jwtConfig.generateInMemory.get "JwtConfig" should "validate expected content" in { jwtConfig.validate() shouldBe ConfigValidationSuccess } + "inMemoryConfig" should "validate expected content" in { + inMemoryConfig.validate() shouldBe ConfigValidationSuccess + } + it should "fail on invalid algorithm" in { - jwtConfig.copy(algName = "ABC").validate() shouldBe + inMemoryConfig.copy(algName = "ABC").validate() shouldBe ConfigValidationError(ConfigValidationException("Invalid algName 'ABC' was given.")) } it should "fail on non-negative expTime" in { - jwtConfig.copy(expTime = -7).validate() shouldBe + inMemoryConfig.copy(expTime = -7).validate() shouldBe ConfigValidationError(ConfigValidationException("expTime must be positive (hours)")) } diff --git a/service/src/test/scala/za/co/absa/loginsvc/rest/config/provider/ConfigProviderTest.scala b/service/src/test/scala/za/co/absa/loginsvc/rest/config/provider/ConfigProviderTest.scala index 823cffa..eceb832 100644 --- a/service/src/test/scala/za/co/absa/loginsvc/rest/config/provider/ConfigProviderTest.scala +++ b/service/src/test/scala/za/co/absa/loginsvc/rest/config/provider/ConfigProviderTest.scala @@ -32,8 +32,9 @@ class ConfigProviderTest extends AnyFlatSpec with Matchers { "The jwtConfig properties" should "Match" in { val jwtConfig: JwtConfig = configProvider.getJWTConfig - assert(jwtConfig.algName == "RS256" && - jwtConfig.expTime == 4) + val inMemoryConfig = jwtConfig.generateInMemory.get + assert(inMemoryConfig.algName == "RS256" && + inMemoryConfig.expTime == 4) } "The ldapConfig properties" should "Match" in { @@ -55,8 +56,8 @@ class ConfigProviderTest extends AnyFlatSpec with Matchers { usersConfig.knownUsers(0).username == "user1") assert(usersConfig.knownUsers(1).groups(0) == "group2" && - usersConfig.knownUsers(1).email == Some("user@two.org") && - usersConfig.knownUsers(1).displayname == Some("User Two") && + usersConfig.knownUsers(1).email.contains("user@two.org") && + usersConfig.knownUsers(1).displayname.contains("User Two") && usersConfig.knownUsers(1).password == "password2" && usersConfig.knownUsers(1).username == "user2") }