Search in sources :

Example 1 with CredentialInfo

use of org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData.CredentialInfo in project kafka by apache.

the class KafkaAdminClientTest method testDescribeUserScramCredentials.

@Test
public void testDescribeUserScramCredentials() throws Exception {
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        final String user0Name = "user0";
        final ScramMechanism user0ScramMechanism0 = ScramMechanism.SCRAM_SHA_256;
        final int user0Iterations0 = 4096;
        final ScramMechanism user0ScramMechanism1 = ScramMechanism.SCRAM_SHA_512;
        final int user0Iterations1 = 8192;
        final CredentialInfo user0CredentialInfo0 = new CredentialInfo();
        user0CredentialInfo0.setMechanism(user0ScramMechanism0.type());
        user0CredentialInfo0.setIterations(user0Iterations0);
        final CredentialInfo user0CredentialInfo1 = new CredentialInfo();
        user0CredentialInfo1.setMechanism(user0ScramMechanism1.type());
        user0CredentialInfo1.setIterations(user0Iterations1);
        final String user1Name = "user1";
        final ScramMechanism user1ScramMechanism = ScramMechanism.SCRAM_SHA_256;
        final int user1Iterations = 4096;
        final CredentialInfo user1CredentialInfo = new CredentialInfo();
        user1CredentialInfo.setMechanism(user1ScramMechanism.type());
        user1CredentialInfo.setIterations(user1Iterations);
        final DescribeUserScramCredentialsResponseData responseData = new DescribeUserScramCredentialsResponseData();
        responseData.setResults(Arrays.asList(new DescribeUserScramCredentialsResponseData.DescribeUserScramCredentialsResult().setUser(user0Name).setCredentialInfos(Arrays.asList(user0CredentialInfo0, user0CredentialInfo1)), new DescribeUserScramCredentialsResponseData.DescribeUserScramCredentialsResult().setUser(user1Name).setCredentialInfos(singletonList(user1CredentialInfo))));
        final DescribeUserScramCredentialsResponse response = new DescribeUserScramCredentialsResponse(responseData);
        final Set<String> usersRequestedSet = new HashSet<>();
        usersRequestedSet.add(user0Name);
        usersRequestedSet.add(user1Name);
        for (final List<String> users : asList(null, new ArrayList<String>(), asList(user0Name, null, user1Name))) {
            env.kafkaClient().prepareResponse(response);
            final DescribeUserScramCredentialsResult result = env.adminClient().describeUserScramCredentials(users);
            final Map<String, UserScramCredentialsDescription> descriptionResults = result.all().get();
            final KafkaFuture<UserScramCredentialsDescription> user0DescriptionFuture = result.description(user0Name);
            final KafkaFuture<UserScramCredentialsDescription> user1DescriptionFuture = result.description(user1Name);
            final Set<String> usersDescribedFromUsersSet = new HashSet<>(result.users().get());
            assertEquals(usersRequestedSet, usersDescribedFromUsersSet);
            final Set<String> usersDescribedFromMapKeySet = descriptionResults.keySet();
            assertEquals(usersRequestedSet, usersDescribedFromMapKeySet);
            final UserScramCredentialsDescription userScramCredentialsDescription0 = descriptionResults.get(user0Name);
            assertEquals(user0Name, userScramCredentialsDescription0.name());
            assertEquals(2, userScramCredentialsDescription0.credentialInfos().size());
            assertEquals(user0ScramMechanism0, userScramCredentialsDescription0.credentialInfos().get(0).mechanism());
            assertEquals(user0Iterations0, userScramCredentialsDescription0.credentialInfos().get(0).iterations());
            assertEquals(user0ScramMechanism1, userScramCredentialsDescription0.credentialInfos().get(1).mechanism());
            assertEquals(user0Iterations1, userScramCredentialsDescription0.credentialInfos().get(1).iterations());
            assertEquals(userScramCredentialsDescription0, user0DescriptionFuture.get());
            final UserScramCredentialsDescription userScramCredentialsDescription1 = descriptionResults.get(user1Name);
            assertEquals(user1Name, userScramCredentialsDescription1.name());
            assertEquals(1, userScramCredentialsDescription1.credentialInfos().size());
            assertEquals(user1ScramMechanism, userScramCredentialsDescription1.credentialInfos().get(0).mechanism());
            assertEquals(user1Iterations, userScramCredentialsDescription1.credentialInfos().get(0).iterations());
            assertEquals(userScramCredentialsDescription1, user1DescriptionFuture.get());
        }
    }
}
Also used : CredentialInfo(org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData.CredentialInfo) DescribeUserScramCredentialsResponseData(org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData) DescribeUserScramCredentialsResponse(org.apache.kafka.common.requests.DescribeUserScramCredentialsResponse) HashSet(java.util.HashSet) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

HashSet (java.util.HashSet)1 DescribeUserScramCredentialsResponseData (org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData)1 CredentialInfo (org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData.CredentialInfo)1 DescribeUserScramCredentialsResponse (org.apache.kafka.common.requests.DescribeUserScramCredentialsResponse)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1