Skip to content

Commit

Permalink
Removed authorizationSource from header + prefix in username (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
nulls authored Aug 2, 2023
1 parent 98468a5 commit 28ad32c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 35 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ jobs:
gradle-version: wrapper
arguments: |
-Dsave-cloud.backend.url=https://saveourtool.com
-Dsave-cloud.user=github@${{ secrets.SAVE_CLOUD_USER }}
-Dsave-cloud.user=${{ secrets.SAVE_CLOUD_USER }}
-Dsave-cloud.password=${{ secrets.SAVE_CLOUD_PASSWORD }}
-Dsave-cloud.user.auth.source=github
-Dsave-cloud.project.name=Diktat-Integration
-Dsave-cloud.contest.name=Integration-Tests
-Dsave-cloud.test.version=save-integration-test
Expand Down
1 change: 0 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ The following properties control the behavior of the tests:

* `save-cloud.backend.url`
* `save-cloud.user`
* `save-cloud.user.auth.source`
* `save-cloud.password`
* `save-cloud.test.suite.ids`
* `save-cloud.test.version`
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ tasks.withType<Test> {
sequenceOf(
"save-cloud.backend.url",
"save-cloud.user",
"save-cloud.user.auth.source",
"save-cloud.password",
"save-cloud.test.suite.ids",
"save-cloud.test.version",
Expand Down
10 changes: 1 addition & 9 deletions src/test/kotlin/com/saveourtool/save/api/SaveBackendFastTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import com.saveourtool.save.api.assertions.assertNonNull
import com.saveourtool.save.api.assertions.fail
import com.saveourtool.save.api.errors.SaveCloudError
import com.saveourtool.save.testsuite.TestSuiteVersioned
import com.saveourtool.save.utils.AUTHORIZATION_SOURCE
import com.saveourtool.save.utils.getLogger
import arrow.core.flatMap
import arrow.core.getOrElse
import io.ktor.client.plugins.auth.providers.BasicAuthCredentials
import io.ktor.client.plugins.auth.providers.basic
import io.ktor.client.request.headers
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -35,13 +33,7 @@ class SaveBackendFastTest {
requestTimeoutMillis = SECONDS.toMillis(500L)
) {
basic {
sendWithoutRequest { requestBuilder ->
requestBuilder.headers {
this[AUTHORIZATION_SOURCE] = authorizationSource
}

true
}
sendWithoutRequest { true }

credentials {
BasicAuthCredentials(username = user, password = passwordOrToken)
Expand Down
10 changes: 1 addition & 9 deletions src/test/kotlin/com/saveourtool/save/api/SaveBackendTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ import com.saveourtool.save.execution.TestingType.PRIVATE_TESTS
import com.saveourtool.save.execution.TestingType.PUBLIC_TESTS
import com.saveourtool.save.request.CreateExecutionRequest
import com.saveourtool.save.testsuite.TestSuiteVersioned
import com.saveourtool.save.utils.AUTHORIZATION_SOURCE
import com.saveourtool.save.utils.getLogger
import arrow.core.getOrElse
import io.ktor.client.plugins.auth.providers.BasicAuthCredentials
import io.ktor.client.plugins.auth.providers.basic
import io.ktor.client.request.headers
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assumptions.assumeThat
import org.junit.jupiter.api.AfterAll
Expand Down Expand Up @@ -184,13 +182,7 @@ class SaveBackendTest {
requestTimeoutMillis = SECONDS.toMillis(500L)
) {
basic {
sendWithoutRequest { requestBuilder ->
requestBuilder.headers {
this[AUTHORIZATION_SOURCE] = authorizationSource
}

true
}
sendWithoutRequest { true }

credentials {
BasicAuthCredentials(username = user, password = passwordOrToken)
Expand Down
34 changes: 21 additions & 13 deletions src/test/kotlin/com/saveourtool/save/api/SaveBackendUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package com.saveourtool.save.api
import com.saveourtool.save.testsuite.TestSuiteVersioned
import org.assertj.core.api.Assumptions.assumeThat

private const val DEFAULT_AUTHORIZATION_SOURCE = "basic"
private const val DEFAULT_BACKEND_URL = "http://localhost:5800"
private const val DEFAULT_ORGANIZATION_NAME = "saveourtool"
private const val DEFAULT_PASSWORD = ""
Expand All @@ -21,7 +20,7 @@ internal const val TEST_TIMEOUT_MINUTES = 20L
@Suppress("CUSTOM_GETTERS_SETTERS")
internal val backendUrl: String
get() {
val backendUrlOrEmpty = System.getProperty("save-cloud.backend.url", DEFAULT_BACKEND_URL)
val backendUrlOrEmpty = getenvOrProperty("save-cloud.backend.url", DEFAULT_BACKEND_URL)

return when {
backendUrlOrEmpty.isEmpty() -> DEFAULT_BACKEND_URL
Expand All @@ -32,20 +31,15 @@ internal val backendUrl: String
@Suppress("CUSTOM_GETTERS_SETTERS")
internal val user: String
get() =
System.getProperty("save-cloud.user", DEFAULT_USER)
getenvOrProperty("save-cloud.user", DEFAULT_USER)

/**
* @return either the password or the _personal access token_.
*/
@Suppress("CUSTOM_GETTERS_SETTERS")
internal val passwordOrToken: String
get() =
System.getProperty("save-cloud.password", DEFAULT_PASSWORD)

@Suppress("CUSTOM_GETTERS_SETTERS")
internal val authorizationSource: String
get() =
System.getProperty("save-cloud.user.auth.source", DEFAULT_AUTHORIZATION_SOURCE)
getenvOrProperty("save-cloud.password", DEFAULT_PASSWORD)

@Suppress("CUSTOM_GETTERS_SETTERS")
internal val organizationName: String
Expand All @@ -55,15 +49,15 @@ internal val organizationName: String
@Suppress("CUSTOM_GETTERS_SETTERS")
internal val projectName: String
get() =
System.getProperty("save-cloud.project.name", DEFAULT_PROJECT_NAME)
getenvOrProperty("save-cloud.project.name", DEFAULT_PROJECT_NAME)

@Suppress(
"NO_CORRESPONDING_PROPERTY",
"CUSTOM_GETTERS_SETTERS",
)
internal val testSuiteIds: Set<Long>
get() {
val rawTestSuiteIds = System.getProperty("save-cloud.test.suite.ids")
val rawTestSuiteIds = getenvOrProperty("save-cloud.test.suite.ids")
?: return emptySet()

return rawTestSuiteIds
Expand All @@ -77,7 +71,7 @@ internal val testSuiteIds: Set<Long>
@Suppress("CUSTOM_GETTERS_SETTERS")
internal val testVersion: String?
get() {
val rawTestVersion = System.getProperty("save-cloud.test.version", DEFAULT_TEST_VERSION)
val rawTestVersion = getenvOrProperty("save-cloud.test.version", DEFAULT_TEST_VERSION)

return when {
rawTestVersion.isEmpty() -> null
Expand All @@ -89,7 +83,7 @@ internal val testVersion: String?
@Suppress("CUSTOM_GETTERS_SETTERS")
internal val testLanguage: String?
get() {
val rawTestLanguage = System.getProperty("save-cloud.test.language", DEFAULT_TEST_LANGUAGE)
val rawTestLanguage = getenvOrProperty("save-cloud.test.language", DEFAULT_TEST_LANGUAGE)

return when {
rawTestLanguage.isEmpty() -> null
Expand Down Expand Up @@ -152,3 +146,17 @@ internal fun List<TestSuiteVersioned>.withinOrganization(): List<TestSuiteVersio
private fun TestSuiteVersioned.hasVersion(version: String?): Boolean =
this.version == version ||
(version != null && this.version.matches(Regex("""^\Q$version\E\h+\([0-9A-Fa-f]+\)$""")))

/**
* @param name env name or property name.
* @return env value or property value if env is missed.
*/
private fun getenvOrProperty(name: String): String? =
System.getenv(name) ?: System.getProperty(name)

/**
* @param name env name or property name.
* @param defaultValue value when env and property are missed.
* @return env value or property value if env is missed.
*/
private fun getenvOrProperty(name: String, defaultValue: String): String = getenvOrProperty(name) ?: defaultValue

0 comments on commit 28ad32c

Please sign in to comment.