Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Add new test environment TESTER-MOCK + clean up (DEV, EXPOSUREAPP-613…
Browse files Browse the repository at this point in the history
…8) (#2744)

* Add new test environment TESTER-MOCK + clean up.

* kLint, fun for the whole family.

* Make naming consistent

Co-authored-by: harambasicluka <64483219+harambasicluka@users.noreply.github.com>
Co-authored-by: Lukas Lechner <lukas.lechner@sap.com>
Co-authored-by: Lukas Lechner <office@lukaslechner.com>
  • Loading branch information
4 people authored Apr 6, 2021
1 parent 4faf340 commit 0c63ea6
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class VerifiedTraceLocationTest : BaseTestInstrumentation() {
@Before
fun setUp() {
MockKAnnotations.init(this)
every { environmentSetup.appConfigVerificationKey } returns PUB_KEY
every { environmentSetup.appConfigPublicKey } returns PUB_KEY
}

// TODO: Ugly but kinda works
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class VerificationKeysTest {
@Before
fun setup() {
MockKAnnotations.init(this)
every { environmentSetup.appConfigVerificationKey } returns PUB_KEY
every { environmentSetup.appConfigPublicKey } returns PUB_KEY
}

private fun createTool() = SignatureValidation(environmentSetup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class DebugOptionsFragment : Fragment(R.layout.fragment_test_debugoptions), Auto
environmentCdnurlSubmission.text = "Submission CDN:\n${state.urlSubmission}"
environmentCdnurlVerification.text = "Verification CDN:\n${state.urlVerification}"
environmentUrlDatadonation.text = "DataDonation:\n${state.urlDataDonation}"
environmentUrlQrcodePosterTemplate.text = "QR-Code Poster Template:\n${state.urlQrCodePosterTemplate}"
environmentUrlLogUpload.text = "LogUpload:\n${state.urlLogUpload}"
environmentPubkeyCrowdnotifier.text = "CrowdNotifierPubKey:\n${state.pubKeyCrowdNotifier}"
environmentPubkeyAppconfig.text = "AppConfigPubKey:\n${state.pubKeyAppConfig}"
}
}
vm.environmentChangeEvent.observe2(this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ data class EnvironmentState(
val urlDownload: String,
val urlVerification: String,
val urlDataDonation: String,
val urlQrCodePosterTemplate: String

val urlLogUpload: String,
val pubKeyCrowdNotifier: String,
val pubKeyAppConfig: String,
) {
companion object {
internal fun EnvironmentSetup.toEnvironmentState() = EnvironmentState(
Expand All @@ -20,7 +21,9 @@ data class EnvironmentState(
urlDownload = downloadCdnUrl,
urlVerification = verificationCdnUrl,
urlDataDonation = dataDonationCdnUrl,
urlQrCodePosterTemplate = qrCodePosterTemplateCdnUrl
urlLogUpload = logUploadServerUrl,
pubKeyCrowdNotifier = crowdNotifierPublicKey,
pubKeyAppConfig = appConfigPublicKey,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
app:layout_constraintTop_toBottomOf="@+id/new_debuglog_screen_explanation" />
</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
<LinearLayout
android:orientation="vertical"
android:id="@+id/environment_container"
style="@style/Card"
android:layout_width="match_parent"
Expand All @@ -66,77 +67,71 @@
style="@style/headline6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Server environment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:text="Server environments" />

<TextView
android:id="@+id/environment_cdnurl_download"
style="@style/body2"
style="@style/TextAppearance.MaterialComponents.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_tiny"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/environment_title"
tools:text="Download: ?" />

<TextView
android:id="@+id/environment_cdnurl_submission"
style="@style/body2"
style="@style/TextAppearance.MaterialComponents.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_tiny"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/environment_cdnurl_download"
android:layout_marginTop="4dp"
tools:text="Submission: ?" />

<TextView
android:id="@+id/environment_cdnurl_verification"
style="@style/body2"
style="@style/TextAppearance.MaterialComponents.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_tiny"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/environment_cdnurl_submission"
android:layout_marginTop="4dp"
tools:text="Verification: ?" />

<TextView
android:id="@+id/environment_url_datadonation"
style="@style/body2"
style="@style/TextAppearance.MaterialComponents.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_tiny"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/environment_cdnurl_verification"
android:layout_marginTop="4dp"
tools:text="DataDonation: ?" />

<TextView
android:id="@+id/environment_url_qrcode_poster_template"
style="@style/body2"
android:id="@+id/environment_url_log_upload"
style="@style/TextAppearance.MaterialComponents.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_tiny"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/environment_url_datadonation"
tools:text="QR-Code poster template: ?" />
android:layout_marginTop="4dp"
tools:text="LogUpload: ?" />

<TextView
android:id="@+id/environment_pubkey_appconfig"
style="@style/TextAppearance.MaterialComponents.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
tools:text="AppConfigPubKey: ?" />

<TextView
android:id="@+id/environment_pubkey_crowdnotifier"
style="@style/TextAppearance.MaterialComponents.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
tools:text="CrowdNotifierPubKey: ?" />

<RadioGroup
android:id="@+id/environment_toggle_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_tiny"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/environment_url_qrcode_poster_template" />
</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_marginTop="16dp"
android:orientation="vertical" />
</LinearLayout>

</LinearLayout>
</androidx.core.widget.NestedScrollView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class EnvironmentSetup @Inject constructor(
DOWNLOAD("DOWNLOAD_CDN_URL"),
VERIFICATION_KEYS("PUB_KEYS_SIGNATURE_VERIFICATION"),
DATA_DONATION("DATA_DONATION_CDN_URL"),
QRCODE_POSTER_TEMPLATE("QRCODE_POSTER_TEMPLATE_URL"),
LOG_UPLOAD("LOG_UPLOAD_SERVER_URL"),
SAFETYNET_API_KEY("SAFETYNET_API_KEY"),
CROWD_NOTIFIER_PUBLIC_KEY("CROWD_NOTIFIER_PUBLIC_KEY")
Expand All @@ -48,6 +47,7 @@ class EnvironmentSetup @Inject constructor(
WRU("WRU"),
WRU_XA("WRU-XA"), // (aka ACME),
WRU_XD("WRU-XD"), // (aka Germany)
TESTER_MOCK("TESTER-MOCK"), // (aka Germany)
LOCAL("LOCAL"); // Emulator/CLI tooling

companion object {
Expand Down Expand Up @@ -118,10 +118,8 @@ class EnvironmentSetup @Inject constructor(
get() = getEnvironmentValue(DOWNLOAD).asString
val dataDonationCdnUrl: String
get() = getEnvironmentValue(DATA_DONATION).asString
val qrCodePosterTemplateCdnUrl: String
get() = getEnvironmentValue(EnvKey.QRCODE_POSTER_TEMPLATE).asString

val appConfigVerificationKey: String
val appConfigPublicKey: String
get() = getEnvironmentValue(VERIFICATION_KEYS).asString

val useEuropeKeyPackageFiles: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import android.content.Context
import dagger.Module
import dagger.Provides
import de.rki.coronawarnapp.environment.BaseEnvironmentModule
import de.rki.coronawarnapp.environment.EnvironmentSetup
import de.rki.coronawarnapp.environment.download.DownloadCDNHttpClient
import de.rki.coronawarnapp.environment.download.DownloadCDNServerUrl
import de.rki.coronawarnapp.eventregistration.events.server.qrcodepostertemplate.QrCodePosterTemplateApiV1
import de.rki.coronawarnapp.util.di.AppContext
import okhttp3.Cache
Expand All @@ -32,19 +32,11 @@ class QrCodePosterTemplateModule : BaseEnvironmentModule() {
@QrCodePosterTemplate cacheDir: File
): Cache = Cache(File(cacheDir, "cache_http"), CACHE_SIZE_5MB)

@Singleton
@QrCodePosterTemplate
@Provides
fun provideQrCodePosterTemplateCDNServerUrl(environment: EnvironmentSetup): String {
val url = environment.qrCodePosterTemplateCdnUrl
return requireValidUrl(url)
}

@Singleton
@Provides
fun api(
@DownloadCDNHttpClient client: OkHttpClient,
@QrCodePosterTemplate url: String,
@DownloadCDNServerUrl url: String,
@QrCodePosterTemplate cache: Cache
): QrCodePosterTemplateApiV1 {
val httpClient = client.newBuilder().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SignatureValidation @Inject constructor(

// Public keys within this server environment
private val publicKeys by lazy {
environmentSetup.appConfigVerificationKey.split(KEY_DELIMITER)
environmentSetup.appConfigPublicKey.split(KEY_DELIMITER)
.mapNotNull { pubKeyBase64 -> Base64.decode(pubKeyBase64, Base64.DEFAULT) }
.map { pubKeyBinary -> keyFactory.generatePublic(X509EncodedKeySpec(pubKeyBinary)) }
.onEach { Timber.tag(TAG).v("ENV PubKey: %s", it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ class EnvironmentSetupTest : BaseTest() {
downloadCdnUrl shouldBe "https://download-${env.rawKey}"
submissionCdnUrl shouldBe "https://submission-${env.rawKey}"
verificationCdnUrl shouldBe "https://verification-${env.rawKey}"
appConfigVerificationKey shouldBe "12345678-${env.rawKey}"
appConfigPublicKey shouldBe "12345678-${env.rawKey}"
safetyNetApiKey shouldBe "placeholder-${env.rawKey}"
dataDonationCdnUrl shouldBe "https://datadonation-${env.rawKey}"
logUploadServerUrl shouldBe "https://logupload-${env.rawKey}"
qrCodePosterTemplateCdnUrl shouldBe "https://qrcodepostertemplate-${env.rawKey}"
crowdNotifierPublicKey shouldBe "123_abc-${env.rawKey}"
}
}
Expand Down Expand Up @@ -115,8 +114,9 @@ class EnvironmentSetupTest : BaseTest() {
EnvironmentSetup.Type.WRU.rawKey shouldBe "WRU"
EnvironmentSetup.Type.WRU_XA.rawKey shouldBe "WRU-XA"
EnvironmentSetup.Type.WRU_XD.rawKey shouldBe "WRU-XD"
EnvironmentSetup.Type.TESTER_MOCK.rawKey shouldBe "TESTER-MOCK"
EnvironmentSetup.Type.LOCAL.rawKey shouldBe "LOCAL"
EnvironmentSetup.Type.values().size shouldBe 7
EnvironmentSetup.Type.values().size shouldBe 8

EnvironmentSetup.EnvKey.USE_EUR_KEY_PKGS.rawKey shouldBe "USE_EUR_KEY_PKGS"
EnvironmentSetup.EnvKey.SUBMISSION.rawKey shouldBe "SUBMISSION_CDN_URL"
Expand All @@ -126,9 +126,8 @@ class EnvironmentSetupTest : BaseTest() {
EnvironmentSetup.EnvKey.DATA_DONATION.rawKey shouldBe "DATA_DONATION_CDN_URL"
EnvironmentSetup.EnvKey.LOG_UPLOAD.rawKey shouldBe "LOG_UPLOAD_SERVER_URL"
EnvironmentSetup.EnvKey.SAFETYNET_API_KEY.rawKey shouldBe "SAFETYNET_API_KEY"
EnvironmentSetup.EnvKey.QRCODE_POSTER_TEMPLATE.rawKey shouldBe "QRCODE_POSTER_TEMPLATE_URL"
EnvironmentSetup.EnvKey.CROWD_NOTIFIER_PUBLIC_KEY.rawKey shouldBe "CROWD_NOTIFIER_PUBLIC_KEY"
EnvironmentSetup.EnvKey.values().size shouldBe 10
EnvironmentSetup.EnvKey.values().size shouldBe 9
}

companion object {
Expand All @@ -137,6 +136,7 @@ class EnvironmentSetupTest : BaseTest() {
EnvironmentSetup.Type.PRODUCTION,
EnvironmentSetup.Type.WRU_XD,
EnvironmentSetup.Type.WRU_XA,
EnvironmentSetup.Type.TESTER_MOCK,
EnvironmentSetup.Type.LOCAL
)
private const val GOOD_JSON =
Expand All @@ -149,7 +149,6 @@ class EnvironmentSetupTest : BaseTest() {
"VERIFICATION_CDN_URL": "https://verification-PROD",
"DATA_DONATION_CDN_URL": "https://datadonation-PROD",
"LOG_UPLOAD_SERVER_URL": "https://logupload-PROD",
"QRCODE_POSTER_TEMPLATE_URL": "https://qrcodepostertemplate-PROD",
"SAFETYNET_API_KEY": "placeholder-PROD",
"PUB_KEYS_SIGNATURE_VERIFICATION": "12345678-PROD",
"CROWD_NOTIFIER_PUBLIC_KEY": "123_abc-PROD"
Expand All @@ -161,7 +160,6 @@ class EnvironmentSetupTest : BaseTest() {
"VERIFICATION_CDN_URL": "https://verification-DEV",
"DATA_DONATION_CDN_URL": "https://datadonation-DEV",
"LOG_UPLOAD_SERVER_URL": "https://logupload-DEV",
"QRCODE_POSTER_TEMPLATE_URL": "https://qrcodepostertemplate-DEV",
"SAFETYNET_API_KEY": "placeholder-DEV",
"PUB_KEYS_SIGNATURE_VERIFICATION": "12345678-DEV",
"CROWD_NOTIFIER_PUBLIC_KEY": "123_abc-DEV"
Expand All @@ -173,7 +171,6 @@ class EnvironmentSetupTest : BaseTest() {
"VERIFICATION_CDN_URL": "https://verification-INT",
"DATA_DONATION_CDN_URL": "https://datadonation-INT",
"LOG_UPLOAD_SERVER_URL": "https://logupload-INT",
"QRCODE_POSTER_TEMPLATE_URL": "https://qrcodepostertemplate-INT",
"SAFETYNET_API_KEY": "placeholder-INT",
"PUB_KEYS_SIGNATURE_VERIFICATION": "12345678-INT",
"CROWD_NOTIFIER_PUBLIC_KEY": "123_abc-INT"
Expand All @@ -185,7 +182,6 @@ class EnvironmentSetupTest : BaseTest() {
"VERIFICATION_CDN_URL": "https://verification-WRU",
"DATA_DONATION_CDN_URL": "https://datadonation-WRU",
"LOG_UPLOAD_SERVER_URL": "https://logupload-WRU",
"QRCODE_POSTER_TEMPLATE_URL": "https://qrcodepostertemplate-WRU",
"SAFETYNET_API_KEY": "placeholder-WRU",
"PUB_KEYS_SIGNATURE_VERIFICATION": "12345678-WRU",
"CREATE_TRACELOCATION_URL": "https://tracelocation-WRU",
Expand All @@ -198,7 +194,6 @@ class EnvironmentSetupTest : BaseTest() {
"VERIFICATION_CDN_URL": "https://verification-WRU-XD",
"DATA_DONATION_CDN_URL": "https://datadonation-WRU-XD",
"LOG_UPLOAD_SERVER_URL": "https://logupload-WRU-XD",
"QRCODE_POSTER_TEMPLATE_URL": "https://qrcodepostertemplate-WRU-XD",
"SAFETYNET_API_KEY": "placeholder-WRU-XD",
"PUB_KEYS_SIGNATURE_VERIFICATION": "12345678-WRU-XD",
"CROWD_NOTIFIER_PUBLIC_KEY": "123_abc-WRU-XD"
Expand All @@ -210,19 +205,28 @@ class EnvironmentSetupTest : BaseTest() {
"VERIFICATION_CDN_URL": "https://verification-WRU-XA",
"DATA_DONATION_CDN_URL": "https://datadonation-WRU-XA",
"LOG_UPLOAD_SERVER_URL": "https://logupload-WRU-XA",
"QRCODE_POSTER_TEMPLATE_URL": "https://qrcodepostertemplate-WRU-XA",
"SAFETYNET_API_KEY": "placeholder-WRU-XA",
"PUB_KEYS_SIGNATURE_VERIFICATION": "12345678-WRU-XA",
"CROWD_NOTIFIER_PUBLIC_KEY": "123_abc-WRU-XA"
},
"TESTER-MOCK": {
"USE_EUR_KEY_PKGS" : true,
"SUBMISSION_CDN_URL": "https://submission-TESTER-MOCK",
"DOWNLOAD_CDN_URL": "https://download-TESTER-MOCK",
"VERIFICATION_CDN_URL": "https://verification-TESTER-MOCK",
"DATA_DONATION_CDN_URL": "https://datadonation-TESTER-MOCK",
"LOG_UPLOAD_SERVER_URL": "https://logupload-TESTER-MOCK",
"SAFETYNET_API_KEY": "placeholder-TESTER-MOCK",
"PUB_KEYS_SIGNATURE_VERIFICATION": "12345678-TESTER-MOCK",
"CROWD_NOTIFIER_PUBLIC_KEY": "123_abc-TESTER-MOCK"
},
"LOCAL": {
"USE_EUR_KEY_PKGS" : true,
"SUBMISSION_CDN_URL": "https://submission-LOCAL",
"DOWNLOAD_CDN_URL": "https://download-LOCAL",
"VERIFICATION_CDN_URL": "https://verification-LOCAL",
"DATA_DONATION_CDN_URL": "https://datadonation-LOCAL",
"LOG_UPLOAD_SERVER_URL": "https://logupload-LOCAL",
"QRCODE_POSTER_TEMPLATE_URL": "https://qrcodepostertemplate-LOCAL",
"SAFETYNET_API_KEY": "placeholder-LOCAL",
"PUB_KEYS_SIGNATURE_VERIFICATION": "12345678-LOCAL",
"CROWD_NOTIFIER_PUBLIC_KEY": "123_abc-LOCAL"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class DebugOptionsFragmentViewModelTest : BaseTestInstrumentation() {
every { environmentSetup.downloadCdnUrl } returns "downloadUrl"
every { environmentSetup.verificationCdnUrl } returns "verificationUrl"
every { environmentSetup.dataDonationCdnUrl } returns "dataDonationUrl"
every { environmentSetup.qrCodePosterTemplateCdnUrl } returns "qrCodePosterTemplateUrl"
every { environmentSetup.logUploadServerUrl } returns "logUploadServerUrl"
every { environmentSetup.crowdNotifierPublicKey } returns "crowdNotifierPublicKey"
every { environmentSetup.appConfigPublicKey } returns "appConfigPublicKey"

every { environmentSetup.currentEnvironment = any() } answers {
currentEnvironment = arg(0)
Expand Down
Loading

0 comments on commit 0c63ea6

Please sign in to comment.