blob: ed6ce70f123a1b5a26b9e022db673d407771a8a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
//-----------------------------------------------------------------------
// <copyright file="OAuth2TestBase.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;
public class OAuth2TestBase : TestBase {
protected internal const string ClientId = "TestClientId";
protected internal const string ClientSecret = "TestClientSecret";
protected const string ResourceOwnerUsername = "TestUser";
protected const string ResourceOwnerPassword = "TestUserPassword";
protected static readonly string[] TestScopes = new[] { "Scope1", "Scope2" };
protected static readonly Uri ClientCallback = new Uri("http://client/callback");
protected static readonly AuthorizationServerDescription AuthorizationServerDescription = new AuthorizationServerDescription {
AuthorizationEndpoint = new Uri("https://authserver/authorize"),
TokenEndpoint = new Uri("https://authserver/token"),
};
protected static readonly IClientDescription ClientDescription = new ClientDescription(
ClientSecret,
ClientCallback,
ClientType.Confidential);
protected static readonly IAuthorizationServer AuthorizationServerMock = CreateAuthorizationServerMock().Object;
protected static Mock<IAuthorizationServer> CreateAuthorizationServerMock() {
var authHostMock = new Mock<IAuthorizationServer>();
var cryptoStore = new MemoryCryptoKeyStore();
authHostMock.Setup(m => m.GetClient(ClientId)).Returns(ClientDescription);
authHostMock.SetupGet(m => m.CryptoKeyStore).Returns(cryptoStore);
authHostMock.Setup(
m =>
m.IsAuthorizationValid(
It.Is<IAuthorizationDescription>(
d =>
d.ClientIdentifier == ClientId && d.User == ResourceOwnerUsername &&
MessagingUtilities.AreEquivalent(d.Scope, TestScopes)))).Returns(true);
authHostMock.Setup(m => m.IsResourceOwnerCredentialValid(ResourceOwnerUsername, ResourceOwnerPassword)).Returns(true);
authHostMock.Setup(m => m.GetAccessTokenParameters(It.IsAny<IAccessTokenRequest>())).Returns(new AccessTokenParameters());
return authHostMock;
}
}
}
|