Search in sources :

Example 1 with BasicAuthCredentialProvider

use of io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider in project flink by apache.

the class CachedSchemaCoderProviderTest method testThatBasicAuthIsInitializedForBasicAuthProperties.

@Test
public void testThatBasicAuthIsInitializedForBasicAuthProperties() {
    String userPassword = "user:pwd";
    Map<String, String> configs = new HashMap<>();
    configs.put("basic.auth.credentials.source", "USER_INFO");
    configs.put("basic.auth.user.info", userPassword);
    CachedSchemaCoderProvider provider = initCachedSchemaCoderProvider(configs);
    BasicAuthCredentialProvider basicAuthCredentialProvider = getBasicAuthFromProvider(provider);
    assertNotNull(basicAuthCredentialProvider);
    assertEquals(basicAuthCredentialProvider.getUserInfo(null), userPassword);
}
Also used : BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with BasicAuthCredentialProvider

use of io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider in project flink-mirror by flink-ci.

the class CachedSchemaCoderProviderTest method testThatBasicAuthIsInitializedForBasicAuthProperties.

@Test
public void testThatBasicAuthIsInitializedForBasicAuthProperties() {
    String userPassword = "user:pwd";
    Map<String, String> configs = new HashMap<>();
    configs.put("basic.auth.credentials.source", "USER_INFO");
    configs.put("basic.auth.user.info", userPassword);
    CachedSchemaCoderProvider provider = initCachedSchemaCoderProvider(configs);
    BasicAuthCredentialProvider basicAuthCredentialProvider = getBasicAuthFromProvider(provider);
    assertNotNull(basicAuthCredentialProvider);
    assertEquals(basicAuthCredentialProvider.getUserInfo(null), userPassword);
}
Also used : BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with BasicAuthCredentialProvider

use of io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider in project flink by splunk.

the class CachedSchemaCoderProviderTest method testThatBasicAuthIsInitializedForBasicAuthProperties.

@Test
public void testThatBasicAuthIsInitializedForBasicAuthProperties() {
    String userPassword = "user:pwd";
    Map<String, String> configs = new HashMap<>();
    configs.put("basic.auth.credentials.source", "USER_INFO");
    configs.put("basic.auth.user.info", userPassword);
    CachedSchemaCoderProvider provider = initCachedSchemaCoderProvider(configs);
    BasicAuthCredentialProvider basicAuthCredentialProvider = getBasicAuthFromProvider(provider);
    assertNotNull(basicAuthCredentialProvider);
    assertEquals(basicAuthCredentialProvider.getUserInfo(null), userPassword);
}
Also used : BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with BasicAuthCredentialProvider

use of io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider in project flink by splunk.

the class CachedSchemaCoderProviderTest method testThatBasicAuthIsNotInitializedForNoBasicAuthProperties.

@Test
public void testThatBasicAuthIsNotInitializedForNoBasicAuthProperties() {
    CachedSchemaCoderProvider provider = initCachedSchemaCoderProvider(new HashMap<>());
    BasicAuthCredentialProvider basicAuthCredentialProvider = getBasicAuthFromProvider(provider);
    assertNull(basicAuthCredentialProvider);
}
Also used : BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) Test(org.junit.Test)

Example 5 with BasicAuthCredentialProvider

use of io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider in project schema-registry by confluentinc.

the class RestServiceTest method testSetBasicAuthRequestHeader.

/*
   * Test setBasicAuthRequestHeader (private method) indirectly through getAllSubjects.
   */
@Test
public void testSetBasicAuthRequestHeader() throws Exception {
    RestService restService = new RestService("http://localhost:8081");
    BasicAuthCredentialProvider basicAuthCredentialProvider = createMock(BasicAuthCredentialProvider.class);
    restService.setBasicAuthCredentialProvider(basicAuthCredentialProvider);
    HttpURLConnection httpURLConnection = createNiceMock(HttpURLConnection.class);
    InputStream inputStream = createNiceMock(InputStream.class);
    expectNew(URL.class, anyString()).andReturn(url);
    expect(url.openConnection()).andReturn(httpURLConnection);
    expect(httpURLConnection.getURL()).andReturn(url);
    expect(basicAuthCredentialProvider.getUserInfo(anyObject(URL.class))).andReturn("user:password");
    expect(httpURLConnection.getResponseCode()).andReturn(HttpURLConnection.HTTP_OK);
    // Make sure that the Authorization header is set with the correct value for "user:password"
    httpURLConnection.setRequestProperty("Authorization", "Basic dXNlcjpwYXNzd29yZA==");
    expectLastCall().once();
    expect(httpURLConnection.getInputStream()).andReturn(inputStream);
    expect(inputStream.read(anyObject(), anyInt(), anyInt())).andDelegateTo(createInputStream("[\"abc\"]")).anyTimes();
    replay(URL.class, url);
    replay(HttpURLConnection.class, httpURLConnection);
    replay(basicAuthCredentialProvider);
    replay(InputStream.class, inputStream);
    restService.getAllSubjects();
    verify(httpURLConnection);
}
Also used : BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

BasicAuthCredentialProvider (io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider)11 Test (org.junit.Test)8 HashMap (java.util.HashMap)3 RestService (io.confluent.kafka.schemaregistry.client.rest.RestService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)1 AvroSchemaProvider (io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)1 CachedSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 SchemaString (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)1 SslFactory (io.confluent.kafka.schemaregistry.client.security.SslFactory)1 BasicAuthCredentialProviderFactory (io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProviderFactory)1 UserInfoCredentialProvider (io.confluent.kafka.schemaregistry.client.security.basicauth.UserInfoCredentialProvider)1 BearerAuthCredentialProvider (io.confluent.kafka.schemaregistry.client.security.bearerauth.BearerAuthCredentialProvider)1 JsonSchemaProvider (io.confluent.kafka.schemaregistry.json.JsonSchemaProvider)1 ProtobufSchemaProvider (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider)1 Inject (jakarta.inject.Inject)1