Skip to content

Commit

Permalink
Allow passing null auth tokens to DDI-Client
Browse files Browse the repository at this point in the history
Signed-off-by: Saeed Rezaee <[email protected]>
  • Loading branch information
SaeedRe committed Feb 23, 2024
1 parent 1960edc commit 87bac69
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data class HaraClientData constructor(
notEmpty(controllerId, "controllerId")
notEmpty(serverUrl, "serverUrl")
validUrl(serverUrl, "serverUrl")
check(!(gatewayToken.isNullOrBlank() && targetToken.isNullOrBlank())) {
check(!(gatewayToken?.isEmpty() == true && targetToken?.isEmpty() == true)) {
"gatewayToken and targetToken cannot both be empty" }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,27 @@ class DdiClientHttpRequestsTest : AbstractHaraMessageTest() {
}
}

@Test(enabled = true, timeOut = 60_000, priority = 2)
@Test(enabled = true, priority = 2)
fun useNullTokensForAnonymousAuthorizationTest() {
runBlocking {
client = createClient(targetToken = null, gatewayToken = null)
enableTargetTokenInServer(false)
enableGatewayTokenInServer(false)

expectPollingOnlyMessage()
expectedServerResponses.apply {
OkHttpMessage(
HttpURLConnection.HTTP_UNAUTHORIZED, null
).also {
add(it)
}
}

startSubTestTest(true)
}
}

@Test(enabled = true, timeOut = 60_000, priority = 3)
fun useOnlyGatewayTokenTest() {
runBlocking {
client = createClient(targetToken = "")
Expand Down Expand Up @@ -153,7 +173,7 @@ class DdiClientHttpRequestsTest : AbstractHaraMessageTest() {
startSubTestTest(true)
}

@Test(enabled = true, timeOut = 60_000, priority = 3)
@Test(enabled = true, timeOut = 60_000, priority = 4)
fun useOnlyTargetTokenTest() {
runBlocking {
client = createClient(gatewayToken = "")
Expand Down Expand Up @@ -199,7 +219,7 @@ class DdiClientHttpRequestsTest : AbstractHaraMessageTest() {
}


@Test(enabled = true, timeOut = 60_000, priority = 4)
@Test(enabled = true, timeOut = 60_000, priority = 5)
fun usingEmptyTargetTokenRequestShouldOnlyUseGatewayTokenTest() {
runBlocking {
client = createClient(targetToken = "")
Expand All @@ -220,7 +240,7 @@ class DdiClientHttpRequestsTest : AbstractHaraMessageTest() {
}


@Test(enabled = true, timeOut = 60_000, priority = 5)
@Test(enabled = true, timeOut = 60_000, priority = 6)
fun usingEmptyGatewayTokenRequestShouldOnlyUseTargetTokenTest() {
runBlocking {
enableTargetTokenInServer(true)
Expand All @@ -240,7 +260,7 @@ class DdiClientHttpRequestsTest : AbstractHaraMessageTest() {
startSubTestTest(true)
}

@Test(enabled = true, timeOut = 200_000, priority = 6)
@Test(enabled = true, timeOut = 200_000, priority = 7)
fun providingBothTokensTest() {
runBlocking {
client = createClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ForcePingTest : AbstractHaraMessageTest() {
}
}

@Test(enabled = true, priority = 7, timeOut = 10_000, invocationCount = 1)
@Test(enabled = true, priority = 8, timeOut = 10_000, invocationCount = 1)
fun forcePingShouldPollFromServerImmediatelyTest() {
logCurrentFunctionName()
runBlocking {
Expand All @@ -76,7 +76,7 @@ class ForcePingTest : AbstractHaraMessageTest() {
}
}

@Test(enabled = true, priority = 8, timeOut = 60_000, invocationCount = 1)
@Test(enabled = true, priority = 9, timeOut = 60_000, invocationCount = 1)
fun timeIntervalBetweenEachForcePingCallShouldBe30SecondsTest() {
logCurrentFunctionName()
runBlocking {
Expand Down Expand Up @@ -109,7 +109,7 @@ class ForcePingTest : AbstractHaraMessageTest() {
}
}

@Test(enabled = true, priority = 9, timeOut = 10_000, invocationCount = 1)
@Test(enabled = true, priority = 10, timeOut = 10_000, invocationCount = 1)
fun forcePingShouldReturnNoNewStateWhenTargetStateOnServerIsNotChanged() {
logCurrentFunctionName()
runBlocking {
Expand All @@ -132,7 +132,7 @@ class ForcePingTest : AbstractHaraMessageTest() {
}
}

@Test(enabled = true, priority = 10, timeOut = 150_000, invocationCount = 1)
@Test(enabled = true, priority = 11, timeOut = 150_000, invocationCount = 1)
fun haraClientShouldReturnPollingStateAfterTheForcePingPollsUpdateFromServer() {
logCurrentFunctionName()
runBlocking {
Expand Down

0 comments on commit 87bac69

Please sign in to comment.