-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix Sasl Plain Authenticator * Add comment
- Loading branch information
1 parent
afabd86
commit bb6c327
Showing
2 changed files
with
35 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,11 +85,11 @@ public async void TestAuthFailed() | |
|
||
[Fact] | ||
[Unit] | ||
public async void TestAuthSucceeds() | ||
public async void TestAuthSucceeds_Module() | ||
{ | ||
var authenticator = Mock.Of<IAuthenticator>(); | ||
var clientCredentialsFactory = Mock.Of<IClientCredentialsFactory>(); | ||
var saslAuthenticator = new EdgeSaslPlainAuthenticator(authenticator, clientCredentialsFactory, "hub1"); | ||
var saslAuthenticator = new EdgeSaslPlainAuthenticator(authenticator, clientCredentialsFactory, "hub1.azure-devices.net"); | ||
var identity = new ModuleIdentity("hub1", "dev1", "mod1"); | ||
var clientCredentials = Mock.Of<IClientCredentials>(c => c.Identity == identity); | ||
const string UserId = "dev1/modules/[email protected]"; | ||
|
@@ -109,5 +109,32 @@ public async void TestAuthSucceeds() | |
bool isAuthenticated = await amqpAuthenticator.AuthenticateAsync("dev1/mod1"); | ||
Assert.True(isAuthenticated); | ||
} | ||
|
||
[Fact] | ||
[Unit] | ||
public async void TestAuthSucceeds_Device() | ||
{ | ||
var authenticator = Mock.Of<IAuthenticator>(); | ||
var clientCredentialsFactory = Mock.Of<IClientCredentialsFactory>(); | ||
var saslAuthenticator = new EdgeSaslPlainAuthenticator(authenticator, clientCredentialsFactory, "hub1.azure-devices.net"); | ||
var identity = new DeviceIdentity("hub1", "dev1"); | ||
var clientCredentials = Mock.Of<IClientCredentials>(c => c.Identity == identity); | ||
const string UserId = "[email protected]"; | ||
const string Password = "pwd"; | ||
|
||
Mock.Get(clientCredentialsFactory).Setup(f => f.GetWithSasToken("dev1", string.Empty, string.Empty, Password, false)) | ||
.Returns(clientCredentials); | ||
Mock.Get(authenticator).Setup(a => a.AuthenticateAsync(clientCredentials)) | ||
.ReturnsAsync(true); | ||
|
||
IPrincipal principal = await saslAuthenticator.AuthenticateAsync(UserId, Password); | ||
Assert.NotNull(principal); | ||
|
||
var amqpAuthenticator = principal as IAmqpAuthenticator; | ||
Assert.NotNull(amqpAuthenticator); | ||
|
||
bool isAuthenticated = await amqpAuthenticator.AuthenticateAsync("dev1"); | ||
Assert.True(isAuthenticated); | ||
} | ||
} | ||
} |