-
Notifications
You must be signed in to change notification settings - Fork 0
New test workflow #135
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
Open
driedpampas
wants to merge
8
commits into
main
Choose a base branch
from
new-test-workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New test workflow #135
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
df06ec5
Update SecurityConfig.java
driedpampas d4603b4
feat: implement JWT authentication for WebSocket connections and add …
driedpampas 3b7625f
refactor: simplify exception handling and improve type inference in S…
driedpampas 3756b60
feat: enhance JWT authentication handling for WebSocket connections a…
driedpampas 1b572ce
refactor: remove WebSocket path exclusion from JwtAuthFilter and enha…
driedpampas 4b3a4ae
refactor: remove unused tests from JwtAuthFilterTest and improve exce…
driedpampas 814ea6f
index on fix/routes-without-authentication: 4b3a4ae refactor: remove …
driedpampas 87f2f13
On fix/routes-without-authentication: new workflow
driedpampas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| POSTGRES_DB=p2p_shopping | ||
| POSTGRES_USER=postgres | ||
| POSTGRES_PASSWORD=postgres | ||
| MONGO_DB=p2p_shopping_mongo | ||
| JWT_SECRET=your-secret-key-here-at-least-32-characters-long |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| name: Tests | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - develop | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Run Tests | ||
| runs-on: ubuntu-latest | ||
|
|
||
| services: | ||
| postgres: | ||
| image: postgis/postgis:16-3.4 | ||
| env: | ||
| POSTGRES_DB: p2p_shopping_test | ||
| POSTGRES_USER: postgres | ||
| POSTGRES_PASSWORD: postgres | ||
| ports: | ||
| - 5432:5432 | ||
| options: >- | ||
| --health-cmd "pg_isready -U postgres -d p2p_shopping_test" | ||
| --health-interval 10s | ||
| --health-timeout 5s | ||
| --health-retries 5 | ||
|
|
||
| mongodb: | ||
| image: mongo:7 | ||
| env: | ||
| MONGO_INITDB_DATABASE: p2p_shopping_test | ||
| ports: | ||
| - 27017:27017 | ||
| options: >- | ||
| --health-cmd "mongosh --eval 'db.adminCommand(\"ping\")'" | ||
| --health-interval 10s | ||
| --health-timeout 5s | ||
| --health-retries 5 | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up JDK 21 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: 21 | ||
| distribution: 'temurin' | ||
|
|
||
| - name: Cache Gradle packages | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.gradle/caches | ||
| ~/.gradle/wrapper | ||
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
| restore-keys: ${{ runner.os }}-gradle- | ||
|
|
||
| - name: Grant execute permission for gradlew | ||
| run: chmod +x gradlew | ||
|
|
||
| - name: Run tests | ||
| env: | ||
| SPRING_DATA_MONGODB_URI: mongodb://localhost:27017/p2p_shopping_test | ||
| run: ./gradlew test --info | ||
|
|
||
| - name: Upload test reports | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: test-reports | ||
| path: build/reports/tests/ | ||
| retention-days: 7 | ||
|
|
||
| - name: Upload coverage report | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: coverage-reports | ||
| path: build/reports/jacoco/ | ||
| retention-days: 7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/com/p2ps/config/JwtHandshakeInterceptor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.p2ps.config; | ||
|
|
||
| import com.p2ps.auth.security.JwtAuthFilter; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.server.ServerHttpRequest; | ||
| import org.springframework.http.server.ServerHttpResponse; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.web.socket.WebSocketHandler; | ||
| import org.springframework.web.socket.server.HandshakeInterceptor; | ||
| import org.springframework.web.util.UriComponentsBuilder; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @Component | ||
| public class JwtHandshakeInterceptor implements HandshakeInterceptor { | ||
|
|
||
| public static final String SESSION_TOKEN_ATTRIBUTE = "wsJwtToken"; | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(JwtHandshakeInterceptor.class); | ||
|
|
||
| private final JwtAuthFilter jwtAuthFilter; | ||
| private final boolean enableUrlToken; | ||
|
|
||
| public JwtHandshakeInterceptor(JwtAuthFilter jwtAuthFilter, | ||
| @Value("${websocket.compatibility.enableUrlToken:false}") boolean enableUrlToken) { | ||
| this.jwtAuthFilter = jwtAuthFilter; | ||
| this.enableUrlToken = enableUrlToken; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, | ||
| Map<String, Object> attributes) { | ||
| if (!enableUrlToken) { | ||
| return true; | ||
| } | ||
|
|
||
| String token = UriComponentsBuilder.fromUri(request.getURI()) | ||
| .build() | ||
| .getQueryParams() | ||
| .getFirst("token"); | ||
|
|
||
| if (token == null || token.isBlank()) { | ||
| return true; | ||
| } | ||
|
|
||
| if (jwtAuthFilter.authenticateToken(token) == null) { | ||
| logger.warn("Rejecting websocket handshake with invalid JWT query token"); | ||
| response.setStatusCode(HttpStatus.UNAUTHORIZED); | ||
| return false; | ||
| } | ||
|
|
||
| attributes.put(SESSION_TOKEN_ATTRIBUTE, token); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, | ||
| Exception exception) { | ||
| // No-op. | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: P2P-Shopping/server
Length of output: 148
Align CI JDK version with Gradle toolchain target.
CI workflow uses Java 21 (line 19) but
build.gradle.ktstargets Java 25 (line 15). Update the workflow to use Java 25 or update the Gradle toolchain to match Java 21 to maintain consistency and avoid build inconsistencies.🤖 Prompt for AI Agents