m1a2st commented on code in PR #16905: URL: https://github.com/apache/kafka/pull/16905#discussion_r1738862139
########## core/src/test/scala/integration/kafka/api/SaslSslAdminIntegrationTest.scala: ########## @@ -337,6 +338,53 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu assertFutureExceptionTypeEquals(results.values.get(emptyResourceNameAcl), classOf[InvalidRequestException]) } + @ParameterizedTest + @ValueSource(strings = Array("zk", "kraft")) + def testCreateDelegationTokenWithLargeTimeout(quorum: String): Unit = { + client = createAdminClient + val timeout = Long.MaxValue + + val options = new CreateDelegationTokenOptions().maxlifeTimeMs(timeout) + val token = client.createDelegationToken(options).delegationToken().get() + + assertEquals(DelegationTokenManagerConfigs.DELEGATION_TOKEN_MAX_LIFE_TIME_MS_DEFAULT, token.tokenInfo.maxTimestamp - token.tokenInfo.issueTimestamp) + assertTrue(token.tokenInfo.maxTimestamp >= token.tokenInfo.expiryTimestamp) + } + + @ParameterizedTest + @ValueSource(strings = Array("zk", "kraft")) + def testCreateDelegationTokenWithNegativeTimeout(quorum: String): Unit = { + client = createAdminClient + val timeout = -1 + + val options = new CreateDelegationTokenOptions().maxlifeTimeMs(timeout) + val token = client.createDelegationToken(options).delegationToken().get() + + assertEquals(DelegationTokenManagerConfigs.DELEGATION_TOKEN_MAX_LIFE_TIME_MS_DEFAULT, token.tokenInfo.maxTimestamp - token.tokenInfo.issueTimestamp) + assertTrue(token.tokenInfo.maxTimestamp >= token.tokenInfo.expiryTimestamp) + } + + @ParameterizedTest + @ValueSource(strings = Array("zk", "kraft")) + def testExpiredTimeStampLargerThanMaxLifeStamp(quorum: String): Unit = { + client = createAdminClient + val timeout = -1 + + val createOptions = new CreateDelegationTokenOptions().maxlifeTimeMs(timeout) + val token = client.createDelegationToken(createOptions).delegationToken().get() + + assertEquals(DelegationTokenManagerConfigs.DELEGATION_TOKEN_MAX_LIFE_TIME_MS_DEFAULT, token.tokenInfo.maxTimestamp - token.tokenInfo.issueTimestamp) + assertTrue(token.tokenInfo.maxTimestamp >= token.tokenInfo.expiryTimestamp) Review Comment: ditto ########## core/src/test/scala/integration/kafka/api/SaslSslAdminIntegrationTest.scala: ########## @@ -337,6 +338,53 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu assertFutureExceptionTypeEquals(results.values.get(emptyResourceNameAcl), classOf[InvalidRequestException]) } + @ParameterizedTest + @ValueSource(strings = Array("zk", "kraft")) + def testCreateDelegationTokenWithLargeTimeout(quorum: String): Unit = { + client = createAdminClient + val timeout = Long.MaxValue + + val options = new CreateDelegationTokenOptions().maxlifeTimeMs(timeout) + val token = client.createDelegationToken(options).delegationToken().get() + + assertEquals(DelegationTokenManagerConfigs.DELEGATION_TOKEN_MAX_LIFE_TIME_MS_DEFAULT, token.tokenInfo.maxTimestamp - token.tokenInfo.issueTimestamp) + assertTrue(token.tokenInfo.maxTimestamp >= token.tokenInfo.expiryTimestamp) + } + + @ParameterizedTest + @ValueSource(strings = Array("zk", "kraft")) + def testCreateDelegationTokenWithNegativeTimeout(quorum: String): Unit = { + client = createAdminClient + val timeout = -1 + + val options = new CreateDelegationTokenOptions().maxlifeTimeMs(timeout) + val token = client.createDelegationToken(options).delegationToken().get() + + assertEquals(DelegationTokenManagerConfigs.DELEGATION_TOKEN_MAX_LIFE_TIME_MS_DEFAULT, token.tokenInfo.maxTimestamp - token.tokenInfo.issueTimestamp) + assertTrue(token.tokenInfo.maxTimestamp >= token.tokenInfo.expiryTimestamp) Review Comment: ditto ########## core/src/test/scala/integration/kafka/api/SaslSslAdminIntegrationTest.scala: ########## @@ -337,6 +338,53 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu assertFutureExceptionTypeEquals(results.values.get(emptyResourceNameAcl), classOf[InvalidRequestException]) } + @ParameterizedTest + @ValueSource(strings = Array("zk", "kraft")) + def testCreateDelegationTokenWithLargeTimeout(quorum: String): Unit = { + client = createAdminClient + val timeout = Long.MaxValue + + val options = new CreateDelegationTokenOptions().maxlifeTimeMs(timeout) + val token = client.createDelegationToken(options).delegationToken().get() + + assertEquals(DelegationTokenManagerConfigs.DELEGATION_TOKEN_MAX_LIFE_TIME_MS_DEFAULT, token.tokenInfo.maxTimestamp - token.tokenInfo.issueTimestamp) + assertTrue(token.tokenInfo.maxTimestamp >= token.tokenInfo.expiryTimestamp) Review Comment: nit: the `token.tokenInfo` have been used four times, I consider make it a variable is more better, WDTY ``` val tokenInfo = client.createDelegationToken(options).delegationToken().get().tokenInfo ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org