Skip to content

Commit

Permalink
Fixed Tests to accommodate new config
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLydonKing committed Oct 5, 2023
1 parent d927cdf commit 7c7a481
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions service/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)"))

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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("[email protected]") &&
usersConfig.knownUsers(1).displayname == Some("User Two") &&
usersConfig.knownUsers(1).email.contains("[email protected]") &&
usersConfig.knownUsers(1).displayname.contains("User Two") &&
usersConfig.knownUsers(1).password == "password2" &&
usersConfig.knownUsers(1).username == "user2")
}
Expand Down

0 comments on commit 7c7a481

Please sign in to comment.