Skip to content

Commit

Permalink
Fix AMQP for C SDK (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
varunpuranik authored Oct 10, 2018
1 parent 775cf95 commit 84be08c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ public static class Constants
public const string MessageAnnotationsConnectionModuleId = "iothub-connection-module-id";
public const string WebSocketSubProtocol = "AMQPWSB10";
public const string WebSocketListenerName = WebSocketSubProtocol +"-listener";
public const string ServiceBusCbsSaslMechanismName = "MSSBCBS";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ void AddSaslProvider()
// needs (i.e. old clients that are still using EXTERNAL for CBS).
// saslProvider.AddHandler(new SaslExternalHandler());

saslProvider.AddHandler(new SaslAnonymousHandler()); // CBS for other clients
// CBS
saslProvider.AddHandler(new SaslAnonymousHandler());

// CBS - used by some SDKs like C
saslProvider.AddHandler(new SaslAnonymousHandler(Constants.ServiceBusCbsSaslMechanismName));

// This handler implements SAS key based auth.
saslProvider.AddHandler(new SaslPlainHandler(new EdgeHubSaslPlainAuthenticator(authenticator, identityFactory, iotHubHostName)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace Microsoft.Azure.Devices.Edge.Hub.Amqp.Test
{
using System;
using Microsoft.Azure.Amqp;
using Microsoft.Azure.Amqp.Sasl;
using Microsoft.Azure.Amqp.Transport;
using Microsoft.Azure.Devices.Edge.Hub.Amqp.LinkHandlers;
using Microsoft.Azure.Devices.Edge.Hub.Amqp.Settings;
using Microsoft.Azure.Devices.Edge.Hub.Core;
Expand All @@ -11,10 +14,10 @@ namespace Microsoft.Azure.Devices.Edge.Hub.Amqp.Test
using Moq;
using Xunit;

[Unit]
public class AmqpSettingsProviderTest
{
[Fact]
[Unit]
[Fact]
public void TestInvalidInputsForGetDefaultAmqpSettings()
{
const string IotHubHostName = "restaurantatendofuniverse.azure-devices.net";
Expand All @@ -29,5 +32,40 @@ public void TestInvalidInputsForGetDefaultAmqpSettings()

Assert.NotNull(AmqpSettingsProvider.GetDefaultAmqpSettings(IotHubHostName, authenticator.Object, identityFactory.Object, linkHandlerProvider, connectionProvider, new NullCredentialsCache()));
}

[Fact]
public void ValidateSettingsTest()
{
// Arrange
string iotHubHostName = "foo.azure-devices.net";
var authenticator = Mock.Of<IAuthenticator>();
var identityFactory = Mock.Of<IClientCredentialsFactory>();
var linkHandlerProvider = Mock.Of<ILinkHandlerProvider>();
var connectionProvider = Mock.Of<IConnectionProvider>();

// Act
AmqpSettings settings = AmqpSettingsProvider.GetDefaultAmqpSettings(iotHubHostName, authenticator, identityFactory, linkHandlerProvider, connectionProvider, new NullCredentialsCache());

// Assert
Assert.NotNull(settings);
Assert.Equal(2, settings.TransportProviders.Count);

var saslTransportProvider = settings.GetTransportProvider<SaslTransportProvider>();
Assert.NotNull(saslTransportProvider);

SaslHandler anonHandler = saslTransportProvider.GetHandler("ANONYMOUS", false);
Assert.NotNull(anonHandler);

SaslHandler plainHandler = saslTransportProvider.GetHandler("PLAIN", false);
Assert.NotNull(plainHandler);

SaslHandler cbsHandler = saslTransportProvider.GetHandler(Amqp.Constants.ServiceBusCbsSaslMechanismName, false);
Assert.NotNull(cbsHandler);

var amqpTransportProvider = settings.GetTransportProvider<AmqpTransportProvider>();
Assert.NotNull(amqpTransportProvider);

Assert.Equal(Amqp.Constants.AmqpVersion100, amqpTransportProvider.Versions[0]);
}
}
}

0 comments on commit 84be08c

Please sign in to comment.