Class SaslServerAuthenticatorTest

java.lang.Object
org.apache.kafka.common.security.authenticator.SaslServerAuthenticatorTest

@Tag("bazel:size:large") public class SaslServerAuthenticatorTest extends Object
  • Constructor Details

    • SaslServerAuthenticatorTest

      public SaslServerAuthenticatorTest()
  • Method Details

    • testOversizeRequest

      @Test public void testOversizeRequest() throws IOException
      Throws:
      IOException
    • testExternalApiVersionRequestContainsNoInternalApis

      @Test public void testExternalApiVersionRequestContainsNoInternalApis() throws IOException
      Throws:
      IOException
    • testUnexpectedRequestTypeWithValidRequestHeader

      @Test public void testUnexpectedRequestTypeWithValidRequestHeader() throws IOException
      Throws:
      IOException
    • testInvalidRequestHeader

      @Test public void testInvalidRequestHeader() throws IOException
      Throws:
      IOException
    • testS2SAuthZEnabledDefaultsFalse

      @Test public void testS2SAuthZEnabledDefaultsFalse() throws IOException
      Throws:
      IOException
    • testS2SAuthZEnabledReadsConfigTrue

      @Test public void testS2SAuthZEnabledReadsConfigTrue() throws IOException
      Throws:
      IOException
    • testS2SAuthZEnabledReadsConfigFalse

      @Test public void testS2SAuthZEnabledReadsConfigFalse() throws IOException
      Throws:
      IOException
    • testOldestApiVersionsRequest

      @Test public void testOldestApiVersionsRequest() throws IOException
      Throws:
      IOException
    • testLatestApiVersionsRequest

      @Test public void testLatestApiVersionsRequest() throws IOException
      Throws:
      IOException
    • testSessionExpiresAtTokenExpiryDespiteNoReauthIsSet

      @Test public void testSessionExpiresAtTokenExpiryDespiteNoReauthIsSet() throws IOException
      Throws:
      IOException
    • testSessionExpiresAtMaxReauthTime

      @Test public void testSessionExpiresAtMaxReauthTime() throws IOException
      Throws:
      IOException
    • testSessionExpiresAtTokenExpiry

      @Test public void testSessionExpiresAtTokenExpiry() throws IOException
      Throws:
      IOException
    • testSessionWontExpireWithLargeExpirationTime

      @Test public void testSessionWontExpireWithLargeExpirationTime() throws IOException
      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

      @Test public void testGetIpFromLat() throws IOException
      Throws:
      IOException
    • testNoIpFromLat

      @Test public void testNoIpFromLat() throws IOException
      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

      @Test public void testSaslAuthFailsWhenMTlsCertificateRevoked() throws IOException
      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

      @Test public void testSaslSslClientWithRevokedCertCannotFallBackToSasl() throws IOException
      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

      @Test public void testSaslAuthFallsBackWhenMTlsNonCrlFailure() throws IOException
      Verify that when mTLS principal building throws a non-CRL AuthenticationException, the client falls back to SASL authentication (existing behavior preserved).
      Throws:
      IOException
    • testMaxNetInBufferSizeReturnsLargerBufferOnCrlFailure

      @Test public void testMaxNetInBufferSizeReturnsLargerBufferOnCrlFailure() throws Exception
      Verify 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.
      Throws:
      Exception
    • testTwoAuthenticatorsDoNotShareConnectionSpecificConfigs

      @Test public void testTwoAuthenticatorsDoNotShareConnectionSpecificConfigs() throws IOException
      Test that two authentications do not share connection-specific configs. This is a regression test for a bug where the shared configs map was mutated directly instead of being copied, causing one authentication to overwrite another authentication's connection-specific values.

      Tests all 5 connection-specific properties at the time of writing the test: 1. SNI_BROKER_HOST_NAME_SASL_PROPERTY_KEY → sniHostName (set via setSniHostName) 2. TRAFFIC_NETWORK_ID_SASL_PROPERTY_KEY → networkId (from request) 3. ORGANIZATION_ID_SASL_PROPERTY_KEY → organizationId (from request) 4. TRAFFIC_NETWORK_TYPE_SASL_PROPERTY_KEY → networkType (from request) 5. CLIENT_LOGICAL_CLUSTER_ID_SASL_PROPERTY_KEY → logicalClusterId (from request)

      Throws:
      IOException
    • testSetTenantConfigSourceForwardsToTenantAwarePrincipalBuilder

      @Test public void testSetTenantConfigSourceForwardsToTenantAwarePrincipalBuilder()