Skip to content
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

Removed authorizationSource from header + prefix in username #71

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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 @@ -72,7 +70,7 @@
@Timeout(TEST_TIMEOUT_MINUTES, unit = MINUTES)
fun `contest mode`() {
with(client) {
runBlocking {

Check failure on line 73 in src/test/kotlin/com/saveourtool/save/api/SaveBackendTest.kt

View workflow job for this annotation

GitHub Actions / JUnit Tests (dorny/test-reporter)

com.saveourtool.save.api.SaveBackendTest ► contest mode()

Failed test found in: build/test-results/test/TEST-com.saveourtool.save.api.SaveBackendTest.xml Error: java.util.concurrent.TimeoutException: contest mode() timed out after 20 minutes
Raw output
java.util.concurrent.TimeoutException: contest mode() timed out after 20 minutes
	at org.junit.jupiter.engine.extension.TimeoutExceptionFactory.create(TimeoutExceptionFactory.java:29)
	at org.junit.jupiter.engine.extension.SameThreadTimeoutInvocation.proceed(SameThreadTimeoutInvocation.java:58)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:218)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:214)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:139)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:62)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at jdk.proxy1/jdk.proxy1.$Proxy2.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
	Suppressed: java.lang.InterruptedException
		at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:84)
		at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
		at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
		at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
		at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
		at com.saveourtool.save.api.SaveBackendTest.contest mode(SaveBackendTest.kt:73)
		at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
		at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
		at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
		at java.base/java.lang.reflect.Method.invoke(Method.java:568)
		at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:728)
		at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
		at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
		at org.junit.jupiter.engine.extension.SameThreadTimeoutInvocation.proceed(SameThreadTimeoutInvocation.java:45)
		... 78 more
val contest = organization.listActiveContests(project.name)
.getOrElse(SaveCloudError::fail)
.firstOrNull { contest ->
Expand Down Expand Up @@ -184,13 +182,7 @@
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
Loading