edoardocomar commented on PR #24047: URL: https://github.com/apache/kafka/pull/24047#issuecomment-6920082913
Thanks for the PR @Vicky677 Coverage is high partly because several tests mock the code under test, so they run every line without verifying the behaviour. some suggestions... **Mocking hides the logic we most want to check** - `Mac` is static-mocked, so the HMAC returned by `getDelegationToken` is whatever the stub returns. In `testGetTokensWhenCacheNotEmpty` the expected token is built from the same bytes as the stub, so the assertion can't fail. Could we use a real key and assert the HMAC against an independently computed HmacSHA512 value? - `ScramFormatter` is construction-mocked and the tests only assert `tokenCache.token(id)`. It would be valuable to assert that the SCRAM credential is in the cache after `updateToken` (`delegationTokenCache.credential(mechanism, tokenId)`) and gone after `removeToken`. - I think `AbstractConfig` could be a real instance built from `DelegationTokenManagerConfigs.CONFIG_DEF` and a map, instead of a mock with `anyString()` stubs. **`filterToken` tests** - In `testFilterTokenWhenOwnerOrRenewer` both authorizers return `TRUE`, so the test would still pass if the owner/renewer branch were removed. Having them return `FALSE` would pin that branch. - The authorizer lambdas ignore their arguments. It would be nice to verify that `authorizeToken` receives the token id and `authorizeRequester` receives `token.owner()`. - These six tests share most of their setup; a single parameterized test might read more easily. **Tests that could probably be dropped or merged** - `testUpdateKeepsUserIndependent`, `testRemoveUserOnlyRemovesGivenUser`, `testUpdateTokenKeepsUserIndependent` and `testRemoveTokenKeepsUserIndependent` mostly check that two keys in a map don't interfere. - `testConstructorKeepsSameCache` checks a field assignment. - `testGetTokensFilterFalse` runs against an empty cache, so the predicate is never invoked; it would be more useful with a few tokens where some are filtered out. - `testTokenAuthEnabledSecretKeyLength0` mocks the config into a state the real `DelegationTokenManagerConfigs` can't produce (enabled with an empty key). - `testNullPointerWhenNotConfiguredMechanism` pins an NPE as expected behaviour. Since `removeCredentials` null-checks the cache, I wonder whether the NPE in `updateCredential` is intended. WDYT? **Minor** - The config/cache/manager setup is repeated in most tests and could move to `@BeforeEach` or a helper. - A few unused variables (`owners` in the `filterToken` tests, `principal`/`principals` in `testGetTokensCacheEmpty`). - `assertSame` / `assertEquals` arguments are in (actual, expected) order in several places. - `"Password".getBytes()` should specify a charset. - `MockitoAnnotations.openMocks(this)` returns an `AutoCloseable` that is never closed. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
