summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/OAuth2
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Test/OAuth2')
-rw-r--r--src/DotNetOpenAuth.Test/OAuth2/OAuth2Coordinator.cs27
-rw-r--r--src/DotNetOpenAuth.Test/OAuth2/UserAgentClientAuthorizeTests.cs74
-rw-r--r--src/DotNetOpenAuth.Test/OAuth2/WebServerClientAuthorizeTests.cs (renamed from src/DotNetOpenAuth.Test/OAuth2/AuthorizeTests.cs)14
3 files changed, 97 insertions, 18 deletions
diff --git a/src/DotNetOpenAuth.Test/OAuth2/OAuth2Coordinator.cs b/src/DotNetOpenAuth.Test/OAuth2/OAuth2Coordinator.cs
index 5af7fe8..993cad5 100644
--- a/src/DotNetOpenAuth.Test/OAuth2/OAuth2Coordinator.cs
+++ b/src/DotNetOpenAuth.Test/OAuth2/OAuth2Coordinator.cs
@@ -12,34 +12,43 @@ namespace DotNetOpenAuth.Test.OAuth2 {
using DotNetOpenAuth.OAuth2;
using DotNetOpenAuth.Test.Mocks;
- internal class OAuth2Coordinator : CoordinatorBase<WebServerClient, AuthorizationServer> {
+ internal class OAuth2Coordinator<TClient> : CoordinatorBase<TClient, AuthorizationServer>
+ where TClient : ClientBase {
private readonly AuthorizationServerDescription serverDescription;
private readonly IAuthorizationServer authServerHost;
+ private readonly TClient client;
- internal OAuth2Coordinator(AuthorizationServerDescription serverDescription, IAuthorizationServer authServerHost, Action<WebServerClient> clientAction, Action<AuthorizationServer> authServerAction)
+ internal OAuth2Coordinator(
+ AuthorizationServerDescription serverDescription,
+ IAuthorizationServer authServerHost,
+ TClient client,
+ Action<TClient> clientAction,
+ Action<AuthorizationServer> authServerAction)
: base(clientAction, authServerAction) {
Requires.NotNull(serverDescription, "serverDescription");
Requires.NotNull(authServerHost, "authServerHost");
+ Requires.NotNull(client, "client");
+
this.serverDescription = serverDescription;
this.authServerHost = authServerHost;
+ this.client = client;
+
+ this.client.ClientIdentifier = OAuth2TestBase.ClientId;
+ this.client.ClientSecret = OAuth2TestBase.ClientSecret;
}
internal override void Run() {
- var client = new WebServerClient(this.serverDescription) {
- ClientIdentifier = OAuth2TestBase.ClientId,
- ClientSecret = OAuth2TestBase.ClientSecret,
- };
var authServer = new AuthorizationServer(this.authServerHost);
- var rpCoordinatingChannel = new CoordinatingChannel(client.Channel, this.IncomingMessageFilter, this.OutgoingMessageFilter);
+ var rpCoordinatingChannel = new CoordinatingChannel(this.client.Channel, this.IncomingMessageFilter, this.OutgoingMessageFilter);
var opCoordinatingChannel = new CoordinatingOAuth2AuthServerChannel(authServer.Channel, this.IncomingMessageFilter, this.OutgoingMessageFilter);
rpCoordinatingChannel.RemoteChannel = opCoordinatingChannel;
opCoordinatingChannel.RemoteChannel = rpCoordinatingChannel;
- client.Channel = rpCoordinatingChannel;
+ this.client.Channel = rpCoordinatingChannel;
authServer.Channel = opCoordinatingChannel;
- this.RunCore(client, authServer);
+ this.RunCore(this.client, authServer);
}
private static Action<WebServerClient> WrapAction(Action<WebServerClient> action) {
diff --git a/src/DotNetOpenAuth.Test/OAuth2/UserAgentClientAuthorizeTests.cs b/src/DotNetOpenAuth.Test/OAuth2/UserAgentClientAuthorizeTests.cs
new file mode 100644
index 0000000..82c8b66
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OAuth2/UserAgentClientAuthorizeTests.cs
@@ -0,0 +1,74 @@
+//-----------------------------------------------------------------------
+// <copyright file="UserAgentClientAuthorizeTests.cs" company="Outercurve Foundation">
+// Copyright (c) Outercurve Foundation. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OAuth2 {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.Messaging.Bindings;
+ using DotNetOpenAuth.OAuth2;
+ using DotNetOpenAuth.OAuth2.ChannelElements;
+ using DotNetOpenAuth.OAuth2.Messages;
+ using Moq;
+ using NUnit.Framework;
+
+ [TestFixture]
+ public class UserAgentClientAuthorizeTests : OAuth2TestBase {
+ [TestCase]
+ public void AuthorizationCodeGrantAuthorization() {
+ var coordinator = new OAuth2Coordinator<UserAgentClient>(
+ AuthorizationServerDescription,
+ AuthorizationServerMock,
+ new UserAgentClient(AuthorizationServerDescription),
+ client => {
+ var authState = new AuthorizationState {
+ Callback = ClientCallback,
+ };
+ var request = client.PrepareRequestUserAuthorization(authState);
+ client.Channel.Respond(request);
+ var incoming = client.Channel.ReadFromRequest();
+ var result = client.ProcessUserAuthorization(authState, incoming);
+ Assert.IsNotNullOrEmpty(result.AccessToken);
+ Assert.IsNotNullOrEmpty(result.RefreshToken);
+ },
+ server => {
+ var request = server.ReadAuthorizationRequest();
+ server.ApproveAuthorizationRequest(request, Username);
+ var tokenRequest = server.ReadAccessTokenRequest();
+ var tokenResponse = server.PrepareAccessTokenResponse(tokenRequest);
+ server.Channel.Respond(tokenResponse);
+ });
+ coordinator.Run();
+ }
+
+ [TestCase]
+ public void ImplicitGrantAuthorization() {
+ var coordinator = new OAuth2Coordinator<UserAgentClient>(
+ AuthorizationServerDescription,
+ AuthorizationServerMock,
+ new UserAgentClient(AuthorizationServerDescription),
+ client => {
+ var authState = new AuthorizationState {
+ Callback = ClientCallback,
+ };
+ var request = client.PrepareRequestUserAuthorization(authState);
+ request.ResponseType = EndUserAuthorizationResponseType.AccessToken;
+ client.Channel.Respond(request);
+ var incoming = client.Channel.ReadFromRequest();
+ var result = client.ProcessUserAuthorization(authState, incoming);
+ Assert.IsNotNullOrEmpty(result.AccessToken);
+ Assert.IsNull(result.RefreshToken);
+ },
+ server => {
+ var request = server.ReadAuthorizationRequest();
+ server.ApproveAuthorizationRequest(request, Username);
+ });
+ coordinator.Run();
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/OAuth2/AuthorizeTests.cs b/src/DotNetOpenAuth.Test/OAuth2/WebServerClientAuthorizeTests.cs
index d4e09fa..ec466f8 100644
--- a/src/DotNetOpenAuth.Test/OAuth2/AuthorizeTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth2/WebServerClientAuthorizeTests.cs
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
-// <copyright file="AuthorizeTests.cs" company="Outercurve Foundation">
+// <copyright file="WebServerClientAuthorizeTests.cs" company="Outercurve Foundation">
// Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
@@ -9,21 +9,17 @@ namespace DotNetOpenAuth.Test.OAuth2 {
using System.Collections.Generic;
using System.Linq;
using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.Messaging.Bindings;
using DotNetOpenAuth.OAuth2;
- using DotNetOpenAuth.OAuth2.ChannelElements;
- using DotNetOpenAuth.OAuth2.Messages;
- using Moq;
using NUnit.Framework;
[TestFixture]
- public class AuthorizeTests : OAuth2TestBase {
+ public class WebServerClientAuthorizeTests : OAuth2TestBase {
[TestCase]
- public void AuthCodeGrantAuthorization() {
- var coordinator = new OAuth2Coordinator(
+ public void AuthorizationCodeGrantAuthorization() {
+ var coordinator = new OAuth2Coordinator<WebServerClient>(
AuthorizationServerDescription,
AuthorizationServerMock,
+ new WebServerClient(AuthorizationServerDescription),
client => {
var authState = new AuthorizationState {
Callback = ClientCallback,