-
Notifications
You must be signed in to change notification settings - Fork 875
/
Copy pathAdminClient_UserScram.cs
119 lines (110 loc) · 5.03 KB
/
AdminClient_UserScram.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2023 Confluent Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Refer to LICENSE for more information.
#pragma warning disable xUnit1026
using System;
using System.Text;
using System.Collections.Generic;
using Confluent.Kafka.Admin;
using Xunit;
namespace Confluent.Kafka.IntegrationTests
{
public partial class Tests
{
/// <summary>
/// Test functionality of AdminClient.DescribeUserScramCredentials and AdminClient.AlterUserScramCredentials.
/// </summary>
[Theory, MemberData(nameof(KafkaParameters))]
public async void AdminClient_UserScramCredentials(string bootstrapServers)
{
LogToFile("start AdminClient_UserScramCredentials");
var timeout = TimeSpan.FromSeconds(10);
using (var adminClient = new AdminClientBuilder(new AdminClientConfig { BootstrapServers = bootstrapServers }).Build())
{
var users = new List<string>
{
"non-existing-user"
};
var describeOptions =
new DescribeUserScramCredentialsOptions() { RequestTimeout = timeout };
var alterOptions =
new AlterUserScramCredentialsOptions() { RequestTimeout = timeout };
List<UserScramCredentialsDescription> descriptions;
try
{
await adminClient.DescribeUserScramCredentialsAsync(users, describeOptions);
Assert.True(false, "Describe request shouldn't succeed");
}
catch (DescribeUserScramCredentialsException e)
{
descriptions = e.Results.UserScramCredentialsDescriptions;
foreach (var description in descriptions)
{
Assert.Equal(users[0], description.User);
Assert.Equal(ErrorCode.ResourceNotFound,description.Error.Code);
}
}
var upsertions = new List<UserScramCredentialAlteration>();
var upsertion = new UserScramCredentialUpsertion()
{
User = users[0],
ScramCredentialInfo = new ScramCredentialInfo
{
Mechanism = ScramMechanism.ScramSha256,
Iterations = 15000,
},
Password = Encoding.UTF8.GetBytes("Password"),
Salt = Encoding.UTF8.GetBytes("Salt")
};
upsertions.Add(upsertion);
await adminClient.AlterUserScramCredentialsAsync(upsertions, alterOptions);
var descResult = await adminClient.DescribeUserScramCredentialsAsync(users, describeOptions);
foreach (var description in descResult.UserScramCredentialsDescriptions)
{
Assert.Equal(users[0], description.User);
Assert.Equal(ErrorCode.NoError, description.Error.Code);
foreach(var credentialinfo in description.ScramCredentialInfos){
Assert.Equal(15000,credentialinfo.Iterations);
Assert.Equal(ScramMechanism.ScramSha256, credentialinfo.Mechanism);
}
}
var deletions = new List<UserScramCredentialAlteration>();
var deletion = new UserScramCredentialDeletion()
{
User = "non-existing-user",
Mechanism = ScramMechanism.ScramSha256
};
deletions.Add(deletion);
await adminClient.AlterUserScramCredentialsAsync(deletions, alterOptions);
try
{
await adminClient.DescribeUserScramCredentialsAsync(users, describeOptions);
Assert.True(false, "Describe request shouldn't succeed");
}
catch (DescribeUserScramCredentialsException e)
{
descriptions = e.Results.UserScramCredentialsDescriptions;
foreach (var description in descriptions)
{
Assert.Equal(users[0], description.User);
Assert.Equal(ErrorCode.ResourceNotFound,description.Error.Code);
}
}
}
Assert.Equal(0, Library.HandleCount);
LogToFile("end AdminClient_UserScramCredentials");
}
}
}