summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs')
-rw-r--r--src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs333
1 files changed, 169 insertions, 164 deletions
diff --git a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
index 029447d..6e3d7dc 100644
--- a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
+++ b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs
@@ -6,6 +6,8 @@
namespace DotNetOpenAuth.Test.OpenId {
using System;
+ using System.Threading;
+ using System.Threading.Tasks;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.Messages;
@@ -22,13 +24,13 @@ namespace DotNetOpenAuth.Test.OpenId {
}
[Test]
- public void AssociateUnencrypted() {
- this.ParameterizedAssociationTest(new Uri("https://host"));
+ public async Task AssociateUnencrypted() {
+ await this.ParameterizedAssociationTestAsync(OPUriSsl);
}
[Test]
- public void AssociateDiffieHellmanOverHttp() {
- this.ParameterizedAssociationTest(new Uri("http://host"));
+ public async Task AssociateDiffieHellmanOverHttp() {
+ await this.ParameterizedAssociationTestAsync(OPUri);
}
/// <summary>
@@ -39,23 +41,22 @@ namespace DotNetOpenAuth.Test.OpenId {
/// putting the two together, so we verify that DNOI can handle it.
/// </remarks>
[Test]
- public void AssociateDiffieHellmanOverHttps() {
+ public async Task AssociateDiffieHellmanOverHttps() {
Protocol protocol = Protocol.V20;
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- // We have to formulate the associate request manually,
- // since the DNOI RP won't voluntarily use DH on HTTPS.
- AssociateDiffieHellmanRequest request = new AssociateDiffieHellmanRequest(protocol.Version, new Uri("https://Provider"));
- request.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA256;
- request.SessionType = protocol.Args.SessionType.DH_SHA256;
- request.InitializeRequest();
- var response = rp.Channel.Request<AssociateSuccessfulResponse>(request);
- Assert.IsNotNull(response);
- Assert.AreEqual(request.AssociationType, response.AssociationType);
- Assert.AreEqual(request.SessionType, response.SessionType);
- },
- AutoProvider);
- coordinator.Run();
+ this.RegisterAutoProvider();
+ var rp = this.CreateRelyingParty();
+
+ // We have to formulate the associate request manually,
+ // since the DNOI RP won't voluntarily use DH on HTTPS.
+ var request = new AssociateDiffieHellmanRequest(protocol.Version, OPUri) {
+ AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA256,
+ SessionType = protocol.Args.SessionType.DH_SHA256
+ };
+ request.InitializeRequest();
+ var response = await rp.Channel.RequestAsync<AssociateSuccessfulResponse>(request, CancellationToken.None);
+ Assert.IsNotNull(response);
+ Assert.AreEqual(request.AssociationType, response.AssociationType);
+ Assert.AreEqual(request.SessionType, response.SessionType);
}
/// <summary>
@@ -63,44 +64,52 @@ namespace DotNetOpenAuth.Test.OpenId {
/// initial request for an association is for a type the OP doesn't support.
/// </summary>
[Test]
- public void AssociateRenegotiateBitLength() {
+ public async Task AssociateRenegotiateBitLength() {
Protocol protocol = Protocol.V20;
// The strategy is to make a simple request of the RP to establish an association,
// and to more carefully observe the Provider-side of things to make sure that both
// the OP and RP are behaving as expected.
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- var opDescription = new ProviderEndpointDescription(OPUri, protocol.Version);
- Association association = rp.AssociationManager.GetOrCreateAssociation(opDescription);
- Assert.IsNotNull(association, "Association failed to be created.");
- Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA1, association.GetAssociationType(protocol));
- },
- op => {
+ int providerAttemptCount = 0;
+ HandleProvider(
+ async (op, request) => {
op.SecuritySettings.MaximumHashBitLength = 160; // Force OP to reject HMAC-SHA256
- // Receive initial request for an HMAC-SHA256 association.
- AutoResponsiveRequest req = (AutoResponsiveRequest)op.GetRequest();
- AssociateRequest associateRequest = (AssociateRequest)req.RequestMessage;
- Assert.That(associateRequest, Is.Not.Null);
- Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA256, associateRequest.AssociationType);
-
- // Ensure that the response is a suggestion that the RP try again with HMAC-SHA1
- AssociateUnsuccessfulResponse renegotiateResponse = (AssociateUnsuccessfulResponse)req.ResponseMessageTestHook;
- Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA1, renegotiateResponse.AssociationType);
- op.Respond(req);
-
- // Receive second attempt request for an HMAC-SHA1 association.
- req = (AutoResponsiveRequest)op.GetRequest();
- associateRequest = (AssociateRequest)req.RequestMessage;
- Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA1, associateRequest.AssociationType);
-
- // Ensure that the response is a success response.
- AssociateSuccessfulResponse successResponse = (AssociateSuccessfulResponse)req.ResponseMessageTestHook;
- Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA1, successResponse.AssociationType);
- op.Respond(req);
+ switch (++providerAttemptCount) {
+ case 1:
+ // Receive initial request for an HMAC-SHA256 association.
+ var req = (AutoResponsiveRequest)await op.GetRequestAsync(request);
+ var associateRequest = (AssociateRequest)req.RequestMessage;
+ Assert.That(associateRequest, Is.Not.Null);
+ Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA256, associateRequest.AssociationType);
+
+ // Ensure that the response is a suggestion that the RP try again with HMAC-SHA1
+ var renegotiateResponse =
+ (AssociateUnsuccessfulResponse)await req.GetResponseMessageAsyncTestHook(CancellationToken.None);
+ Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA1, renegotiateResponse.AssociationType);
+ return await op.PrepareResponseAsync(req);
+
+ case 2:
+ // Receive second attempt request for an HMAC-SHA1 association.
+ req = (AutoResponsiveRequest)await op.GetRequestAsync(request);
+ associateRequest = (AssociateRequest)req.RequestMessage;
+ Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA1, associateRequest.AssociationType);
+
+ // Ensure that the response is a success response.
+ var successResponse =
+ (AssociateSuccessfulResponse)await req.GetResponseMessageAsyncTestHook(CancellationToken.None);
+ Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA1, successResponse.AssociationType);
+ return await op.PrepareResponseAsync(req);
+
+ default:
+ throw Assumes.NotReachable();
+ }
});
- coordinator.Run();
+ var rp = this.CreateRelyingParty();
+ var opDescription = new ProviderEndpointDescription(OPUri, protocol.Version);
+ Association association = await rp.AssociationManager.GetOrCreateAssociationAsync(opDescription, CancellationToken.None);
+ Assert.IsNotNull(association, "Association failed to be created.");
+ Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA1, association.GetAssociationType(protocol));
}
/// <summary>
@@ -110,20 +119,18 @@ namespace DotNetOpenAuth.Test.OpenId {
/// Verifies OP's compliance with OpenID 2.0 section 8.4.1.
/// </remarks>
[Test]
- public void OPRejectsHttpNoEncryptionAssociateRequests() {
+ public async Task OPRejectsHttpNoEncryptionAssociateRequests() {
Protocol protocol = Protocol.V20;
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- // We have to formulate the associate request manually,
- // since the DNOI RP won't voluntarily suggest no encryption at all.
- var request = new AssociateUnencryptedRequestNoSslCheck(protocol.Version, OPUri);
- request.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA256;
- request.SessionType = protocol.Args.SessionType.NoEncryption;
- var response = rp.Channel.Request<DirectErrorResponse>(request);
- Assert.IsNotNull(response);
- },
- AutoProvider);
- coordinator.Run();
+ this.RegisterAutoProvider();
+ var rp = this.CreateRelyingParty();
+
+ // We have to formulate the associate request manually,
+ // since the DNOA RP won't voluntarily suggest no encryption at all.
+ var request = new AssociateUnencryptedRequestNoSslCheck(protocol.Version, OPUri);
+ request.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA256;
+ request.SessionType = protocol.Args.SessionType.NoEncryption;
+ var response = await rp.Channel.RequestAsync<DirectErrorResponse>(request, CancellationToken.None);
+ Assert.IsNotNull(response);
}
/// <summary>
@@ -131,47 +138,43 @@ namespace DotNetOpenAuth.Test.OpenId {
/// when the HMAC and DH bit lengths do not match.
/// </summary>
[Test]
- public void OPRejectsMismatchingAssociationAndSessionTypes() {
+ public async Task OPRejectsMismatchingAssociationAndSessionTypes() {
Protocol protocol = Protocol.V20;
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- // We have to formulate the associate request manually,
- // since the DNOI RP won't voluntarily mismatch the association and session types.
- AssociateDiffieHellmanRequest request = new AssociateDiffieHellmanRequest(protocol.Version, new Uri("https://Provider"));
- request.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA256;
- request.SessionType = protocol.Args.SessionType.DH_SHA1;
- request.InitializeRequest();
- var response = rp.Channel.Request<AssociateUnsuccessfulResponse>(request);
- Assert.IsNotNull(response);
- Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA1, response.AssociationType);
- Assert.AreEqual(protocol.Args.SessionType.DH_SHA1, response.SessionType);
- },
- AutoProvider);
- coordinator.Run();
+ this.RegisterAutoProvider();
+ var rp = this.CreateRelyingParty();
+
+ // We have to formulate the associate request manually,
+ // since the DNOI RP won't voluntarily mismatch the association and session types.
+ var request = new AssociateDiffieHellmanRequest(protocol.Version, OPUri);
+ request.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA256;
+ request.SessionType = protocol.Args.SessionType.DH_SHA1;
+ request.InitializeRequest();
+ var response = await rp.Channel.RequestAsync<AssociateUnsuccessfulResponse>(request, CancellationToken.None);
+ Assert.IsNotNull(response);
+ Assert.AreEqual(protocol.Args.SignatureAlgorithm.HMAC_SHA1, response.AssociationType);
+ Assert.AreEqual(protocol.Args.SessionType.DH_SHA1, response.SessionType);
}
/// <summary>
/// Verifies that the RP quietly rejects an OP that suggests an unknown association type.
/// </summary>
[Test]
- public void RPRejectsUnrecognizedAssociationType() {
+ public async Task RPRejectsUnrecognizedAssociationType() {
Protocol protocol = Protocol.V20;
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(OPUri, protocol.Version));
- Assert.IsNull(association, "The RP should quietly give up when the OP misbehaves.");
- },
- op => {
+ HandleProvider(
+ async (op, req) => {
// Receive initial request.
- var request = op.Channel.ReadFromRequest<AssociateRequest>();
+ var request = await op.Channel.ReadFromRequestAsync<AssociateRequest>(req, CancellationToken.None);
// Send a response that suggests a foreign association type.
- AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request);
+ var renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request);
renegotiateResponse.AssociationType = "HMAC-UNKNOWN";
renegotiateResponse.SessionType = "DH-UNKNOWN";
- op.Channel.Respond(renegotiateResponse);
+ return await op.Channel.PrepareResponseAsync(renegotiateResponse);
});
- coordinator.Run();
+ var rp = this.CreateRelyingParty();
+ var association = await rp.AssociationManager.GetOrCreateAssociationAsync(new ProviderEndpointDescription(OPUri, protocol.Version), CancellationToken.None);
+ Assert.IsNull(association, "The RP should quietly give up when the OP misbehaves.");
}
/// <summary>
@@ -181,24 +184,23 @@ namespace DotNetOpenAuth.Test.OpenId {
/// Verifies RP's compliance with OpenID 2.0 section 8.4.1.
/// </remarks>
[Test]
- public void RPRejectsUnencryptedSuggestion() {
+ public async Task RPRejectsUnencryptedSuggestion() {
Protocol protocol = Protocol.V20;
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(OPUri, protocol.Version));
- Assert.IsNull(association, "The RP should quietly give up when the OP misbehaves.");
- },
- op => {
+ this.HandleProvider(
+ async (op, req) => {
// Receive initial request.
- var request = op.Channel.ReadFromRequest<AssociateRequest>();
+ var request = await op.Channel.ReadFromRequestAsync<AssociateRequest>(req, CancellationToken.None);
// Send a response that suggests a no encryption.
- AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request);
+ var renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request);
renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA1;
renegotiateResponse.SessionType = protocol.Args.SessionType.NoEncryption;
- op.Channel.Respond(renegotiateResponse);
+ return await op.Channel.PrepareResponseAsync(renegotiateResponse);
});
- coordinator.Run();
+
+ var rp = this.CreateRelyingParty();
+ var association = await rp.AssociationManager.GetOrCreateAssociationAsync(new ProviderEndpointDescription(OPUri, protocol.Version), CancellationToken.None);
+ Assert.IsNull(association, "The RP should quietly give up when the OP misbehaves.");
}
/// <summary>
@@ -206,24 +208,22 @@ namespace DotNetOpenAuth.Test.OpenId {
/// when the HMAC and DH bit lengths do not match.
/// </summary>
[Test]
- public void RPRejectsMismatchingAssociationAndSessionBitLengths() {
+ public async Task RPRejectsMismatchingAssociationAndSessionBitLengths() {
Protocol protocol = Protocol.V20;
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(OPUri, protocol.Version));
- Assert.IsNull(association, "The RP should quietly give up when the OP misbehaves.");
- },
- op => {
+ this.HandleProvider(
+ async (op, req) => {
// Receive initial request.
- var request = op.Channel.ReadFromRequest<AssociateRequest>();
+ var request = await op.Channel.ReadFromRequestAsync<AssociateRequest>(req, CancellationToken.None);
// Send a mismatched response
AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request);
renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA1;
renegotiateResponse.SessionType = protocol.Args.SessionType.DH_SHA256;
- op.Channel.Respond(renegotiateResponse);
+ return await op.Channel.PrepareResponseAsync(renegotiateResponse);
});
- coordinator.Run();
+ var rp = this.CreateRelyingParty();
+ var association = await rp.AssociationManager.GetOrCreateAssociationAsync(new ProviderEndpointDescription(OPUri, protocol.Version), CancellationToken.None);
+ Assert.IsNull(association, "The RP should quietly give up when the OP misbehaves.");
}
/// <summary>
@@ -231,52 +231,56 @@ namespace DotNetOpenAuth.Test.OpenId {
/// keeps sending it association retry messages.
/// </summary>
[Test]
- public void RPOnlyRenegotiatesOnce() {
+ public async Task RPOnlyRenegotiatesOnce() {
Protocol protocol = Protocol.V20;
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(OPUri, protocol.Version));
- Assert.IsNull(association, "The RP should quietly give up when the OP misbehaves.");
- },
- op => {
- // Receive initial request.
- var request = op.Channel.ReadFromRequest<AssociateRequest>();
+ int opStep = 0;
+ HandleProvider(
+ async (op, req) => {
+ switch (++opStep) {
+ case 1:
+ // Receive initial request.
+ var request = await op.Channel.ReadFromRequestAsync<AssociateRequest>(req, CancellationToken.None);
- // Send a renegotiate response
- AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request);
- renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA1;
- renegotiateResponse.SessionType = protocol.Args.SessionType.DH_SHA1;
- op.Channel.Respond(renegotiateResponse);
+ // Send a renegotiate response
+ var renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request);
+ renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA1;
+ renegotiateResponse.SessionType = protocol.Args.SessionType.DH_SHA1;
+ return await op.Channel.PrepareResponseAsync(renegotiateResponse, CancellationToken.None);
- // Receive second-try
- request = op.Channel.ReadFromRequest<AssociateRequest>();
+ case 2:
+ // Receive second-try
+ request = await op.Channel.ReadFromRequestAsync<AssociateRequest>(req, CancellationToken.None);
- // Send ANOTHER renegotiate response, at which point the DNOI RP should give up.
- renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request);
- renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA256;
- renegotiateResponse.SessionType = protocol.Args.SessionType.DH_SHA256;
- op.Channel.Respond(renegotiateResponse);
+ // Send ANOTHER renegotiate response, at which point the DNOI RP should give up.
+ renegotiateResponse = new AssociateUnsuccessfulResponse(request.Version, request);
+ renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA256;
+ renegotiateResponse.SessionType = protocol.Args.SessionType.DH_SHA256;
+ return await op.Channel.PrepareResponseAsync(renegotiateResponse, CancellationToken.None);
+
+ default:
+ throw Assumes.NotReachable();
+ }
});
- coordinator.Run();
+ var rp = this.CreateRelyingParty();
+ var association = await rp.AssociationManager.GetOrCreateAssociationAsync(new ProviderEndpointDescription(OPUri, protocol.Version), CancellationToken.None);
+ Assert.IsNull(association, "The RP should quietly give up when the OP misbehaves.");
}
/// <summary>
/// Verifies security settings limit RP's acceptance of OP's counter-suggestion
/// </summary>
[Test]
- public void AssociateRenegotiateLimitedByRPSecuritySettings() {
+ public async Task AssociateRenegotiateLimitedByRPSecuritySettings() {
Protocol protocol = Protocol.V20;
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- rp.SecuritySettings.MinimumHashBitLength = 256;
- var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(OPUri, protocol.Version));
- Assert.IsNull(association, "No association should have been created when RP and OP could not agree on association strength.");
- },
- op => {
+ HandleProvider(
+ async (op, req) => {
op.SecuritySettings.MaximumHashBitLength = 160;
- AutoProvider(op);
+ return await AutoProviderActionAsync(op, req, CancellationToken.None);
});
- coordinator.Run();
+ var rp = this.CreateRelyingParty();
+ rp.SecuritySettings.MinimumHashBitLength = 256;
+ var association = await rp.AssociationManager.GetOrCreateAssociationAsync(new ProviderEndpointDescription(OPUri, protocol.Version), CancellationToken.None);
+ Assert.IsNull(association, "No association should have been created when RP and OP could not agree on association strength.");
}
/// <summary>
@@ -284,10 +288,10 @@ namespace DotNetOpenAuth.Test.OpenId {
/// response from the OP, for example in the HTTP timeout case.
/// </summary>
[Test]
- public void AssociateQuietlyFailsAfterHttpError() {
- this.MockResponder.RegisterMockNotFound(OPUri);
+ public async Task AssociateQuietlyFailsAfterHttpError() {
+ // Without wiring up a mock HTTP handler, the RP will get a 404 Not Found error.
var rp = this.CreateRelyingParty();
- var association = rp.AssociationManager.GetOrCreateAssociation(new ProviderEndpointDescription(OPUri, Protocol.V20.Version));
+ var association = await rp.AssociationManager.GetOrCreateAssociationAsync(new ProviderEndpointDescription(OPUri, Protocol.V20.Version), CancellationToken.None);
Assert.IsNull(association);
}
@@ -295,11 +299,11 @@ namespace DotNetOpenAuth.Test.OpenId {
/// Runs a parameterized association flow test using all supported OpenID versions.
/// </summary>
/// <param name="opEndpoint">The OP endpoint to simulate using.</param>
- private void ParameterizedAssociationTest(Uri opEndpoint) {
+ private async Task ParameterizedAssociationTestAsync(Uri opEndpoint) {
foreach (Protocol protocol in Protocol.AllPracticalVersions) {
var endpoint = new ProviderEndpointDescription(opEndpoint, protocol.Version);
var associationType = protocol.Version.Major < 2 ? protocol.Args.SignatureAlgorithm.HMAC_SHA1 : protocol.Args.SignatureAlgorithm.HMAC_SHA256;
- this.ParameterizedAssociationTest(endpoint, associationType);
+ await this.ParameterizedAssociationTestAsync(endpoint, associationType);
}
}
@@ -314,7 +318,7 @@ namespace DotNetOpenAuth.Test.OpenId {
/// The value of the openid.assoc_type parameter expected,
/// or null if a failure is anticipated.
/// </param>
- private void ParameterizedAssociationTest(
+ private async Task ParameterizedAssociationTestAsync(
ProviderEndpointDescription opDescription,
string expectedAssociationType) {
Protocol protocol = Protocol.Lookup(Protocol.Lookup(opDescription.Version).ProtocolVersion);
@@ -323,19 +327,18 @@ namespace DotNetOpenAuth.Test.OpenId {
Association rpAssociation = null, opAssociation;
AssociateSuccessfulResponse associateSuccessfulResponse = null;
AssociateUnsuccessfulResponse associateUnsuccessfulResponse = null;
- OpenIdCoordinator coordinator = new OpenIdCoordinator(
- rp => {
- rp.SecuritySettings = this.RelyingPartySecuritySettings;
- rpAssociation = rp.AssociationManager.GetOrCreateAssociation(opDescription);
- },
- op => {
- op.SecuritySettings = this.ProviderSecuritySettings;
- IRequest req = op.GetRequest();
+ var relyingParty = new OpenIdRelyingParty(new StandardRelyingPartyApplicationStore(), this.HostFactories);
+ var provider = new OpenIdProvider(new StandardProviderApplicationStore(), this.HostFactories) {
+ SecuritySettings = this.ProviderSecuritySettings
+ };
+ Handle(opDescription.Uri).By(
+ async (request, ct) => {
+ IRequest req = await provider.GetRequestAsync(request, ct);
Assert.IsNotNull(req, "Expected incoming request but did not receive it.");
Assert.IsTrue(req.IsResponseReady);
- op.Respond(req);
+ return await provider.PrepareResponseAsync(req, ct);
});
- coordinator.IncomingMessageFilter = message => {
+ relyingParty.Channel.IncomingMessageFilter = message => {
Assert.AreSame(opDescription.Version, message.Version, "The message was recognized as version {0} but was expected to be {1}.", message.Version, Protocol.Lookup(opDescription.Version).ProtocolVersion);
var associateSuccess = message as AssociateSuccessfulResponse;
var associateFailed = message as AssociateUnsuccessfulResponse;
@@ -346,16 +349,18 @@ namespace DotNetOpenAuth.Test.OpenId {
associateUnsuccessfulResponse = associateFailed;
}
};
- coordinator.OutgoingMessageFilter = message => {
+ relyingParty.Channel.OutgoingMessageFilter = message => {
Assert.AreEqual(opDescription.Version, message.Version, "The message was for version {0} but was expected to be for {1}.", message.Version, opDescription.Version);
};
- coordinator.Run();
+
+ relyingParty.SecuritySettings = this.RelyingPartySecuritySettings;
+ rpAssociation = await relyingParty.AssociationManager.GetOrCreateAssociationAsync(opDescription, CancellationToken.None);
if (expectSuccess) {
Assert.IsNotNull(rpAssociation);
- Association actual = coordinator.RelyingParty.AssociationManager.AssociationStoreTestHook.GetAssociation(opDescription.Uri, rpAssociation.Handle);
+ Association actual = relyingParty.AssociationManager.AssociationStoreTestHook.GetAssociation(opDescription.Uri, rpAssociation.Handle);
Assert.AreEqual(rpAssociation, actual);
- opAssociation = coordinator.Provider.AssociationStore.Deserialize(new TestSignedDirectedMessage(), false, rpAssociation.Handle);
+ opAssociation = provider.AssociationStore.Deserialize(new TestSignedDirectedMessage(), false, rpAssociation.Handle);
Assert.IsNotNull(opAssociation, "The Provider could not decode the association handle.");
Assert.AreEqual(opAssociation.Handle, rpAssociation.Handle);
@@ -373,7 +378,7 @@ namespace DotNetOpenAuth.Test.OpenId {
var unencryptedResponse = (AssociateUnencryptedResponse)associateSuccessfulResponse;
}
} else {
- Assert.IsNull(coordinator.RelyingParty.AssociationManager.AssociationStoreTestHook.GetAssociation(opDescription.Uri, new RelyingPartySecuritySettings()));
+ Assert.IsNull(relyingParty.AssociationManager.AssociationStoreTestHook.GetAssociation(opDescription.Uri, new RelyingPartySecuritySettings()));
}
}
}