-
Notifications
You must be signed in to change notification settings - Fork 6
Test/karate integration test #159
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
Draft
mfd2007
wants to merge
17
commits into
main
Choose a base branch
from
test/karate_integration_test
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.
Draft
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c21490f
Add Karate framework and some integration tests
mfd2007 7897c8c
style: fix whitespace
mfd2007 e2a2ab9
Merge branch 'main' into test/karate_integration_test
mfd2007 66749fc
Add test case for local integration tests.
mfd2007 497008c
Merge branch 'main' into test/karate_integration_test
mfd2007 23ea07f
Move feature files to ressources
mfd2007 ba20876
Update documetation
mfd2007 ba3dbd3
docs: Fix typo
mfd2007 4fe7c6b
fix: Wrong test title
mfd2007 39c7412
test: Improve test data
mfd2007 e4634bf
test: Improve test data
mfd2007 1556a14
fix: Wrong test title
mfd2007 2f18434
style: Fix wrong intents
mfd2007 dd973c0
chore: Update github actions
mfd2007 77e13e3
Merge remote-tracking branch 'origin/main' into
mfd2007 fc7c8ed
chore: add karate to dependecies
mfd2007 17747c4
Merge remote-tracking branch 'origin/chore/update_github-action_uploa…
mfd2007 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
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
22 changes: 22 additions & 0 deletions
22
src/test/java/de/bsi/secvisogram/csaf_cms_backend/integration/KarateRunner.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,22 @@ | ||
| package de.bsi.secvisogram.csaf_cms_backend.integration; | ||
|
|
||
| import com.intuit.karate.junit5.Karate; | ||
|
|
||
|
|
||
| public class KarateRunner { | ||
| @Karate.Test | ||
| Karate testExport() { | ||
| String[] testCases = new String[] { | ||
| "classpath:de/bsi/secvisogram/csaf_cms_backend/integration/export.feature" | ||
| }; | ||
| return Karate.run(testCases); | ||
| } | ||
|
|
||
| @Karate.Test | ||
| Karate testFullWorkflow() { | ||
| String[] testCases = new String[] { | ||
| "classpath:de/bsi/secvisogram/csaf_cms_backend/integration/fullworkflow.feature" | ||
| }; | ||
| return Karate.run(testCases); | ||
| } | ||
| } |
90 changes: 90 additions & 0 deletions
90
src/test/resources/de/bsi/secvisogram/csaf_cms_backend/integration/export.feature
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,90 @@ | ||
| Feature: Test export of documents | ||
|
|
||
| Background: | ||
| * def authUrl = 'http://localhost:9000' | ||
| * def loginPath = '/realms/csaf/protocol/openid-connect/token' | ||
| * def logoutPath = '/realms/csaf/protocol/openid-connect/logout' | ||
|
|
||
| * def restUrl = 'http://localhost:8081' | ||
| * def apiBase = '/api/v1/advisories' | ||
|
|
||
| * def username = 'all' | ||
| * def password = 'all' | ||
|
|
||
| Scenario: Export all formats and store response in folder ./target/ | ||
| The first document in the list will be exported in all available | ||
| formats. | ||
|
|
||
| # Login | ||
| Given url 'http://localhost:9000/realms/csaf/protocol/openid-connect/token' | ||
| * form field client_id = 'secvisogram' | ||
| * form field username = 'all' | ||
| * form field password = 'all' | ||
| * form field grant_type = 'password' | ||
| * form field response_type = 'code' | ||
| * form field audience = 'secvisogram' | ||
| * form field requested_token_type = 'ID' | ||
| When method post | ||
| Then status 200 | ||
| * def accessToken = response.access_token | ||
| * def refreshToken = response.refresh_token | ||
| * def session = response.session_state | ||
|
|
||
| #Get advisory list and store first advisory id | ||
| Given url 'http://localhost:8081' | ||
| * path apiBase | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| When method get | ||
| Then status 200 | ||
| * def advisoryId = response[0].advisoryId | ||
|
|
||
| # Download advisory as JSON | ||
| * def format = 'JSON' | ||
| Given path apiBase + '/' + advisoryId + '/csaf' | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| * param format = format | ||
| When method get | ||
| Then status 200 | ||
| * karate.write(response, 'advisory.json') | ||
|
|
||
| # Download advisory as HTML | ||
| * def format = 'HTML' | ||
| Given path apiBase + '/' + advisoryId + '/csaf' | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| * param format = format | ||
| When method get | ||
| Then status 200 | ||
| * karate.write(response, 'advisory.html') | ||
|
|
||
| # Download advisory as PDF | ||
| * def format = 'PDF' | ||
| Given path apiBase + '/' + advisoryId + '/csaf' | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| * param format = format | ||
| When method get | ||
| Then status 200 | ||
| * karate.write(response, 'advisory.pdf') | ||
|
|
||
| # Download advisory as Markdown | ||
| * def format = 'Markdown' | ||
| Given path apiBase + '/' + advisoryId + '/csaf' | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| * param format = format | ||
| When method get | ||
| Then status 200 | ||
| * karate.write(response, 'advisory.md') | ||
|
|
||
| # Logout | ||
| Given url 'http://localhost:9000/realms/csaf/protocol/openid-connect/logout' | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/x-www-form-urlencoded' | ||
| * form field refresh_token = refreshToken | ||
| * form field client_id = 'secvisogram' | ||
| When method post | ||
| * status 204 | ||
|
|
128 changes: 128 additions & 0 deletions
128
src/test/resources/de/bsi/secvisogram/csaf_cms_backend/integration/fullworkflow.feature
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,128 @@ | ||
| Feature: Hello World | ||
|
mfd2007 marked this conversation as resolved.
Outdated
|
||
|
|
||
| Background: | ||
| * url 'http://localhost:8081' | ||
| * def apiBase = '/api/v1/advisories' | ||
|
|
||
| Scenario: oauth 2 flow | ||
| # Login | ||
| Given url 'http://localhost:9000/realms/csaf/protocol/openid-connect/token' | ||
| * form field client_id = 'secvisogram' | ||
| * form field username = 'all' | ||
| * form field password = 'all' | ||
| * form field grant_type = 'password' | ||
| * form field response_type = 'code' | ||
| * form field audience = 'secvisogram' | ||
| * form field requested_token_type = 'ID' | ||
| When method post | ||
| Then status 200 | ||
| * def accessToken = response.access_token | ||
| * def refreshToken = response.refresh_token | ||
| * def session = response.session_state | ||
|
|
||
| ######## | ||
| #Upload | ||
| Given url 'http://localhost:8081' | ||
| * path apiBase | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| * request read('min.json') | ||
| When method post | ||
| Then status 201 | ||
| * def advisoryId = response.id | ||
| * def revision = response.revision | ||
|
|
||
| ######## | ||
| #Change workflow state to Review | ||
| # | ||
| # Draft, Review, Approved, RfPublication, Published | ||
| * def workflowStatus = 'Review' | ||
| Given path apiBase + '/' + advisoryId + '/workflowstate/' + workflowStatus | ||
| * param revision = revision | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| When method patch | ||
| Then status 200 | ||
|
|
||
| # Get new revision after workflow state change | ||
| Given path apiBase | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| When method get | ||
| Then status 200 | ||
| * def filt = function(x){ return x.advisoryId == advisoryId } | ||
| * def items = get response[*] | ||
| * def revision = karate.filter(items, filt)[0].revision | ||
|
mfd2007 marked this conversation as resolved.
Outdated
|
||
|
|
||
| ######## | ||
| #Change workflow state to Approved | ||
| # | ||
| * def workflowStatus = 'Approved' | ||
| Given path apiBase + '/' + advisoryId + '/workflowstate/' + workflowStatus | ||
| * param revision = revision | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| When method patch | ||
| Then status 200 | ||
| # Get new revision after workflow state change | ||
| Given path apiBase | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| When method get | ||
| Then status 200 | ||
| * def filt = function(x){ return x.advisoryId == advisoryId } | ||
| * def items = get response[*] | ||
| * def revision = karate.filter(items, filt)[0].revision | ||
|
|
||
| ######## | ||
| #Change workflow state to RfPublication | ||
| # | ||
| * def workflowStatus = 'RfPublication' | ||
| Given path apiBase + '/' + advisoryId + '/workflowstate/' + workflowStatus | ||
| * param revision = revision | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| When method patch | ||
| Then status 200 | ||
| # Get new revision after workflow state change | ||
| Given path apiBase | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| When method get | ||
| Then status 200 | ||
| * def filt = function(x){ return x.advisoryId == advisoryId } | ||
| * def items = get response[*] | ||
| * def revision = karate.filter(items, filt)[0].revision | ||
|
|
||
| ######## | ||
| #Change workflow state to Published | ||
| # | ||
| * def workflowStatus = 'Published' | ||
| Given path apiBase + '/' + advisoryId + '/workflowstate/' + workflowStatus | ||
| * param revision = revision | ||
| # final, interim, draft | ||
| * param documentTrackingStatus = 'Final' | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| When method patch | ||
| Then status 200 | ||
|
|
||
| # Get new revision after workflow state change | ||
| Given path apiBase | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/json' | ||
| When method get | ||
| Then status 200 | ||
| * def filt = function(x){ return x.advisoryId == advisoryId } | ||
| * def items = get response[*] | ||
| * def revision = karate.filter(items, filt)[0].revision | ||
|
mfd2007 marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Logout | ||
| Given url 'http://localhost:9000/realms/csaf/protocol/openid-connect/logout' | ||
| * header Authorization = 'Bearer ' + accessToken | ||
| * header Content-Type = 'application/x-www-form-urlencoded' | ||
| * form field refresh_token = refreshToken | ||
| * form field client_id = 'secvisogram' | ||
| When method post | ||
| * status 204 | ||
|
|
||
38 changes: 38 additions & 0 deletions
38
src/test/resources/de/bsi/secvisogram/csaf_cms_backend/integration/min.json
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,38 @@ | ||
| { | ||
| "csaf": { | ||
| "document": { | ||
| "category": "csaf_base", | ||
| "csaf_version": "2.0", | ||
| "publisher": { | ||
| "category": "other", | ||
| "name": "1", | ||
| "namespace": "h:2" | ||
|
mfd2007 marked this conversation as resolved.
Outdated
|
||
| }, | ||
| "title": "title", | ||
| "tracking": { | ||
| "current_release_date": "2023-07-12T10:00:00.000Z", | ||
| "generator": { | ||
| "date": "2023-07-12T07:53:29.378Z", | ||
| "engine": { | ||
| "name": "Secvisogram", | ||
| "version": "2.2.5" | ||
| } | ||
| }, | ||
| "id": "document-id", | ||
| "initial_release_date": "2023-07-12T10:00:00.000Z", | ||
| "revision_history": [ | ||
| { | ||
| "date": "2023-07-12T10:00:00.000Z", | ||
| "number": "1.0.0", | ||
| "summary": "summary" | ||
|
mfd2007 marked this conversation as resolved.
Outdated
|
||
| } | ||
| ], | ||
| "status": "final", | ||
| "version": "1.0.0" | ||
| } | ||
| } | ||
| }, | ||
| "summary": "-", | ||
| "legacyVersion": "" | ||
| } | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.