diff --git a/.github/ISSUE_TEMPLATE/01_bug.md b/.github/ISSUE_TEMPLATE/01_bug.md new file mode 100644 index 0000000..0c12e2d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/01_bug.md @@ -0,0 +1,43 @@ +--- +name: "\U0001F6A8 Bug" +about: Did you come across a bug or unexpected behaviour differing from the docs? +labels: bug +--- + + + +## Describe the bug + + + +## Expected behaviour + + + +## Steps to reproduce the issue + + + + + +## Technical details + +- Host Machine OS (Windows/Linux/Mac): + +## Possible Fix + + + +## Additional context + + diff --git a/.github/ISSUE_TEMPLATE/02_feature_request.md b/.github/ISSUE_TEMPLATE/02_feature_request.md new file mode 100644 index 0000000..ad11b6b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/02_feature_request.md @@ -0,0 +1,31 @@ +--- +name: "\U0001F381 Feature Request" +about: Do you have an idea for a new feature? +labels: feature request +--- + + + +## Feature description + + + +## Problem and motivation + + + +## Is this something you're interested in working on + + diff --git a/.github/ISSUE_TEMPLATE/03_enhancement.md b/.github/ISSUE_TEMPLATE/03_enhancement.md new file mode 100644 index 0000000..bbdc3b7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/03_enhancement.md @@ -0,0 +1,30 @@ +--- +name: "\u23F1\uFE0F Enhancement" +about: Do you have an idea for an enhancement? +labels: enhancement +--- + + + +## Current Implementation + + + +## Suggested Enhancement + + + +## Expected Benefits + + diff --git a/.github/ISSUE_TEMPLATE/04_question.md b/.github/ISSUE_TEMPLATE/04_question.md new file mode 100644 index 0000000..2be9b92 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/04_question.md @@ -0,0 +1,20 @@ +--- +name: "\U00002753 Question" +about: If you have questions about pieces of the code or documentation for this component, please post them here. +labels: question +--- + + + +## Your Question + + + +* Source File: +* Line(s): +* Question: diff --git a/.github/ISSUE_TEMPLATE/05_other.md b/.github/ISSUE_TEMPLATE/05_other.md new file mode 100644 index 0000000..102f771 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/05_other.md @@ -0,0 +1,12 @@ +--- +name: "\U0001F4AC Other" +about: For conceptual questions, please consider opening an issue in the documentation repository. +labels: other +--- + + diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..3ba13e0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: false diff --git a/.github/workflows/ci-dockerfile.yml b/.github/workflows/ci-dockerfile.yml new file mode 100644 index 0000000..cdf701e --- /dev/null +++ b/.github/workflows/ci-dockerfile.yml @@ -0,0 +1,21 @@ +name: ci-dockerfile +on: + push: + branches: + - master + paths: + - Dockerfile + pull_request: + types: + - opened + - synchronize + - reopened + paths: + - Dockerfile +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: docker pull hadolint/hadolint + - run: docker run --rm --interactive hadolint/hadolint < Dockerfile diff --git a/.github/workflows/ci-master.yml b/.github/workflows/ci-master.yml new file mode 100644 index 0000000..bf81a7d --- /dev/null +++ b/.github/workflows/ci-master.yml @@ -0,0 +1,51 @@ +name: ci-master +on: + push: + branches: + - master +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: environment + run: | + export VERSION=$(git rev-parse --short ${GITHUB_SHA}) + echo "VERSION=${VERSION}" >> $GITHUB_ENV + - name: docker build + run: | + docker build \ + --tag docker.pkg.github.com/${GITHUB_REPOSITORY}/cwa-log-upload:latest \ + --tag docker.pkg.github.com/${GITHUB_REPOSITORY}/cwa-log-upload:${VERSION} \ + --tag ${TRUSTED_URL}/${TRUSTED_REPOSITORY}/cwa-log-upload:${VERSION} \ + . + env: + TRUSTED_URL: ${{ secrets.TRUSTED_URL }} + TRUSTED_REPOSITORY: ${{ secrets.TRUSTED_REPOSITORY }} + - name: docker push github + run: | + echo ${GITHUB_TOKEN} | docker login docker.pkg.github.com -u ${GITHUB_REPOSITORY_OWNER} --password-stdin + docker push docker.pkg.github.com/${GITHUB_REPOSITORY}/cwa-log-upload:latest + docker push docker.pkg.github.com/${GITHUB_REPOSITORY}/cwa-log-upload:${VERSION} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: docker push trusted + run: | + echo ${TRUSTED_TOKEN} | docker login ${TRUSTED_URL} -u ${TRUSTED_USER} --password-stdin + export DOCKER_CONTENT_TRUST=1 + export DOCKER_CONTENT_TRUST_SERVER=${TRUSTED_SERVER_URL} + export DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE=${TRUSTED_TOKEN} + export DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE=${TRUSTED_TOKEN} + gpg --quiet --batch --yes --decrypt --passphrase=${TRUSTED_KEY} \ + --output trusted.key trusted.key.gpg + chmod 600 trusted.key + docker trust key load trusted.key --name user + docker trust sign ${TRUSTED_URL}/${TRUSTED_REPOSITORY}/cwa-log-upload:${VERSION} + docker push ${TRUSTED_URL}/${TRUSTED_REPOSITORY}/cwa-log-upload:${VERSION} + env: + TRUSTED_KEY: ${{ secrets.TRUSTED_KEY }} + TRUSTED_URL: ${{ secrets.TRUSTED_URL }} + TRUSTED_SERVER_URL: ${{ secrets.TRUSTED_SERVER_URL }} + TRUSTED_REPOSITORY: ${{ secrets.TRUSTED_REPOSITORY }} + TRUSTED_USER: ${{ secrets.TRUSTED_USER }} + TRUSTED_TOKEN: ${{ secrets.TRUSTED_TOKEN }} diff --git a/.github/workflows/ci-pull-request.yml b/.github/workflows/ci-pull-request.yml new file mode 100644 index 0000000..20c9113 --- /dev/null +++ b/.github/workflows/ci-pull-request.yml @@ -0,0 +1,14 @@ +name: ci-pull-request +on: + pull_request: + types: + - opened + - synchronize + - reopened +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: docker build + run: docker build . diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a3e3bd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code ### +.vscode/ + +build.sh +trusted.key diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..10a8e59 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,8 @@ +# This file provides an overview of code owners in this repository. + +# Each line is a file pattern followed by one or more owners. +# The last matching pattern has the most precedence. +# For more details, read the following article on GitHub: https://help.github.com/articles/about-codeowners/. + +# These are the default owners for the whole content of this repository. The default owners are automatically added as reviewers when you open a pull request, unless different owners are specified in the file. +* @alstiefel @dfischer-tech @f11h @jhagestedt @lstelzne-tech @mlaue-tech @mschulte-tsi @tence @kreincke @ascheibal @lbenthins @ChristianFirmenich @BugBuster1701 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..d8d1b36 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,105 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for +everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity +and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, +or sexual identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take +appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, +issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for +moderation decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing +the community in public spaces. Examples of representing our community include using an official e-mail address, posting +via an official social media account, or acting as an appointed representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible +for enforcement at +[cwa-opensource@telekom.de](mailto:cwa-opensource@telekom.de). All complaints will be reviewed and investigated promptly +and fairly. + +All community leaders are obligated to respect the privacy and security of the reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem +in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the +community. + +**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation +and an explanation of why the behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of actions. + +**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including +unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding +interactions in community spaces as well as external channels like social media. Violating these terms may lead to a +temporary or permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified +period of time. No public or private interaction with the people involved, including unsolicited interaction with those +enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate +behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired +by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e7f4378 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,97 @@ +# Contributing + +## Code of conduct + +All members of the project community must abide by the [Contributor Covenant, version 2.0](CODE_OF_CONDUCT.md). Only by +respecting each other can we develop a productive, collaborative community. Instances of abusive, harassing, or +otherwise unacceptable behavior may be reported by +contacting [cwa-opensource@telekom.de](mailto:cwa-opensource@telekom.de) and/or a project maintainer. + +We appreciate your courtesy of avoiding political questions here. Issues which are not related to the project itself +will be closed by our community managers. + +## Engaging in our project + +We use GitHub to manage reviews of pull requests. + +* If you are a new contributor, see: [Steps to Contribute](#steps-to-contribute) + +* If you have a trivial fix or improvement, go ahead and create a pull request, addressing (with `@...`) a suitable + maintainer of this repository (see [CODEOWNERS](CODEOWNERS) of the repository you want to contribute to) in the + description of the pull request. + +* If you plan to do something more involved, please reach out to us and send + an [email](mailto:cwa-opensource@telekom.de). This will avoid unnecessary work and surely give you and us a good deal + of inspiration. + +* Relevant coding style guidelines are available in the respective sub-repositories as they are programming + language-dependent. + +## Steps to Contribute + +Should you wish to work on an issue, please claim it first by commenting on the GitHub issue that you want to work on. +This is to prevent duplicated efforts from other contributors on the same issue. + +If you have questions about one of the issues, please comment on them, and one of the maintainers will clarify. + +We kindly ask you to follow the [Pull Request Checklist](#Pull-Request-Checklist) to ensure reviews can happen +accordingly. + +## Contributing Code + +You are welcome to contribute code in order to fix a bug or to implement a new feature. + +The following rule governs code contributions: + +* Contributions must be licensed under the [Apache 2.0 License](LICENSE) +* Newly created files must be opened by an instantiated version of the file 'templates/file-header.txt' +* At least if you add a new file to the repository, add your name into the contributor section of the file NOTICE ( + please respect the preset entry structure) + +## Contributing Documentation + +You are welcome to contribute documentation to the project. + +The following rule governs documentation contributions: + +* Contributions must be licensed under the same license as code, the [Apache 2.0 License](LICENSE) + +## Pull Request Checklist + +* Branch from the master branch and, if needed, rebase to the current master branch before submitting your pull request. + If it doesn't merge cleanly with master you may be asked to rebase your changes. + +* Commits should be as small as possible while ensuring that each commit is correct independently (i.e., each commit + should compile and pass tests). + +* Test your changes as thoroughly as possible before you commit them. Preferably, automate your test by unit/integration + tests. If tested manually, provide information about the test scope in the PR description (e.g. “Test passed: Upgrade + version from 0.42 to 0.42.23.”). + +* Create _Work In Progress [WIP]_ pull requests only if you need clarification or an explicit review before you can + continue your work item. + +* If your patch is not getting reviewed or you need a specific person to review it, you can @-reply a reviewer asking + for a review in the pull request or a comment, or you can ask for a review by contacting us + via [email](mailto:cwa-opensource@telekom.de). + +* Post review: + * If a review requires you to change your commit(s), please test the changes again. + * Amend the affected commit(s) and force push onto your branch. + * Set respective comments in your GitHub review to resolved. + * Create a general PR comment to notify the reviewers that your amendments are ready for another round of review. + +## Issues and Planning + +* We use GitHub issues to track bugs and enhancement requests. + +* Please provide as much context as possible when you open an issue. The information you provide must be comprehensive + enough to reproduce that issue for the assignee. Therefore, contributors may use but aren't restricted to the issue + template provided by the project maintainers. + +* When creating an issue, try using one of our issue templates which already contain some guidelines on which content is + expected to process the issue most efficiently. If no template applies, you can of course also create an issue from + scratch. + +* Please apply one or more applicable [labels](https://github.com/corona-warn-app/cwa-documentation/labels) to your + issue so that all community members are able to cluster the issues better. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4cf26c3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM maven:3-openjdk-11 as build + +COPY . . +RUN mvn clean install + + +FROM gcr.io/distroless/java-debian10:11 as run + +COPY --from=build ./target/*.jar /app.jar +#COPY scripts/Dpkg.java Dpkg.java +#RUN ["java", "Dpkg.java"] +USER 65534:65534 +CMD ["app.jar"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..23a0b69 --- /dev/null +++ b/NOTICE @@ -0,0 +1,17 @@ +Copyright (c) 2020 Deutsche Telekom AG. + +This project is licensed under Apache License, Version 2.0; +you may not use them except in compliance with the License. + +Contributors: +------------- + +Karsten Reincke [kreincke], Deutsche Telekom AG +Daniel Eder [daniel-eder], T-Mobile International Austria GmbH +Dominik Fischer [dfischer-tech], T-Systems International GmbH +Julien Hagestedt [jhagestedt], T-Systems International GmbH +Maximilian Laue [mlaue-tech], T-Systems International GmbH +Andreas Scheibal [ascheibal], T-Systems International GmbH +Michael Schulte [mschulte-tsi], T-Systems International GmbH +Lars Stelzner [lstelzne-tech], T-Systems International GmbH +Andreas Mandel [amandel], T-Systems International GmbH diff --git a/README.md b/README.md new file mode 100644 index 0000000..dfee6d2 --- /dev/null +++ b/README.md @@ -0,0 +1,207 @@ +
+ Development • + Documentation • + Support • + Contribute • + Contributors • + Repositories • + Licensing +
+ +The goal of this project is to develop the official Corona-Warn-App for Germany based on the exposure notification API +from [Apple](https://www.apple.com/covid19/contacttracing/) +and [Google](https://www.google.com/covid19/exposurenotifications/). The apps (for both iOS and Android) use Bluetooth +technology to exchange anonymous encrypted data with other mobile phones (on which the app is also installed) in the +vicinity of an app user's phone. The data is stored locally on each user's device, preventing authorities or other +parties from accessing or controlling the data. This repository contains the **log upload** for the Corona-Warn-App. + +## Status + +![ci](https://github.com/corona-warn-app/cwa-log-upload/workflows/ci/badge.svg) +[![quality gate](https://sonarcloud.io/api/project_badges/measure?project=corona-warn-app_cwa-log-upload&metric=alert_status)](https://sonarcloud.io/dashboard?id=corona-warn-app_cwa-log-upload) +[![coverage](https://sonarcloud.io/api/project_badges/measure?project=corona-warn-app_cwa-log-upload&metric=coverage)](https://sonarcloud.io/dashboard?id=corona-warn-app_cwa-log-upload) +[![bugs](https://sonarcloud.io/api/project_badges/measure?project=corona-warn-app_cwa-log-upload&metric=bugs)](https://sonarcloud.io/dashboard?id=corona-warn-app_cwa-log-upload) + +## About this component + +The log upload service is the counterpart of the log upload in the app. It enables the App developers to analyse the log data uploaded to the CWA infrastructure to indentify the root cause of bugs that only occur in rare conditions are not easy to reproduce. The log upload and viewer service follows the privacy preserving paradigm of the corona warn app, only allowing authorized personell to access the logs. The means to restrict access are the same that also protect TeleTAN generation from abusive usage. + +## Development + +This component can be built locally in order to test the functionality of the interfaces and verify the concepts it is +build upon. There are two ways to build: + +- [Maven](https:///maven.apache.org) build - to run this component as spring application on your local machine +- [Docker](https://www.docker.com) build - to run it as docker container build from the provided docker + build [file](https://github.com/corona-warn-app/cwa-log-upload/blob/master/Dockerfile) + +### Prerequisites + +[Open JDK 11](https://openjdk.java.net) +[Maven](https://maven.apache.org) +*(optional)*: [Docker](https://www.docker.com) + +### Build + +Whether you cloned or downloaded the 'zipped' sources you will either find the sources in the chosen checkout-directory +or get a zip file with the source code, which you can expand to a folder of your choice. + +In either case open a terminal pointing to the directory you put the sources in. The local build process is described +afterwards depending on the way you choose. + +#### Maven based build + +For actively take part on the development this is the way you should choose. +Please check, whether following prerequisites are fulfilled + +- [Open JDK 11](https://openjdk.java.net) or a similar JDK 11 compatible VM +- [Maven](https://maven.apache.org) + +is installed on your machine. +You can then open a terminal pointing to the root directory of the log upload and do the following: + + mvn package + java -jar target/cwa-log-upload-0.0.1-SNAPSHOT.jar + +The log upload will start up and run locally on your machine available on port 8081. Please keep in mind, that you need +another component [cwa-verification-iam] the get this running in a sensable manner. + +#### Docker based build + +We recommend that you first check the prerequisites to ensure that + +- [Docker](https://www.docker.com) + +is installed on your machine. + +On the command line do the following: + +```bash +docker build -f|--file'.concat(e,"
")})},create:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;jsPanel.zi||(jsPanel.zi=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:jsPanel.ziBase;return{next:function(){return e++}}}()),t.config?delete(t=Object.assign({},this.defaults,t.config,t)).config:t=Object.assign({},this.defaults,t),t.id?"function"==typeof t.id&&(t.id=t.id()):t.id="jsPanel-".concat(jsPanel.idCounter+=1);var o=document.getElementById(t.id);if(null!==o){if(o.classList.contains("jsPanel")&&o.front(),this.errorReporting){var a="◀ COULD NOT CREATE NEW JSPANEL ►>=p,I-=p,o=f,n=a,s=h,e=3;case 3:for(p=o;I
>=n[g+1],I-=n[g+1],y=n[g],0!=(16&y)){_=15&y,d=n[g+2],e=4;break}if(0==(64&y)){o=y,s=g/3+n[g+2];break}return e=9,x.msg="invalid distance code",w=$,t.bitb=U,t.bitk=I,x.avail_in=v,x.total_in+=E-x.next_in_index,x.next_in_index=E,t.write=m,t.inflate_flush(x,w);case 4:for(p=_;I
>=p,I-=p,e=5;case 5:for(A=m-d;A<0;)A+=t.end;for(;0!==r;){if(0===k&&(m==t.end&&0!==t.read&&(m=0,k=m >>=14,_-=14,o=0,r=4;case 4:for(;o<4+(s>>>10);){for(;_<3;){if(0===y)return n.bitb=w,n.bitk=_,t.avail_in=y,t.total_in+=g-t.next_in_index,t.next_in_index=g,n.write=b,n.inflate_flush(t,e);e=0,y--,w|=(255&t.read_byte(g++))<<_,_+=8}i[q[o++]]=7&w,w>>>=3,_-=3}for(;o<19;)i[q[o++]]=0;if(l[0]=7,p=f.inflate_trees_bits(i,l,d,h,t),0!=p)return-3==(e=p)&&(i=null,r=9),n.bitb=w,n.bitk=_,t.avail_in=y,t.total_in+=g-t.next_in_index,t.next_in_index=g,n.write=b,n.inflate_flush(t,e);o=0,r=5;case 5:for(;p=s,!(o>=258+(31&p)+(p>>5&31));){let a,c;for(p=l[0];_ >>=p,_-=p,i[o++]=c;else{for(m=18==c?7:c-14,a=18==c?11:3;_ >>=p,_-=p,a+=w&M[m],w>>>=m,_-=m,m=o,p=s,m+a>258+(31&p)+(p>>5&31)||16==c&&m<1)return i=null,r=9,t.msg="invalid bit length repeat",e=-3,n.bitb=w,n.bitk=_,t.avail_in=y,t.total_in+=g-t.next_in_index,t.next_in_index=g,n.write=b,n.inflate_flush(t,e);c=16==c?i[m-1]:0;do{i[m++]=c}while(0!=--a);o=m}}if(d[0]=-1,U=[],R=[],S=[],D=[],U[0]=9,R[0]=6,p=s,p=f.inflate_trees_dynamic(257+(31&p),1+(p>>5&31),i,U,R,S,D,h,t),0!=p)return-3==p&&(i=null,r=9),e=p,n.bitb=w,n.bitk=_,t.avail_in=y,t.total_in+=g-t.next_in_index,t.next_in_index=g,n.write=b,n.inflate_flush(t,e);c.init(U[0],R[0],h,S[0],h,D[0]),r=6;case 6:if(n.bitb=w,n.bitk=_,t.avail_in=y,t.total_in+=g-t.next_in_index,t.next_in_index=g,n.write=b,1!=(e=c.proc(n,t,e)))return n.inflate_flush(t,e);if(e=0,c.free(t),g=t.next_in_index,y=t.avail_in,w=n.bitb,_=n.bitk,b=n.write,x=b N)throw new Error(ae);const l=ce(this,n,"password"),d=ce(this,n,"encryptionStrength")||3;if(void 0!==l&&void 0!==d&&(d<1||d>3))throw new Error(se);e&&!e.initialized&&await e.init();let c=new Uint8Array(0);const u=n.extraField;if(u){let t=0,e=0;u.forEach((e=>t+=4+e.length)),c=new Uint8Array(t),u.forEach(((t,n)=>{if(n>D)throw new Error(oe);if(t.length>D)throw new Error(le);c.set(new Uint16Array([n]),e),c.set(new Uint16Array([t.length]),e+2),c.set(t,e+4),e+=4+t.length}))}const h=n.zip64||this.options.zip64||this.offset>=S||e&&(e.size>=S||this.offset+e.size>=S),f=ce(this,n,"level"),p=ce(this,n,"useWebWorkers"),w=ce(this,n,"bufferedWrite"),_=ce(this,n,"keepOrder"),g=await async function(t,e,n,i){const r=t.files,a=t.writer;let s,o,l;r.set(e,null);try{let d,c;try{i.keepOrder&&(o=t.lockPreviousFile,t.lockPreviousFile=new Promise((t=>l=t))),i.bufferedWrite||t.lockWrite?(d=new U,await d.init()):(t.lockWrite=new Promise((t=>s=t)),a.initialized||await a.init(),d=a),c=await async function(t,e,n,i){const r=i.rawFilename,a=i.lastModDate,s=i.password,o=Boolean(s&&s.length),l=i.level,d=0!==l&&!i.directory,c=i.zip64;let u,h;if(o){u=new Uint8Array(de.length+2);const t=new DataView(u.buffer);he(t,0,M),u.set(de,2),h=i.encryptionStrength,ue(t,8,h)}else u=new Uint8Array(0);const f={version:i.version||20,zip64:c,directory:Boolean(i.directory),filenameUTF8:!0,rawFilename:r,commentUTF8:!0,rawComment:i.rawComment,rawExtraFieldZip64:c?new Uint8Array(28):new Uint8Array(0),rawExtraFieldAES:u,rawExtraField:i.rawExtraField};let p=2056,w=0;d&&(w=8);c&&(f.version=f.version>45?f.version:45);o&&(f.version=f.version>51?f.version:51,p|=1,w=99,d&&(f.rawExtraFieldAES[9]=8));const _=f.headerArray=new Uint8Array(26),g=new DataView(_.buffer);he(g,0,f.version),he(g,2,p),he(g,4,w),he(g,6,(a.getHours()<<6|a.getMinutes())<<5|a.getSeconds()/2),he(g,8,(a.getFullYear()-1980<<4|a.getMonth()+1)<<5|a.getDate()),he(g,22,r.length),he(g,24,0);const y=g.getUint32(6,!0),b=new Uint8Array(30+r.length);fe(new DataView(b.buffer),0,F),b.set(_,4),b.set(r,30);let x,m=0,v=0;if(t){m=t.size;const r=await Ut({codecType:pt,codecConstructor:n.Deflate,level:l,outputPassword:s,outputEncryptionStrength:h,outputSigned:!0,outputCompressed:d,outputEncrypted:o,useWebWorkers:i.useWebWorkers},n);await e.writeUint8Array(b),x=await St(r,t,e,0,m,n,{onprogress:i.onprogress}),v=x.length}else await e.writeUint8Array(b);const k=new Uint8Array(c?24:16),A=new DataView(k.buffer);if(fe(A,0,I),t)if(o||void 0===x.signature||(fe(g,10,x.signature),fe(A,4,x.signature),f.signature=x.signature),c){const t=new DataView(f.rawExtraFieldZip64.buffer);he(t,0,1),he(t,2,24),fe(g,14,S),pe(A,8,BigInt(v)),pe(t,12,BigInt(v)),fe(g,18,S),pe(A,16,BigInt(m)),pe(t,4,BigInt(m))}else fe(g,14,v),fe(A,8,v),fe(g,18,m),fe(A,12,m);return await e.writeUint8Array(k),f.compressedSize=v,f.uncompressedSize=m,f.lastModDate=a,f.rawLastModDate=y,f.encrypted=o,f.length=b.length+(x?x.length:0)+k.length,f}(n,d,t.config,i)}catch(t){throw r.delete(e),t}if(r.set(e,c),d!=a&&(t.lockWrite&&await t.lockWrite,o&&await o,await a.writeUint8Array(d.getData())),c.offset=t.offset,c.zip64){pe(new DataView(c.rawExtraFieldZip64.buffer),20,BigInt(c.offset))}return t.offset+=c.length,c}finally{l&&l(),s&&(t.lockWrite=null,s())}}(this,t,e,Object.assign({},n,{rawFilename:i,rawComment:a,version:s,lastModDate:o,rawExtraField:c,zip64:h,password:l,level:f,useWebWorkers:p,encryptionStrength:d,bufferedWrite:w,keepOrder:_}));return g.filename=t,g.comment=r,g.extraField=u,new It(g)}async close(t=new Uint8Array(0)){const e=this.writer,n=this.files;let i=0,r=0,a=this.offset,s=n.size;for(const[,t]of n)r+=46+t.rawFilename.length+t.rawComment.length+t.rawExtraFieldZip64.length+t.rawExtraFieldAES.length+t.rawExtraField.length;const o=this.options.zip64||a+r>=S||s>=D,l=new Uint8Array(r+(o?98:22)),d=new DataView(l.buffer);if(t.length){if(!(t.length<=D))throw new Error(ee);he(d,i+20,t.length)}for(const[,t]of n){const e=t.rawFilename,n=t.rawExtraFieldZip64,r=t.rawExtraFieldAES,a=n.length+r.length+t.rawExtraField.length;fe(d,i,T),he(d,i+4,t.version),l.set(t.headerArray,i+6),he(d,i+30,a),he(d,i+32,t.rawComment.length),t.directory&&ue(d,i+38,16),t.zip64?fe(d,i+42,S):fe(d,i+42,t.offset),l.set(e,i+46),l.set(n,i+46+e.length),l.set(r,i+46+e.length+n.length),l.set(t.rawExtraField,46+e.length+n.length+r.length),l.set(t.rawComment,i+46+e.length+a),i+=46+e.length+a+t.rawComment.length}return o&&(fe(d,i,z),pe(d,i+4,BigInt(44)),he(d,i+12,45),he(d,i+14,45),pe(d,i+24,BigInt(s)),pe(d,i+32,BigInt(s)),pe(d,i+40,BigInt(r)),pe(d,i+48,BigInt(a)),fe(d,i+56,O),pe(d,i+64,BigInt(a+r)),fe(d,i+72,1),s=D,a=S,i+=76),fe(d,i,C),he(d,i+8,s),he(d,i+10,s),fe(d,i+12,r),fe(d,i+16,a),await e.writeUint8Array(l),t.length&&await e.writeUint8Array(t),e.getData()}}{constructor(t,e){super(t,e,i())}},t.configure=r,t.getMimeType=function(){return"application/octet-stream"},t.initShimAsyncCodec=(t,e={})=>({Deflate:s(t.Deflate,e.deflate),Inflate:s(t.Inflate,e.inflate)}),Object.defineProperty(t,"__esModule",{value:!0})}));
diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html
new file mode 100644
index 0000000..db3e00d
--- /dev/null
+++ b/src/main/resources/templates/error.html
@@ -0,0 +1,40 @@
+
+
+9||n<0||n>2?-2:(F[D].func!=F[e].func&&0!==t.total_in&&(i=t.deflate(1)),D!=e&&(D=e,U=F[D].max_lazy,z=F[D].good_length,O=F[D].nice_length,E=F[D].max_chain),C=n,i)},t.deflateSetDictionary=function(t,e,i){let r,s=i,d=0;if(!e||42!=n)return-2;if(s<3)return 0;for(s>a-262&&(s=a-262,d=i-s),l.set(e.subarray(d,d+s),0),m=s,g=s,h=255&l[0],h=(h<<_^255&l[1])&w,r=0;r<=s-3;r++)h=(h<<_^255&l[r+2])&w,c[r&o]=u[h],u[h]=r;return 0},t.deflate=function(d,p){let E,R,T,z,O;if(p>4||p<0)return-2;if(!d.next_out||!d.next_in&&0!==d.avail_in||666==n&&4!=p)return d.msg=I[4],-2;if(0===d.avail_out)return d.msg=I[7],-5;var M;if(e=d,z=r,r=p,42==n&&(R=8+(s-8<<4)<<8,T=(D-1&255)>>1,T>3&&(T=3),R|=T<<6,0!==m&&(R|=32),R+=31-R%31,n=113,Q((M=R)>>8&255),Q(255&M)),0!==t.pending){if(e.flush_pending(),0===e.avail_out)return r=-1,0}else if(0===e.avail_in&&p<=z&&4!=p)return e.msg=I[7],-5;if(666==n&&0!==e.avail_in)return d.msg=I[7],-5;if(0!==e.avail_in||0!==k||0!=p&&666!=n){switch(O=-1,F[D].func){case 0:O=function(t){let n,r=65535;for(r>i-5&&(r=i-5);;){if(k<=1){if(ct(),0===k&&0==t)return 0;if(0===k)break}if(m+=k,k=0,n=g+r,(0===m||m>=n)&&(k=m-n,m=n,dt(!1),0===e.avail_out))return 0;if(m-g>=a-262&&(dt(!1),0===e.avail_out))return 0}return dt(4==t),0===e.avail_out?4==t?2:0:4==t?3:1}(p);break;case 1:O=function(t){let n,i=0;for(;;){if(k<262){if(ct(),k<262&&0==t)return 0;if(0===k)break}if(k>=3&&(h=(h<<_^255&l[m+2])&w,i=65535&u[h],c[m&o]=u[h],u[h]=m),0!==i&&(m-i&65535)<=a-262&&2!=C&&(y=ut(i)),y>=3)if(n=rt(m-v,y-3),k-=y,y<=U&&k>=3){y--;do{m++,h=(h<<_^255&l[m+2])&w,i=65535&u[h],c[m&o]=u[h],u[h]=m}while(0!=--y);m++}else m+=y,y=0,h=255&l[m],h=(h<<_^255&l[m+1])&w;else n=rt(0,255&l[m]),k--,m++;if(n&&(dt(!1),0===e.avail_out))return 0}return dt(4==t),0===e.avail_out?4==t?2:0:4==t?3:1}(p);break;case 2:O=function(t){let n,i,r=0;for(;;){if(k<262){if(ct(),k<262&&0==t)return 0;if(0===k)break}if(k>=3&&(h=(h<<_^255&l[m+2])&w,r=65535&u[h],c[m&o]=u[h],u[h]=m),A=y,b=v,y=2,0!==r&&A4096)&&(y=2)),A>=3&&y<=A){i=m+k-3,n=rt(m-1-b,A-3),k-=A-1,A-=2;do{++m<=i&&(h=(h<<_^255&l[m+2])&w,r=65535&u[h],c[m&o]=u[h],u[h]=m)}while(0!=--A);if(x=0,y=2,m++,n&&(dt(!1),0===e.avail_out))return 0}else if(0!==x){if(n=rt(0,255&l[m-1]),n&&dt(!1),m++,k--,0===e.avail_out)return 0}else x=1,m++,k--}return 0!==x&&(n=rt(0,255&l[m-1]),x=0),dt(4==t),0===e.avail_out?4==t?2:0:4==t?3:1}(p)}if(2!=O&&3!=O||(n=666),0==O||2==O)return 0===e.avail_out&&(r=-1),0;if(1==O){if(1==p)tt(2,3),et(256,S.static_ltree),it(),1+K+10-X<9&&(tt(2,3),et(256,S.static_ltree),it()),K=7;else if(ot(0,0,!1),3==p)for(E=0;E
+
+
+
+
+
+ Corona Warn App - Log Upload
+
+
+
+
+
+
+ Corona Warn App - Log Upload
+
+
+
+
+
+
+
+
+ Corona Warn App - Log Upload
+
+ Log-ID:
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/templates/start.html b/src/main/resources/templates/start.html
new file mode 100644
index 0000000..18e2a37
--- /dev/null
+++ b/src/main/resources/templates/start.html
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Corona Warn App - Log Upload
+
+
+
+
+
+
+
+
+
diff --git a/src/test/java/app/coronawarn/logupload/controller/LogDownloadApiControllerTest.java b/src/test/java/app/coronawarn/logupload/controller/LogDownloadApiControllerTest.java
new file mode 100644
index 0000000..5aa1c08
--- /dev/null
+++ b/src/test/java/app/coronawarn/logupload/controller/LogDownloadApiControllerTest.java
@@ -0,0 +1,91 @@
+package app.coronawarn.logupload.controller;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.BDDMockito.given;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import app.coronawarn.logupload.model.LogEntity;
+import app.coronawarn.logupload.service.FileStorageService;
+import com.c4_soft.springaddons.security.oauth2.test.annotations.keycloak.WithMockKeycloakAuth;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.time.ZonedDateTime;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.HttpHeaders;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.ResultMatcher;
+
+@WebMvcTest(controllers = LogDownloadApiController.class)
+@ContextConfiguration(classes = LogDownloadApiController.class)
+@ActiveProfiles("portal")
+public class LogDownloadApiControllerTest {
+
+ @Autowired
+ MockMvc mockMvc;
+
+ @MockBean
+ FileStorageService fileStorageServiceMock;
+
+ private final static byte[] dummyBytes = new byte[]{0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF};
+ private final static String dummyFileName = "dummy.zip";
+ private final static String dummyHash = "hash123456789";
+ private final static String dummyLogId = "ABCDEFG";
+ private final static LogEntity dummyLogEntity = new LogEntity(dummyLogId, ZonedDateTime.now(), dummyFileName, dummyBytes.length, dummyHash, "");
+
+ @Test
+ @WithMockKeycloakAuth
+ public void testLogDownload() throws Exception {
+ InputStream stream = new ByteArrayInputStream(dummyBytes);
+
+ given(fileStorageServiceMock.downloadFile(eq(dummyLogId)))
+ .willReturn(new FileStorageService.LogDownloadResponse(dummyLogEntity, stream));
+
+ mockMvc.perform(get("/portal/api/logs/" + dummyLogId).header("Host", "localhost:8085"))
+ .andExpect(ResultMatcher.matchAll(
+ status().isOk(),
+ header().string(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + dummyFileName + "\""),
+ header().longValue(HttpHeaders.CONTENT_LENGTH, dummyBytes.length),
+ content().bytes(dummyBytes)
+ ));
+ }
+
+ @Test
+ public void testLogDownloadShouldFailWithInvalidRole() throws Exception {
+ InputStream stream = new ByteArrayInputStream(dummyBytes);
+
+ given(fileStorageServiceMock.downloadFile(eq(dummyLogId)))
+ .willReturn(new FileStorageService.LogDownloadResponse(dummyLogEntity, stream));
+
+ mockMvc.perform(get("/portal/api/logs/" + dummyLogId).header("Host", "localhost:8085"))
+ .andExpect(status().isUnauthorized());
+ }
+
+ @Test
+ @WithMockKeycloakAuth
+ public void testLogDownloadShouldReturn404IfFileNotFound() throws Exception {
+ given(fileStorageServiceMock.downloadFile(eq(dummyLogId)))
+ .willThrow(new FileStorageService.FileStoreException(FileStorageService.FileStoreException.Reason.FILE_NOT_FOUND));
+
+ mockMvc.perform(get("/portal/api/logs/" + dummyLogId).header("Host", "localhost:8085"))
+ .andExpect(status().isNotFound());
+ }
+
+ @Test
+ @WithMockKeycloakAuth
+ public void testLogDownloadShouldReturn500IfDownloadFails() throws Exception {
+ given(fileStorageServiceMock.downloadFile(eq(dummyLogId)))
+ .willThrow(new FileStorageService.FileStoreException(FileStorageService.FileStoreException.Reason.S3_DOWNLOAD_FAILED));
+
+ mockMvc.perform(get("/portal/api/logs/" + dummyLogId).header("Host", "localhost:8085"))
+ .andExpect(status().isInternalServerError());
+
+ }
+}
diff --git a/src/test/java/app/coronawarn/logupload/controller/LogUploadApiControllerTest.java b/src/test/java/app/coronawarn/logupload/controller/LogUploadApiControllerTest.java
new file mode 100644
index 0000000..e79079e
--- /dev/null
+++ b/src/test/java/app/coronawarn/logupload/controller/LogUploadApiControllerTest.java
@@ -0,0 +1,163 @@
+package app.coronawarn.logupload.controller;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import app.coronawarn.logupload.model.LogEntity;
+import app.coronawarn.logupload.service.FileStorageService;
+import app.coronawarn.logupload.service.OtpService;
+import com.c4_soft.springaddons.security.oauth2.test.annotations.keycloak.WithMockKeycloakAuth;
+import java.io.InputStream;
+import java.time.ZonedDateTime;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.mock.web.MockMultipartFile;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.ResultMatcher;
+
+@WebMvcTest(controllers = LogUploadApiController.class)
+@ContextConfiguration(classes = {LogUploadApiController.class})
+@ActiveProfiles("api")
+public class LogUploadApiControllerTest {
+
+
+ @Autowired
+ MockMvc mockMvc;
+
+ @MockBean
+ FileStorageService fileStorageServiceMock;
+
+ @MockBean
+ OtpService otpServiceMock;
+
+ private final static byte[] dummyBytes = new byte[]{0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF};
+ private final static String dummyFileName = "dummy.zip";
+ private final static String dummyHash = "hash123456789";
+ private final static String dummyLogId = "ABCDEFG";
+ private final static String OTP_HEADER = "cwa-otp";
+ private final static LogEntity dummyLogEntity = new LogEntity(dummyLogId, ZonedDateTime.now(), dummyFileName, dummyBytes.length, dummyHash, "");
+ private final static String testOtp = "ea8166fa-6a42-426a-8b14-a4c53ff710b5";
+
+ @Test
+ @WithMockKeycloakAuth
+ public void testLogUpload() throws Exception {
+ ArgumentCaptor
+
+
+
+