Skip to content

Commit 3861a5d

Browse files
committed
* Set RabbitMQ logging to debug for OAuth2
* Use internal backend for HTTP API for OAuth2 tests * Remove debug logging
1 parent 8178886 commit 3861a5d

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

projects/RabbitMQ.Client.OAuth2/CredentialsRefresher.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ private async Task RefreshLoopAsync()
9494

9595
CredentialsRefresherEventSource.Log.RefreshedCredentials(_credentialsProvider.Name);
9696

97-
Console.WriteLine("{0} [DEBUG] calling _onRefreshed, ValidUntil: {1}", DateTime.Now, _credentials.ValidUntil);
9897
await _onRefreshed(_credentials, null, _linkedCts.Token)
9998
.ConfigureAwait(false);
10099
}
@@ -114,8 +113,6 @@ await _onRefreshed(null, ex, _linkedCts.Token)
114113
delaySpan = TimeSpan.FromMilliseconds(_credentials.ValidUntil.Value.TotalMilliseconds * (1.0 - (1 / 3.0)));
115114
}
116115

117-
Console.WriteLine("{0} [DEBUG] RefreshLoopAsync delaySpan : {1}",
118-
DateTime.Now, delaySpan);
119116
await Task.Delay(delaySpan, _linkedCts.Token)
120117
.ConfigureAwait(false);
121118
}

projects/Test/OAuth2/OAuth2Options.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public override string ClientId
9696
{
9797
return _mode switch
9898
{
99-
Mode.uaa => "mgt_api_client_2",
99+
Mode.uaa => "rabbit_client_code",
100100
Mode.keycloak => "mgt_api_client",
101101
_ => throw new InvalidOperationException(),
102102
};
@@ -109,7 +109,7 @@ public override string ClientSecret
109109
{
110110
return _mode switch
111111
{
112-
Mode.uaa => "mgt_api_client",
112+
Mode.uaa => "rabbit_client_code",
113113
Mode.keycloak => "LWOuYqJ8gjKg3D2U8CJZDuID3KiRZVDa",
114114
_ => throw new InvalidOperationException(),
115115
};

projects/Test/OAuth2/TestOAuth2.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public class TestOAuth2 : IAsyncLifetime
5151
private readonly IConnectionFactory _connectionFactory;
5252
private readonly int _tokenExpiresInSeconds;
5353
private readonly OAuth2ClientCredentialsProvider _producerCredentialsProvider;
54-
private readonly OAuth2ClientCredentialsProvider _httpApiCredentialsProvider;
54+
// TODO rabbitmq-dotnet-client-1639
55+
// private readonly OAuth2ClientCredentialsProvider _httpApiCredentialsProvider;
5556
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
5657

5758
private IConnection? _connection;
@@ -67,8 +68,9 @@ public TestOAuth2(ITestOutputHelper testOutputHelper)
6768
var producerOptions = new OAuth2ProducerOptions(mode);
6869
_producerCredentialsProvider = GetCredentialsProvider(producerOptions);
6970

70-
var httpApiOptions = new OAuth2HttpApiOptions(mode);
71-
_httpApiCredentialsProvider = GetCredentialsProvider(httpApiOptions);
71+
// TODO rabbitmq-dotnet-client-1639
72+
// var httpApiOptions = new OAuth2HttpApiOptions(mode);
73+
// _httpApiCredentialsProvider = GetCredentialsProvider(httpApiOptions);
7274

7375
_connectionFactory = new ConnectionFactory
7476
{
@@ -127,27 +129,24 @@ public async Task DisposeAsync()
127129
private Task OnCredentialsRefreshedAsync(Credentials? credentials, Exception? exception,
128130
CancellationToken cancellationToken = default)
129131
{
130-
Console.WriteLine("{0} [INFO] OnCredentialsRefreshedAsync start", DateTime.Now);
131-
132132
if (_connection is null)
133133
{
134+
_testOutputHelper.WriteLine("connection is unexpectedly null!");
134135
Assert.Fail("_connection is unexpectedly null!");
135136
}
136137

137138
if (exception != null)
138139
{
139-
Console.WriteLine("{0} [ERROR] OnCredentialsRefreshedAsync exception: {1}",
140-
DateTime.Now, exception);
140+
_testOutputHelper.WriteLine("exception is unexpectedly not-null: {0}", exception);
141141
Assert.Fail($"exception is unexpectedly not-null: {exception}");
142142
}
143143

144144
if (credentials is null)
145145
{
146+
_testOutputHelper.WriteLine("credentials arg is unexpectedly null!");
146147
Assert.Fail("credentials arg is unexpectedly null!");
147148
}
148149

149-
_testOutputHelper.WriteLine("{0} [INFO] calling UpdateSecretAsync", DateTime.Now);
150-
Console.WriteLine("{0} [INFO] calling UpdateSecretAsync", DateTime.Now);
151150
return _connection.UpdateSecretAsync(credentials.Password, "Token refresh", cancellationToken);
152151
}
153152

@@ -177,8 +176,10 @@ public async void IntegrationTest()
177176
async Task CloseConnection()
178177
{
179178
Assert.NotNull(_connection);
180-
Credentials httpApiCredentials = await _httpApiCredentialsProvider.GetCredentialsAsync();
181-
closeConnectionUtil = new Util("mgt_api_client", httpApiCredentials.Password);
179+
// TODO rabbitmq-dotnet-client-1639
180+
// Credentials httpApiCredentials = await _httpApiCredentialsProvider.GetCredentialsAsync();
181+
// closeConnectionUtil = new Util("mgt_api_client", httpApiCredentials.Password);
182+
closeConnectionUtil = new Util();
182183
await closeConnectionUtil.CloseConnectionAsync(_connection.ClientProvidedName);
183184
}
184185

projects/Test/OAuth2/keycloak/rabbitmq.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
auth_backends.1 = rabbit_auth_backend_oauth2
1+
log.console = true
2+
log.console.level = debug
3+
4+
auth_backends.1 = internal
5+
auth_backends.2 = oauth2
26

37
auth_oauth2.resource_server_id = rabbitmq
48
auth_oauth2.preferred_username_claims.1 = username

projects/Test/OAuth2/uaa/rabbitmq.conf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
auth_backends.1 = rabbit_auth_backend_oauth2
1+
log.console = true
2+
log.console.level = debug
3+
4+
auth_backends.1 = internal
5+
auth_backends.2 = oauth2
6+
27
management.oauth_enabled = true
38
management.oauth_client_id = rabbit_client_code
49
management.oauth_provider_url = http://localhost:8080/

0 commit comments

Comments
 (0)