Skip to content

Commit f6b2335

Browse files
committed
Fix issue with tests and Authorize attribute
1 parent 23fcfd0 commit f6b2335

4 files changed

Lines changed: 24 additions & 21 deletions

File tree

src/Services/Common/Infrastructure/EventBusRabbitMQ.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
1515
{
1616
public class EventBusRabbitMQ : IEventBus
1717
{
18-
private readonly string _brokerName = "event_bus";
18+
private readonly string _brokerName = "eshop_event_bus";
1919
private readonly string _connectionString;
2020
private readonly Dictionary<string, List<IIntegrationEventHandler>> _handlers;
2121
private readonly List<Type> _eventTypes;
@@ -120,24 +120,11 @@ private IModel GetChannel()
120120

121121
var consumer = new EventingBasicConsumer(channel);
122122
consumer.Received += async (model, ea) =>
123-
{
123+
{
124124
var eventName = ea.RoutingKey;
125-
if (_handlers.ContainsKey(eventName))
126-
{
127-
var message = Encoding.UTF8.GetString(ea.Body);
128-
Type eventType = _eventTypes.Single(t => t.Name == eventName);
129-
130-
var integrationEvent = JsonConvert.DeserializeObject(message, eventType);
131-
var handlers = _handlers[eventName];
132-
133-
134-
var concreteType = typeof(IIntegrationEventHandler<>).MakeGenericType(eventType);
135-
136-
foreach (var handler in handlers)
137-
{
138-
await (Task)concreteType.GetMethod("Handle").Invoke(handler, new object[] { integrationEvent });
139-
}
140-
}
125+
var message = Encoding.UTF8.GetString(ea.Body);
126+
127+
await ProcessEvent(eventName, message);
141128
};
142129
channel.BasicConsume(queue: _queueName,
143130
noAck: true,
@@ -147,5 +134,21 @@ private IModel GetChannel()
147134
return _connection.Item1;
148135
}
149136
}
137+
138+
private async Task ProcessEvent(string eventName, string message)
139+
{
140+
if (_handlers.ContainsKey(eventName))
141+
{
142+
Type eventType = _eventTypes.Single(t => t.Name == eventName);
143+
var integrationEvent = JsonConvert.DeserializeObject(message, eventType);
144+
var concreteType = typeof(IIntegrationEventHandler<>).MakeGenericType(eventType);
145+
var handlers = _handlers[eventName];
146+
147+
foreach (var handler in handlers)
148+
{
149+
await (Task)concreteType.GetMethod("Handle").Invoke(handler, new object[] { integrationEvent });
150+
}
151+
}
152+
}
150153
}
151154
}

src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
1212
{
1313
[Route("api/v1/[controller]")]
14-
//[Authorize]
14+
[Authorize]
1515
public class OrdersController : Controller
1616
{
1717
private readonly IMediator _mediator;

test/Services/FunctionalTests/Middleware/AutoAuthorizeMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public AutoAuthorizeMiddleware(RequestDelegate rd)
1717

1818
public async Task Invoke(HttpContext httpContext)
1919
{
20-
var identity = new ClaimsIdentity();
20+
var identity = new ClaimsIdentity("cookies");
2121
identity.AddClaim(new Claim("sub", "1234"));
2222
httpContext.User.AddIdentity(identity);
2323
await _next.Invoke(httpContext);

test/Services/IntegrationTests/Middleware/AutoAuthorizeMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public AutoAuthorizeMiddleware(RequestDelegate rd)
1717

1818
public async Task Invoke(HttpContext httpContext)
1919
{
20-
var identity = new ClaimsIdentity();
20+
var identity = new ClaimsIdentity("cookies");
2121
identity.AddClaim(new Claim("sub", "1234"));
2222
httpContext.User.AddIdentity(identity);
2323
await _next.Invoke(httpContext);

0 commit comments

Comments
 (0)