Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration test failing on a newly created project #24912

Closed
artyomsv opened this issue Jan 19, 2024 · 4 comments · Fixed by #24916
Closed

Integration test failing on a newly created project #24912

artyomsv opened this issue Jan 19, 2024 · 4 comments · Fixed by #24916

Comments

@artyomsv
Copy link
Contributor

Overview of the issue

I have created a new project (Monolith) and w/o changing a bit running ```mvn clean install``. As a result one of the IT tests is failing all the time with 403 error.

2024-01-19T17:55:51.702+01:00  INFO 34528 --- [marlin-agent] [           main] c.s.r.a.m.w.r.MarlinAgentKafkaResourceIT : Started MarlinAgentKafkaResourceIT in 2.072 seconds (process running for 78.53)

MockHttpServletRequest:
      HTTP Method = POST
      Request URI = /api/marlin-agent-kafka/publish
       Parameters = {message=[value-produce]}
          Headers = []
             Body = null
    Session Attrs = {SPRING_SECURITY_CONTEXT=SecurityContextImpl [Authentication=UsernamePasswordAuthenticationToken [Principal=org.springframework.security.core.userdetails.User [Username=user, Password=[PROTECTED], Enabled=true, AccountNonExpired=true, CredentialsNonExpired=true, AccountNonLocked=true, Granted Authorities=[ROLE_USER]], Credentials=[PROTECTED], Authenticated=true, Details=null, Granted Authorities=[ROLE_USER]]]}

Handler:
             Type = null

Async:
    Async started = false
     Async result = null

Resolved Exception:
             Type = null

ModelAndView:
        View name = null
            Model = null

FlashMap:
       Attributes = null

MockHttpServletResponse:
           Status = 403
    Error message = Forbidden
          Headers = [Vary:"Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers", Set-Cookie:"XSRF-TOKEN=432f553f-08ae-4127-99d9-1f04d39f64f8; Path=/", X-Content-Type-Options:"nosniff", X-XSS-Protection:"0", Cache-Control:"no-cache, no-store, max-age=0, must-revalidate", Pragma:"no-cache", Expires:"0", X-Frame-Options:"DENY"]
     Content type = null
             Body =
    Forwarded URL = null
   Redirected URL = null
          Cookies = [[Cookie@77d6fd21 name = 'XSRF-TOKEN', value = '432f553f-08ae-4127-99d9-1f04d39f64f8', comment = [null], domain = [null], maxAge = -1, path = '/', secure = false, version = 0, httpOnly = false]]
2024-01-19T17:55:51.751+01:00  WARN 34528 --- [marlin-agent] [           main] o.s.w.s.h.HandlerMappingIntrospector     : Cache miss for REQUEST dispatch to '/api/marlin-agent-kafka/register' (previous null). Performing MatchableHandlerMapping lookup. This is logged once only at WARN level, and every time at TRACE.
[ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 2.324 s <<< FAILURE! -- in com.stukans.refirmware.agent.marlin.web.rest.MarlinAgentKafkaResourceIT
[ERROR] com.stukans.refirmware.agent.marlin.web.rest.MarlinAgentKafkaResourceIT.producesMessages -- Time elapsed: 0.026 s <<< FAILURE!
java.lang.AssertionError: Status expected:<200> but was:<403>
        at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:59)
        at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:122)
        at org.springframework.test.web.servlet.result.StatusResultMatchers.lambda$matcher$9(StatusResultMatchers.java:637)
        at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:214)
        at com.stukans.refirmware.agent.marlin.web.rest.MarlinAgentKafkaResourceIT.producesMessages(MarlinAgentKafkaResourceIT.java:46)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

[INFO] Running com.stukans.refirmware.agent.marlin.web.rest.errors.ExceptionTranslatorIT

        ██╗ ██╗   ██╗ ████████╗ ███████╗   ██████╗ ████████╗ ████████╗ ███████╗
        ██║ ██║   ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
        ██║ ████████║    ██║    ███████╔╝ ╚█████╗     ██║    ██████╗   ███████╔╝
  ██╗   ██║ ██╔═══██║    ██║    ██╔════╝   ╚═══██╗    ██║    ██╔═══╝   ██╔══██║
  ╚██████╔╝ ██║   ██║ ████████╗ ██║       ██████╔╝    ██║    ████████╗ ██║  ╚██╗
   ╚═════╝  ╚═╝   ╚═╝ ╚═══════╝ ╚═╝       ╚═════╝     ╚═╝    ╚═══════╝ ╚═╝   ╚═╝

:: JHipster ?  :: Running Spring Boot 3.2.0 :: Startup profile(s) testdev ::
:: https://www.jhipster.tech ::

2024-01-19T17:55:52.031+01:00  INFO 34528 --- [marlin-agent] [           main] ContainersSpringContextCustomizerFactory : Warming up the kafka broker
2024-01-19T17:55:52.035+01:00  INFO 34528 --- [marlin-agent] [           main] c.s.r.a.m.w.r.e.ExceptionTranslatorIT    : Starting ExceptionTranslatorIT using Java 17.0.3.1 with PID 34528 (started by artjo in E:\Projects\JHipster\refirmware\test)
2024-01-19T17:55:52.036+01:00  INFO 34528 --- [marlin-agent] [           main] c.s.r.a.m.w.r.e.ExceptionTranslatorIT    : The following 1 profile is active: "testdev"
2024-01-19T17:55:54.060+01:00  INFO 34528 --- [marlin-agent] [           main] c.s.r.a.m.w.r.e.ExceptionTranslatorIT    : Started ExceptionTranslatorIT in 2.103 seconds (process running for 80.887)
2024-01-19T17:55:54.082+01:00  WARN 34528 --- [marlin-agent] [           main] o.s.w.s.h.HandlerMappingIntrospector     : Cache miss for REQUEST dispatch to '/api/exception-translator-test/missing-servlet-request-part' (previous null). Performing MatchableHandlerMapping lookup. This is logged once only at WARN level, and every time at TRACE.
2024-01-19T17:55:54.162+01:00  WARN 34528 --- [marlin-agent] [           main] o.s.web.servlet.PageNotFound             : Request method 'POST' is not supported
[INFO] Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.465 s -- in com.stukans.refirmware.agent.marlin.web.rest.errors.ExceptionTranslatorIT
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   MarlinAgentKafkaResourceIT.producesMessages:46 Status expected:<200> but was:<403>
[INFO]
[ERROR] Tests run: 23, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.11:report-integration (post-integration-tests) @ marlin-agent ---
[INFO] Loading execution data file E:\Projects\JHipster\refirmware\test\target\jacoco-it.exec
[INFO] Analyzed bundle 'Marlin Agent' with 32 classes
[INFO]
[INFO] --- maven-checkstyle-plugin:3.3.1:check (default) @ marlin-agent ---
[INFO] You have 0 Checkstyle violations.
[INFO]
[INFO] --- maven-failsafe-plugin:3.2.2:verify (verify) @ marlin-agent ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:00 min
[INFO] Finished at: 2024-01-19T17:55:56+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:3.2.2:verify (verify) on project marlin-agent: There are test failures.
[ERROR]
[ERROR] Please refer to E:\Projects\JHipster\refirmware\test\target\failsafe-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Motivation for or Use Case

A newly created project should not have failing tests.

Reproduce the error

create a project with the provided .yo-rc.json and run mvn clean install command

Related issues

Yes, I had a similar issue in the past with an older version of JHipster, but that bug was not solved.

Suggest a Fix
JHipster Version(s)

8.1.0

JHipster configuration
PS E:\Projects\JHipster\refirmware\test> jhipster info

        ██╗ ██╗   ██╗ ████████╗ ███████╗   ██████╗ ████████╗ ████████╗ ███████╗
        ██║ ██║   ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
        ██║ ████████║    ██║    ███████╔╝ ╚█████╗     ██║    ██████╗   ███████╔╝
  ██╗   ██║ ██╔═══██║    ██║    ██╔════╝   ╚═══██╗    ██║    ██╔═══╝   ██╔══██║
  ╚██████╔╝ ██║   ██║ ████████╗ ██║       ██████╔╝    ██║    ████████╗ ██║  ╚██╗
   ╚═════╝  ╚═╝   ╚═╝ ╚═══════╝ ╚═╝       ╚═════╝     ╚═╝    ╚═══════╝ ╚═╝   ╚═╝
                            https://www.jhipster.tech
Welcome to JHipster v8.1.0

Welcome to the JHipster Information Sub-Generator


marlin-agent@0.0.0 E:\Projects\JHipster\refirmware\test
`-- generator-jhipster@8.1.0



##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder**


<details>
<summary>.yo-rc.json file</summary>
<pre>
{
  "generator-jhipster": {
    "applicationType": "monolith",
    "authenticationType": "oauth2",
    "baseName": "marlin-agent",
    "buildTool": "maven",
    "cacheProvider": "no",
    "creationTimestamp": 1705655658027,
    "databaseType": "no",
    "devDatabaseType": "no",
    "enableGradleEnterprise": null,
    "enableHibernateCache": false,
    "enableSwaggerCodegen": false,
    "enableTranslation": false,
    "entities": [],
    "feignClient": false,
    "gradleEnterpriseHost": null,
    "jhipsterVersion": "8.1.0",
    "messageBroker": "kafka",
    "monorepository": true,
    "nativeLanguage": "en",
    "packageName": "com.stukans.refirmware.agent.marlin",
    "prodDatabaseType": "no",
    "reactive": false,
    "searchEngine": false,
    "serverPort": null,
    "serverSideOptions": [
      "messageBroker:kafka"
    ],
    "serviceDiscoveryType": false,
    "skipClient": true,
    "skipCommitHook": true,
    "skipUserManagement": true,
    "testFrameworks": [],
    "websocket": false
  }
}
</pre>
</details>


##### **Environment and Tools**

java version "17.0.3.1" 2022-04-22 LTS
Java(TM) SE Runtime Environment (build 17.0.3.1+2-LTS-6)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.3.1+2-LTS-6, mixed mode, sharing)

git version 2.40.1.windows.1

node: v20.11.0
npm: 10.2.4

Docker version 24.0.6, build ed223bc

##### **JDL for the Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**

<details>
<summary>JDL entity definitions</summary>

<pre>

</pre>
</details>

[
.yo-rc.json
](url)

Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System

Windows 10 PRO [Version 10.0.19045 Build 19045]
Chrome Version 120.0.6099.225 (Official Build) (64-bit)

  • [ X] Checking this box is mandatory (this is just to show you read everything)
Copy link
Contributor

github-actions bot commented Jan 20, 2024

JHipster has completed the sample check
.yo-rc.json: valid
Entities JDL: blank
Application: successfully generated
Frontend check: success
Backend check: failure
E2E check: success

This check uses jhipster info output from the issue description to generate the sample.
Bug report that does not contain this information will be marked as invalid.

@artyomsv
Copy link
Contributor Author

changing the test with .with(csrf()) fixed the issue:

    @Test
    void producesMessages() throws Exception {
        restMockMvc.perform(post("/api/marlin-agent-kafka/publish?message=value-produce").with(csrf())).andExpect(status().isOk());
        assertThat(output.receive(1000, "binding-out-0").getPayload()).isEqualTo("value-produce".getBytes());
    }

@atomfrede
Copy link
Member

Thanks for analysing! Can you do a PR to fix it?

@artyomsv
Copy link
Contributor Author

Thanks for analysing! Can you do a PR to fix it?

Sure, I can try to do that.

artyomsv pushed a commit to artyomsv/generator-jhipster that referenced this issue Jan 21, 2024
fix missing csfr in the Kafka integration test

Fix jhipster#24912
artyomsv added a commit to artyomsv/generator-jhipster that referenced this issue Jan 21, 2024
fix missing csfr in the Kafka integration test

Fix jhipster#24912
@deepu105 deepu105 added this to the 8.2.0 milestone Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants