小编Sto*_*pov的帖子

Hamcrest Matcher 签名者信息与同一包中其他类的签名者信息不匹配

我正在尝试使用 REST-Assured 和 JUnit5 在我的 Spring Boot 应用程序中编写一些集成测试,但是当我运行以下命令时:

@SpringBootTest(classes = ProductsApplication.class)
class ProductsApiTest {

  @Before
  public void setup() {
    RestAssured.baseURI = "http://localhost:8080/test/api/products";
  }

  @Test
  public void test1() {
    ValidatableResponse statusCode = given().when().get().then().statusCode(200);
  }
}
Run Code Online (Sandbox Code Playgroud)

出现一个令人讨厌的错误:

java.lang.SecurityException:类“org.hamcrest.Matchers”的签名者信息与同一包中其他类的签名者信息不匹配

请看一下我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    ...
    <dependencies>
        ...
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        ...
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>   
        <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId> …
Run Code Online (Sandbox Code Playgroud)

java junit integration-testing hamcrest spring-boot

5
推荐指数
1
解决办法
1938
查看次数

如何从控制器获取 Identity/Pages/Account/ConfirmEmail 的回调 URL?

我有一个场景,我想以与身份区域的注册页面(“身份/页面/帐户/注册”)相同的方式生成电子邮件确认 URL。我已经搭建了身份区域并可以访问其页面。

我需要从位于完全不同区域的控制器发生这种情况。我尝试做与 Register.cshtml.cs 类似的事情,但我不使用 Url.Page,而是使用 Url.Action (我们位于控制器内部,记得)。

问题是以下代码生成一个空字符串,这并不完全是我们想要的:

string confirmationLink = Url.Action("ConfirmEmail",
                        "Account", new
                        {
                            area = "Identity",
                            userid = viewModel.User.Id,
                            token = code
                        },
                        protocol: HttpContext.Request.Scheme);
Run Code Online (Sandbox Code Playgroud)

我在这里可能做错了什么?这是位于

/Areas/CompanyUsers/Controllers/HomeController.cs。

请不要评论从“随机”控制器生成此 url 的想法。我需要一种从已经经过身份验证的用户注册用户的方法(公司所有者用户必须能够将用户注册到应用程序中,而无需使用默认的身份方式来执行此操作。)。

c# asp.net-core-mvc asp.net-core

4
推荐指数
1
解决办法
2679
查看次数