我正在开发一个 Spring 应用程序,它充当 OAuth2 客户端,Spotify 是资源服务器。这是我的配置:
spring:
security:
oauth2:
client:
registration:
spotify:
client-id: ...
client-secret: ...
authorization-grant-type: authorization_code
redirect-uri: '{baseUrl}/login/oauth2/code/{registrationId}'
scope: user-read-private, user-read-email
client-name: Spotify
client-alias: spotify
provider:
spotify:
authorization-uri: https://accounts.spotify.com/authorize
token-uri: https://accounts.spotify.com/api/token
user-info-uri: https://api.spotify.com/v1/me
user-name-attribute: display_name
Run Code Online (Sandbox Code Playgroud)
我的问题是我只是找不到如何获取 Spotify 在响应中发送的刷新令牌/api/token
Spotify 的响应如下所示:(来源: https: //developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow)
我尝试CustomUserService
像这样实现我自己的:
spring:
security:
oauth2:
client:
registration:
spotify:
client-id: ...
client-secret: ...
authorization-grant-type: authorization_code
redirect-uri: '{baseUrl}/login/oauth2/code/{registrationId}'
scope: user-read-private, user-read-email
client-name: Spotify
client-alias: spotify
provider:
spotify:
authorization-uri: https://accounts.spotify.com/authorize
token-uri: https://accounts.spotify.com/api/token
user-info-uri: https://api.spotify.com/v1/me
user-name-attribute: display_name …
Run Code Online (Sandbox Code Playgroud) 我一直在搜索我应该如何测试我的数据访问层而不是很成功.让我列出我的担忧:
这个人(这里:使用InMemoryConnection测试ElasticSearch)说:
虽然声明序列化形式的请求符合您在SUT中的期望可能就足够了.
断言请求的序列化形式是否真的值得?这些测试有什么价值吗?它似乎不太可能改变不应该更改序列化请求的函数.
如果值得,那么断言这些要求的正确方法是什么?
另一个人(这里:使用MOQ的ElasticSearch 2.0 Nest Unit Testing)显示了一个好看的例子:
void Main()
{
var people = new List<Person>
{
new Person { Id = 1 },
new Person { Id = 2 },
};
var mockSearchResponse = new Mock<ISearchResponse<Person>>();
mockSearchResponse.Setup(x => x.Documents).Returns(people);
var mockElasticClient = new Mock<IElasticClient>();
mockElasticClient.Setup(x => x
.Search(It.IsAny<Func<SearchDescriptor<Person>, ISearchRequest>>()))
.Returns(mockSearchResponse.Object);
var result = mockElasticClient.Object.Search<Person>(s => s);
Assert.AreEqual(2, result.Documents.Count()).Dump();
}
public class Person
{
public int Id { get; set;}
}
Run Code Online (Sandbox Code Playgroud)
可能我错过了一些东西,但我看不出这段代码的重点.首先,他嘲笑一个 …