Skip to content

Commit

Permalink
Merge pull request #47 from pagopa/SLS-16
Browse files Browse the repository at this point in the history
[SLS-16] Configured docker compose - mock clients - e2e tests
  • Loading branch information
alessio-cialini authored Apr 28, 2023
2 parents 81e111d + 7870cad commit 2498fa7
Show file tree
Hide file tree
Showing 24 changed files with 4,625 additions and 236 deletions.
Empty file added .env
Empty file.
5 changes: 5 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ASSERTION_CLIENT_MOCK_ENABLED = true
IDP_CLIENT_MOCK_ENABLED = true
IDP_CLIENT_BASE_URI = "http://localhost:3001"
LOLLIPOP_ASSERTION_NOT_BEFORE_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"
LOLLIPOP_ASSERTION_INSTANT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"
140 changes: 76 additions & 64 deletions .github/workflows/pr_scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,79 @@ jobs:
pull-requests: write

steps:
- name: Checkout project sources
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3
with:
fetch-depth: 0
- name: Setup Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar-project.properties/cache
key: ${{ runner.os }}-sonar-project.properties
restore-keys: ${{ runner.os }}-sonar-project.properties
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Run build with Gradle Wrapper
run: ./gradlew build testCodeCoverageReport
- name: Add coverage to PR
id: jacoco
uses: madrapps/jacoco-report@7a334255fbce42f385d7567c25d986a9c62e2971
with:
paths: ${{ github.workspace }}/test-coverage/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 40
min-coverage-changed-files: 60
- name: Build the Docker image
run: docker build . --file ${{ env.DOCKERFILE }} --tag localbuild/testimage:latest
- name: Run the Anchore Grype scan action
uses: anchore/scan-action@d5aa5b6cb9414b0c7771438046ff5bcfa2854ed7
id: scan
with:
image: "localbuild/testimage:latest"
fail-build: true
severity-cutoff: "high"
- name: Upload Anchore Scan Report
uses: github/codeql-action/upload-sarif@9885f86fab4879632b7e44514f19148225dfbdcd
if: always()
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
- name: Run Sonar Scanner on Pull Request
if: ${{ github.event_name == 'pull_request' }}
run: ./gradlew sonar --info
-Dsonar.organization=pagopa
-Dsonar.projectKey=${{ env.PROJECT_KEY }}
-Dsonar.coverage.jacoco.xmlReportPaths=**/test-coverage/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml
-Dsonar.coverage.exclusions="**/config/*","**/*Mock*","**/model/**","**/entity/*","**/*Stub*","**/*Config*,**/*Exception*"
-Dsonar.cpd.exclusions="**/model/**,**/entity/**,**/simple/internal/**"
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.java.libraries="**/*.jar"
-Dsonar.login=${{ env.SONAR_TOKEN }}
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
-Dsonar.pullrequest.branch=${{ github.head_ref }}
-Dsonar.pullrequest.base=${{ github.base_ref }}
- name: Run Sonar Scanner
if: ${{ github.event_name != 'pull_request' }}
run: ./gradlew sonar --info
-Dsonar.organization=pagopa
-Dsonar.projectKey=${{ env.PROJECT_KEY }}
-Dsonar.coverage.jacoco.xmlReportPaths=**/test-coverage/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml
-Dsonar.coverage.exclusions="**/config/*","**/*Mock*","**/model/**","**/entity/*","**/*Stub*","**/*Config*,**/*Exception*"
-Dsonar.cpd.exclusions="**/model/**,**/entity/**,**/simple/internal/**"
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.java.libraries="**/*.jar"
-Dsonar.login=${{ env.SONAR_TOKEN }}
-Dsonar.branch.name=${{ github.head_ref }}
- name: Checkout project sources
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3
with:
fetch-depth: 0
- name: Setup Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar-project.properties/cache
key: ${{ runner.os }}-sonar-project.properties
restore-keys: ${{ runner.os }}-sonar-project.properties
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Run build with Gradle Wrapper
run: ./gradlew build testCodeCoverageReport
- name: Add coverage to PR
id: jacoco
uses: madrapps/jacoco-report@7a334255fbce42f385d7567c25d986a9c62e2971
with:
paths: ${{ github.workspace }}/test-coverage/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 40
min-coverage-changed-files: 60
- name: Build the Docker image
run: docker build . --file ${{ env.DOCKERFILE }} --tag localbuild/testimage:latest
- name: Run the Anchore Grype scan action
uses: anchore/scan-action@d5aa5b6cb9414b0c7771438046ff5bcfa2854ed7
id: scan
with:
image: "localbuild/testimage:latest"
fail-build: true
severity-cutoff: "high"
- name: Upload Anchore Scan Report
uses: github/codeql-action/upload-sarif@9885f86fab4879632b7e44514f19148225dfbdcd
if: always()
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
- name: Run Sonar Scanner on Pull Request
if: ${{ github.event_name == 'pull_request' }}
run: ./gradlew sonar --info
-Dsonar.organization=pagopa
-Dsonar.projectKey=${{ env.PROJECT_KEY }}
-Dsonar.coverage.jacoco.xmlReportPaths=**/test-coverage/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml
-Dsonar.coverage.exclusions="**/config/*","**/*Mock*","**/model/**","**/entity/*","**/*Stub*","**/*Config*,**/*Exception*"
-Dsonar.cpd.exclusions="**/model/**,**/entity/**,**/simple/internal/**"
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.java.libraries="**/*.jar"
-Dsonar.login=${{ env.SONAR_TOKEN }}
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
-Dsonar.pullrequest.branch=${{ github.head_ref }}
-Dsonar.pullrequest.base=${{ github.base_ref }}
- name: Run Sonar Scanner
if: ${{ github.event_name != 'pull_request' }}
run: ./gradlew sonar --info
-Dsonar.organization=pagopa
-Dsonar.projectKey=${{ env.PROJECT_KEY }}
-Dsonar.coverage.jacoco.xmlReportPaths=**/test-coverage/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml
-Dsonar.coverage.exclusions="**/config/*","**/*Mock*","**/model/**","**/entity/*","**/*Stub*","**/*Config*,**/*Exception*"
-Dsonar.cpd.exclusions="**/model/**,**/entity/**,**/simple/internal/**"
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.java.libraries="**/*.jar"
-Dsonar.login=${{ env.SONAR_TOKEN }}
-Dsonar.branch.name=${{ github.head_ref }}
- name: Publish to Maven Local
run: ./gradlew publishToMavenLocal
- name: Build Spring Sample
working-directory: ./samples/spring
run: chmod +x ./gradlew && ./gradlew bootJar
- name: Run Docker compose with .env.dev
run: docker compose --env-file .env.dev up -d --build
- name: Install node modules and execute e2e tests
working-directory: ./e2e
run: npm install && npm run execute-test
- name: Shutdown docker compose
run: docker compose down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@

# Ignore Gradle build output directory
build

# Ignore newman node modules and test reports
e2e/newman
e2e/node_modules
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ FROM eclipse-temurin:11-jdk-alpine as runtime

WORKDIR /app
COPY --from=build /build/build/libs/*.jar /app/app.jar
COPY --from=build /build/build/resources/main/application.properties /app/application.properties

RUN addgroup -S appuser && adduser -S appuser -G appuser
USER appuser

EXPOSE 8080
ENTRYPOINT [ "java","-jar","/app/app.jar" ]
ENTRYPOINT [ "java","-jar","/app/app.jar", "/app/application.properties" ]
1 change: 0 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ dependencies {
implementation 'ch.qos.logback:logback-classic:1.4.6'
implementation 'ch.qos.logback:logback-core:1.4.6'
implementation 'org.codehaus.janino:janino:3.1.9'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'
implementation 'org.apache.wss4j:wss4j-ws-security-common:2.4.1'

implementation 'javax.servlet:javax.servlet-api:3.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public static HttpServletResponse interceptResult(
CommandResult commandResult, HttpServletResponse httpResponse) throws IOException {

if (!commandResult.getResultCode().equals(VERIFICATION_SUCCESS_CODE)) {
httpResponse.sendError(401, commandResult.getResultMessage());
httpResponse.setStatus(401);
httpResponse.getWriter().write(commandResult.getResultMessage());
}

return httpResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void convertUnauthorizedResponse() throws IOException {
LollipopConsumerConverter.interceptResult(result, mockResponse);

Assertions.assertEquals(401, response.getStatus());
Assertions.assertSame(
COMMAND_RESPONSE_FAILED, ((MockHttpServletResponse) response).getErrorMessage());
Assertions.assertEquals(
COMMAND_RESPONSE_FAILED, ((MockHttpServletResponse) response).getContentAsString());
}
}
37 changes: 37 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: "3.9"
services:
web:
build: .
ports:
- "8080:8080"
environment:
##Client mocks config
ASSERTION_CLIENT_MOCK_ENABLED: ${ASSERTION_CLIENT_MOCK_ENABLED}
IDP_CLIENT_MOCK_ENABLED: ${IDP_CLIENT_MOCK_ENABLED}

##General Lollipop Configs Sample
LOLLIPOP_ASSERTION_EXPIRE_IN_DAYS: ${LOLLIPOP_ASSERTION_EXPIRE_IN_DAYS:-180}
LOLLIPOP_EXPECTED_LC_ORIGINAL_URL: ${LOLLIPOP_EXPECTED_LC_ORIGINAL_URL:-https://api-app.io.pagopa.it/first-lollipop/sign}
LOLLIPOP_EXPECTED_LC_ORIGINAL_METHOD: ${LOLLIPOP_EXPECTED_LC_ORIGINAL_METHOD:-POST}
LOLLIPOP_ASSERTION_NOT_BEFORE_DATE_FORMAT: ${LOLLIPOP_ASSERTION_NOT_BEFORE_DATE_FORMAT:-yyyy-MM-dd'T'HH:mm:ss.SSS'Z'}
LOLLIPOP_ASSERTION_INSTANT_DATE_FORMAT: ${LOLLIPOP_ASSERTION_INSTANT_DATE_FORMAT:-yyyy-MM-dd'T'HH:mm:ss.SSS'Z'}

###Idp Client Configs
IDP_CLIENT_CIEID: ${IDP_CLIENT_CIEID:-https://idserver.servizicie.interno.gov.it/idp/profile/SAML2/POST/SSO}
IDP_CLIENT_BASE_URI: ${IDP_CLIENT_BASE_URI:-https://api.is.eng.pagopa.it}
IDP_CLIENT_CIE_ENDPOINT: ${IDP_CLIENT_CIE_ENDPOINT:-/idp-keys/cie}
IDP_CLIENT_SPID_ENDPOINT: ${IDP_CLIENT_SPID_ENDPOINT:-/idp-keys/spid}

###Idp Storage Configs
IDP_STORAGE_ENABLED: ${IDP_STORAGE_ENABLED:-true}
IDP_STORAGE_EVICTION_DELAY: ${IDP_STORAGE_EVICTION_DELAY:-1}

##Assertion Client Configs
ASSERTION_REST_URI: ${ASSERTION_REST_URI:-http://localhost:3000}
ASSERTION_REST_ENDPOINT: ${ASSERTION_REST_ENDPOINT:-/assertions}

##Assertion Storage Configs
ASSERTION_STORAGE_ENABLED: ${ASSERTION_STORAGE_ENABLED:-true}
ASSERTION_STORAGE_EVICTION_DELAY: ${ASSERTION_STORAGE_EVICTION_DELAY:-1}


18 changes: 18 additions & 0 deletions e2e/automatic-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const newman = require('newman');

newman.run({
collection: require('./collections/LollipopSDKTest.postman_collection.json'),
environment: './env/Lollipop environment variables.postman_environment.json',
reporters: ['cli', 'htmlextra'],
bail: true
}, function (err, summary) {
if (err) { throw err; }
if(summary?.run?.error){ throw 'collection run encountered an error.';}

if(summary?.run?.failures?.length > 0){
const errors = summary.run.failures;
throw `following collection tests failed: ${errors.map((er) => `\n${er.source.name}`)}`;
}

console.info('collection run completed.');
});
Loading

0 comments on commit 2498fa7

Please sign in to comment.