Class SaslServerAuthenticatorTest
java.lang.Object
org.apache.kafka.common.security.authenticator.SaslServerAuthenticatorTest
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPrincipal builder that simulates a non-CRL mTLS failure by throwing a generic AuthenticationException.static classPrincipal builder that simulates a CRL check failure by throwing CertificateRevokedException.static classRecords the most-recently-pushedTenantConfigSourcefor the forwarding test below. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidtestFailedSaslAuthMTlsSslPeerVerified_BigRequestOverLimit(boolean mTlsEnabled) voidvoidtestInternalClientConnection(String mechanism, boolean isInternal, boolean hasPublicIpInLat, boolean ipFilteringConfig, boolean findInternalTrafficOrPrivateNetwork) voidvoidvoidVerify that maxNetInBufferSize returns the larger mTLS buffer size when CRL check fails, so that the client's full Kafka request can be read before the connection is closed.voidtestMTlsConfiguration(boolean globalConfig, String listenerName, boolean listenerSpecificConfig, boolean expectedMTlsEnabled) Comprehensive test for all mTLS configuration combinations.voidvoidtestNoSaslAuthInvalidRequest(boolean mTlsEnabled, boolean sendApiVersions) voidtestNoSaslAuthMTlsSslPeerAnonymous(boolean mTlsEnabled, boolean sendApiVersions) Ensure SASL authentication fails regardless of whether mTLS is enabled for unauthenticated clients send valid Kafka requests.voidvoidvoidtestRegisterClientIdDuringAuthentication(boolean sendApiVersions) voidvoidvoidvoidVerify that when mTLS principal building throws CertificateRevokedException (CRL check failure), the connection is closed (authentication fails) instead of falling back to SASL.voidVerify that when mTLS principal building throws a non-CRL AuthenticationException, the client falls back to SASL authentication (existing behavior preserved).voidVerify that a SASL_SSL client with a revoked certificate fails the first API_VERSIONS rquest.voidvoidvoidvoidvoidvoidtestSuccessfulSaslAuthMTlsSslPeerVerified(boolean mTlsEnabled, boolean sendApiVersions) Ensure SASL authentication is successful if mTLS is enabled and clients sending valid Kafka requests are authenticated by the transport layer (SSL).voidtestSuccessfulSaslAuthMTlsSslPeerVerified_BigRequestWithinLimit(boolean mTlsEnabled, boolean sendApiVersions) voidtestSuccessfulSaslAuthMTlsSslPeerVerified_multipleApiVersionsRequests(boolean mTlsEnabled, boolean sendApiVersions) Note that we don't include the scenario mtls_enabled=true.send_api_versions=false because that scenario isn't sending multiple API_VERSIONS requests.voidTest that two authentications do not share connection-specific configs.void
-
Constructor Details
-
SaslServerAuthenticatorTest
public SaslServerAuthenticatorTest()
-
-
Method Details
-
testOversizeRequest
- Throws:
IOException
-
testExternalApiVersionRequestContainsNoInternalApis
- Throws:
IOException
-
testUnexpectedRequestTypeWithValidRequestHeader
- Throws:
IOException
-
testInvalidRequestHeader
- Throws:
IOException
-
testS2SAuthZEnabledDefaultsFalse
- Throws:
IOException
-
testS2SAuthZEnabledReadsConfigTrue
- Throws:
IOException
-
testS2SAuthZEnabledReadsConfigFalse
- Throws:
IOException
-
testOldestApiVersionsRequest
- Throws:
IOException
-
testLatestApiVersionsRequest
- Throws:
IOException
-
testSessionExpiresAtTokenExpiryDespiteNoReauthIsSet
- Throws:
IOException
-
testSessionExpiresAtMaxReauthTime
- Throws:
IOException
-
testSessionExpiresAtTokenExpiry
- Throws:
IOException
-
testSessionWontExpireWithLargeExpirationTime
- Throws:
IOException
-
testInternalClientConnection
@ParameterizedTest @CsvSource({"PLAIN,true,false,true,true","PLAIN,false,false,true,true","OAUTHBEARER,true,true,true,true","OAUTHBEARER,true,false,true,true","OAUTHBEARER,false,true,true,true","OAUTHBEARER,false,false,true,true","PLAIN,true,false,false,true","PLAIN,false,false,false,true","OAUTHBEARER,true,true,false,true","OAUTHBEARER,true,false,false,true","OAUTHBEARER,false,true,false,true","OAUTHBEARER,false,false,false,true","PLAIN,true,false,true,false","PLAIN,false,false,true,false","OAUTHBEARER,true,true,true,false","OAUTHBEARER,true,false,true,false","OAUTHBEARER,false,true,true,false","OAUTHBEARER,false,false,true,false","PLAIN,true,false,false,false","PLAIN,false,false,false,false","OAUTHBEARER,true,true,false,false","OAUTHBEARER,true,false,false,false","OAUTHBEARER,false,true,false,false","OAUTHBEARER,false,false,false,false"}) public void testInternalClientConnection(String mechanism, boolean isInternal, boolean hasPublicIpInLat, boolean ipFilteringConfig, boolean findInternalTrafficOrPrivateNetwork) throws IOException - Throws:
IOException
-
testGetIpFromLat
- Throws:
IOException
-
testNoIpFromLat
- Throws:
IOException
-
testSuccessfulSaslAuthMTlsSslPeerVerified
@ParameterizedTest(name="{displayName}.mtls_enabled={0}.send_api_versions={1}") @CsvSource(value={"false:false","false:true","true:false","true:true"}, delimiter=':') public void testSuccessfulSaslAuthMTlsSslPeerVerified(boolean mTlsEnabled, boolean sendApiVersions) throws IOException Ensure SASL authentication is successful if mTLS is enabled and clients sending valid Kafka requests are authenticated by the transport layer (SSL). Clients may or may not send API_VERSIONS request.- Throws:
IOException
-
testSuccessfulSaslAuthMTlsSslPeerVerified_multipleApiVersionsRequests
@ParameterizedTest(name="{displayName}.mtls_enabled={0}.send_api_versions={1}") @CsvSource(value={"false:false","false:true","true:true"}, delimiter=':') public void testSuccessfulSaslAuthMTlsSslPeerVerified_multipleApiVersionsRequests(boolean mTlsEnabled, boolean sendApiVersions) throws IOException Note that we don't include the scenario mtls_enabled=true.send_api_versions=false because that scenario isn't sending multiple API_VERSIONS requests.- Throws:
IOException
-
testSuccessfulSaslAuthMTlsSslPeerVerified_BigRequestWithinLimit
@ParameterizedTest(name="{displayName}.mtls_enabled={0}.send_api_versions={1}") @CsvSource(value={"false:false","false:true","true:false","true:true"}, delimiter=':') public void testSuccessfulSaslAuthMTlsSslPeerVerified_BigRequestWithinLimit(boolean mTlsEnabled, boolean sendApiVersions) throws IOException - Throws:
IOException
-
testFailedSaslAuthMTlsSslPeerVerified_BigRequestOverLimit
@ParameterizedTest(name="{displayName}.mtls_enabled={0}") @ValueSource(booleans={false,true}) public void testFailedSaslAuthMTlsSslPeerVerified_BigRequestOverLimit(boolean mTlsEnabled) throws IOException - Throws:
IOException
-
testNoSaslAuthMTlsSslPeerAnonymous
@ParameterizedTest(name="{displayName}.mtls_enabled={0}.send_api_versions={1}") @CsvSource(value={"false:false","false:true","true:false","true:true"}, delimiter=':') public void testNoSaslAuthMTlsSslPeerAnonymous(boolean mTlsEnabled, boolean sendApiVersions) throws IOException Ensure SASL authentication fails regardless of whether mTLS is enabled for unauthenticated clients send valid Kafka requests. Clients may or may not send API_VERSIONS request.- Throws:
IOException
-
testNoSaslAuthInvalidRequest
@ParameterizedTest(name="{displayName}.mtls_enabled={0}.send_api_versions={1}") @CsvSource(value={"false:false","false:true","true:false","true:true"}, delimiter=':') public void testNoSaslAuthInvalidRequest(boolean mTlsEnabled, boolean sendApiVersions) throws IOException - Throws:
IOException
-
testMTlsConfiguration
@ParameterizedTest(name="[{index}] globalConfig={0}, listenerName={1}, listenerSpecificConfig={2} -> mTlsEnabled={3}") @MethodSource("mtlsConfigurationScenarios") public void testMTlsConfiguration(boolean globalConfig, String listenerName, boolean listenerSpecificConfig, boolean expectedMTlsEnabled) throws IOException Comprehensive test for all mTLS configuration combinations. Tests all 8 possible combinations of the 3 mTLS configs: - Global config (confluent.mtls.enable) - Listener name config (confluent.mtls.listener.name) - Listener-specific config (confluent.mtls.enabled.listener)Formula: mTlsEnabled = globalConfig invalid input: '&'invalid input: '&' (listenerNameMatches || listenerSpecificConfig)
When mTLS is enabled: authentication completes, saved request is available When mTLS is disabled: authentication throws IllegalSaslStateException
- Throws:
IOException
-
testRegisterClientIdDuringAuthentication
@ParameterizedTest(name="{displayName}.send_api_versions={0}") @ValueSource(booleans={false,true}) public void testRegisterClientIdDuringAuthentication(boolean sendApiVersions) throws IOException - Throws:
IOException
-
testSaslAuthFailsWhenMTlsCertificateRevoked
Verify that when mTLS principal building throws CertificateRevokedException (CRL check failure), the connection is closed (authentication fails) instead of falling back to SASL.- Throws:
IOException
-
testSaslSslClientWithRevokedCertCannotFallBackToSasl
Verify that a SASL_SSL client with a revoked certificate fails the first API_VERSIONS rquest. The CRL check should reject the connection.- Throws:
IOException
-
testSaslAuthFallsBackWhenMTlsNonCrlFailure
Verify that when mTLS principal building throws a non-CRL AuthenticationException, the client falls back to SASL authentication (existing behavior preserved).- Throws:
IOException
-
testMaxNetInBufferSizeReturnsLargerBufferOnCrlFailure
-
testSetTenantConfigSourceForwardsToTenantAwarePrincipalBuilder
@Test public void testSetTenantConfigSourceForwardsToTenantAwarePrincipalBuilder()
-