-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SonarSource-Demos:main' into main
- Loading branch information
Showing
9 changed files
with
191 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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,55 @@ | ||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven | ||
|
||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
name: SonarQube Analyze | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Cache SonarQube packages | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.sonar/cache | ||
key: ${{ runner.os }}-sonar | ||
restore-keys: ${{ runner.os }}-sonar | ||
- name: Cache Maven packages | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.m2 | ||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | ||
restore-keys: ${{ runner.os }}-m2 | ||
- name: Build with Maven and analyze with SonarQube | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} | ||
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=demo:java-security | ||
#run: mvn -B package --file pom.xml | ||
|
||
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive | ||
#- name: Update dependency graph | ||
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 |
This file contains 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 |
---|---|---|
|
@@ -26,3 +26,4 @@ hs_err_pid* | |
#IDEs | ||
.idea/ | ||
.vscode/ | ||
java-security.iml |
This file contains 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 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,2 @@ | ||
keyId=AKIA6HMXNBHDXXNYUMIX | ||
aws_secret_access_key=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 |
This file contains 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 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 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,14 @@ | ||
package demo.security.util; | ||
import java.io.Serializable; | ||
public class SessionHeader implements Serializable { | ||
private String username; | ||
private String sessionId; | ||
public SessionHeader(String username, String sessionId) { | ||
this.username = username; | ||
this.sessionId = sessionId; | ||
} | ||
public String getUsername() { return this.username; } | ||
public void setUsername(String username) { this.username = username; } | ||
public String getSessionId() { return this.sessionId; } | ||
public void setSessionId(String sessionId) { this.sessionId = sessionId; } | ||
} |
This file contains 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 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,34 @@ | ||
import demo.security.util.WebUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class WebUtilsTest { | ||
|
||
@Test | ||
public void getSessionId_withValidRequest() { | ||
HttpServletRequest request = Mockito.mock(HttpServletRequest.class); | ||
when(request.getRequestedSessionId()).thenReturn("validSessionId"); | ||
|
||
WebUtils.getSessionId(request); | ||
} | ||
|
||
@Test | ||
public void getSessionId_withNullSessionId() { | ||
HttpServletRequest request = Mockito.mock(HttpServletRequest.class); | ||
when(request.getRequestedSessionId()).thenReturn(null); | ||
|
||
WebUtils.getSessionId(request); | ||
} | ||
|
||
@Test | ||
public void getSessionId_withIOException() { | ||
HttpServletRequest request = Mockito.mock(HttpServletRequest.class); | ||
when(request.getRequestedSessionId()).thenThrow(new RuntimeException()); | ||
|
||
assertThrows(RuntimeException.class, () -> WebUtils.getSessionId(request)); | ||
} | ||
} |