Class AssertionSupplierFactoryTest

java.lang.Object
org.apache.kafka.common.security.oauthbearer.internals.secured.OAuthBearerTest
org.apache.kafka.common.security.oauthbearer.internals.secured.assertion.AssertionSupplierFactoryTest

public class AssertionSupplierFactoryTest extends OAuthBearerTest
  • Constructor Details

    • AssertionSupplierFactoryTest

      public AssertionSupplierFactoryTest()
  • Method Details

    • testCreateWithAssertionFile

      @Test public void testCreateWithAssertionFile() throws Exception
      When SASL_OAUTHBEARER_ASSERTION_FILE is configured, the factory should use file-based assertion creation and return the JWT from the file.
      Throws:
      Exception
    • testCreateWithPrivateKeyFile

      @Test public void testCreateWithPrivateKeyFile() throws Exception
      When no assertion file is configured, the factory should fall back to locally-generated assertions using the private key and signing algorithm.
      Throws:
      Exception
    • testCreateWithPrivateKeyFileAndStaticClaims

      @Test public void testCreateWithPrivateKeyFileAndStaticClaims() throws Exception
      When static claims (aud, iss, sub) are configured alongside the private key, they should be included in the generated JWT assertion.
      Throws:
      Exception
    • testCreateWithPassphraseReadsPasswordConfig

      @Test public void testCreateWithPassphraseReadsPasswordConfig() throws Exception
      When a passphrase is configured, the factory should read it via validatePassword and pass it to the DefaultAssertionCreator. Providing a passphrase for an unencrypted key is an invalid combination and should result in a JwtRetrieverException because the raw key bytes cannot be parsed as an EncryptedPrivateKeyInfo structure.
      Throws:
      Exception
    • testCreateWithoutPassphraseDoesNotReadPasswordConfig

      @Test public void testCreateWithoutPassphraseDoesNotReadPasswordConfig() throws Exception
      When the passphrase config key is absent, the factory should not attempt to read a password and should produce a working supplier with the unencrypted private key.
      Throws:
      Exception
    • testFileBasedSupplierReturnsSameValueOnMultipleCalls

      @Test public void testFileBasedSupplierReturnsSameValueOnMultipleCalls() throws Exception
      The file-based supplier should return the same value on consecutive calls since the file contents haven't changed.
      Throws:
      Exception
    • testLocallyGeneratedSupplierProducesConsistentAssertions

      @Test public void testLocallyGeneratedSupplierProducesConsistentAssertions() throws Exception
      The locally-generated supplier should produce valid assertions on consecutive calls. With MockTime, timestamps are deterministic so both assertions will be identical, confirming that no randomness (e.g. JTI) causes unexpected variation.
      Throws:
      Exception
    • testSupplierGetWrapsExceptionInJwtRetrieverException

      @Test public void testSupplierGetWrapsExceptionInJwtRetrieverException() throws Exception
      When the underlying file is deleted after factory creation, calling get() should throw a JwtRetrieverException since the assertion creator cannot read the file.
      Throws:
      Exception
    • testSupplierCloseDoesNotThrow

      @Test public void testSupplierCloseDoesNotThrow() throws Exception
      Closing the supplier should not throw any exceptions.
      Throws:
      Exception
    • testSupplierCanBeClosedMultipleTimes

      @Test public void testSupplierCanBeClosedMultipleTimes() throws Exception
      After closing the supplier, the underlying resources should be released. Verify that the supplier can be closed multiple times without error.
      Throws:
      Exception
    • testCreateWithPrivateKeyFileEs256

      @Test public void testCreateWithPrivateKeyFileEs256() throws Exception
      When ES256 algorithm is configured, the factory should produce valid assertions signed with the EC private key.
      Throws:
      Exception