diff --git a/tests/e2e-tests/src/test/kotlin/common/Agents.kt b/tests/e2e-tests/src/test/kotlin/common/Agents.kt index 0b800e3c7a..c01dca7a04 100644 --- a/tests/e2e-tests/src/test/kotlin/common/Agents.kt +++ b/tests/e2e-tests/src/test/kotlin/common/Agents.kt @@ -15,22 +15,16 @@ object Agents { lateinit var Faber: Actor private set - init { - if (Environments.AGENT_AUTH_REQUIRED) { - SerenityRest.setDefaultRequestSpecification( - RequestSpecBuilder().addHeader( - Environments.AGENT_AUTH_HEADER, - Environments.AGENT_AUTH_KEY, - ) - .build(), - ) - } - } - fun createAgents() { Acme = Actor.named("Acme").whoCan(CallAnApi.at(Environments.ACME_AGENT_URL)) Bob = Actor.named("Bob").whoCan(CallAnApi.at(Environments.BOB_AGENT_URL)) Mallory = Actor.named("Mallory").whoCan(CallAnApi.at(Environments.MALLORY_AGENT_URL)) Faber = Actor.named("Faber").whoCan(CallAnApi.at(Environments.FABER_AGENT_URL)) + if (Environments.AGENT_AUTH_REQUIRED) { + Acme.remember("AUTH_KEY", Environments.ACME_AUTH_KEY) + Bob.remember("AUTH_KEY", Environments.BOB_AUTH_KEY) + Mallory.remember("AUTH_KEY", Environments.MALLORY_AUTH_KEY) + Faber.remember("AUTH_KEY", Environments.FABER_AUTH_KEY) + } } } diff --git a/tests/e2e-tests/src/test/kotlin/common/Environments.kt b/tests/e2e-tests/src/test/kotlin/common/Environments.kt index b00f7bff37..5804346985 100644 --- a/tests/e2e-tests/src/test/kotlin/common/Environments.kt +++ b/tests/e2e-tests/src/test/kotlin/common/Environments.kt @@ -3,9 +3,12 @@ package common object Environments { val AGENT_AUTH_REQUIRED: Boolean = System.getenv("AGENT_AUTH_REQUIRED").toBoolean() val AGENT_AUTH_HEADER = System.getenv("AGENT_AUTH_HEADER") ?: "apikey" - val AGENT_AUTH_KEY = System.getenv("AGENT_AUTH_KEY") ?: "" + val ACME_AUTH_KEY = System.getenv("ACME_AUTH_KEY") ?: "" val ACME_AGENT_URL = System.getenv("ACME_AGENT_URL") ?: "http://localhost:8080/prism-agent" val BOB_AGENT_URL = System.getenv("BOB_AGENT_URL") ?: "http://localhost:8090/prism-agent" + val BOB_AUTH_KEY = System.getenv("BOB_AUTH_KEY") ?: "" val MALLORY_AGENT_URL = System.getenv("MALLORY_AGENT_URL") ?: "http://localhost:8070/prism-agent" + val MALLORY_AUTH_KEY = System.getenv("MALLORY_AUTH_KEY") ?: "" val FABER_AGENT_URL = System.getenv("FABER_AGENT_URL") ?: "http://localhost:8070/prism-agent" + val FABER_AUTH_KEY = System.getenv("FABER_AUTH_KEY") ?: "" } diff --git a/tests/e2e-tests/src/test/kotlin/features/CommonSteps.kt b/tests/e2e-tests/src/test/kotlin/features/CommonSteps.kt index 9d54b304cf..7d23a2c5cd 100644 --- a/tests/e2e-tests/src/test/kotlin/features/CommonSteps.kt +++ b/tests/e2e-tests/src/test/kotlin/features/CommonSteps.kt @@ -15,11 +15,6 @@ import features.issue_credentials.IssueCredentialsSteps import io.cucumber.java.Before import io.cucumber.java.ParameterType import io.cucumber.java.en.Given -import io.restassured.RestAssured -import io.restassured.config.ObjectMapperConfig -import io.restassured.config.ObjectMapperConfig.objectMapperConfig -import io.restassured.config.RestAssuredConfig -import io.restassured.mapper.ObjectMapperType import net.serenitybdd.screenplay.Actor import net.serenitybdd.screenplay.actors.Cast import net.serenitybdd.screenplay.actors.OnStage diff --git a/tests/e2e-tests/src/test/kotlin/features/connection/ConnectionSteps.kt b/tests/e2e-tests/src/test/kotlin/features/connection/ConnectionSteps.kt index f00cb8cbbb..c66ec162a8 100644 --- a/tests/e2e-tests/src/test/kotlin/features/connection/ConnectionSteps.kt +++ b/tests/e2e-tests/src/test/kotlin/features/connection/ConnectionSteps.kt @@ -5,11 +5,11 @@ import api_models.ConnectionState import api_models.Invitation import common.Utils.lastResponseObject import common.Utils.wait +import interactions.Get +import interactions.Post import io.cucumber.java.en.Then import io.cucumber.java.en.When import net.serenitybdd.screenplay.Actor -import net.serenitybdd.screenplay.rest.interactions.Get -import net.serenitybdd.screenplay.rest.interactions.Post import net.serenitybdd.screenplay.rest.questions.ResponseConsequence import org.apache.http.HttpStatus.SC_CREATED import org.apache.http.HttpStatus.SC_OK diff --git a/tests/e2e-tests/src/test/kotlin/features/credential_schemas/CredentialSchemasSteps.kt b/tests/e2e-tests/src/test/kotlin/features/credential_schemas/CredentialSchemasSteps.kt index 70f8271973..147b8d9a12 100644 --- a/tests/e2e-tests/src/test/kotlin/features/credential_schemas/CredentialSchemasSteps.kt +++ b/tests/e2e-tests/src/test/kotlin/features/credential_schemas/CredentialSchemasSteps.kt @@ -10,8 +10,8 @@ import io.cucumber.java.en.Then import io.cucumber.java.en.When import io.restassured.path.json.JsonPath import net.serenitybdd.screenplay.Actor -import net.serenitybdd.screenplay.rest.interactions.Get -import net.serenitybdd.screenplay.rest.interactions.Post +import interactions.Get +import interactions.Post import net.serenitybdd.screenplay.rest.questions.ResponseConsequence import org.apache.http.HttpStatus.* import org.hamcrest.CoreMatchers.* diff --git a/tests/e2e-tests/src/test/kotlin/features/did/DeactivateDidSteps.kt b/tests/e2e-tests/src/test/kotlin/features/did/DeactivateDidSteps.kt index e2865a3ea9..e7124a2b8e 100644 --- a/tests/e2e-tests/src/test/kotlin/features/did/DeactivateDidSteps.kt +++ b/tests/e2e-tests/src/test/kotlin/features/did/DeactivateDidSteps.kt @@ -6,8 +6,8 @@ import common.Utils.lastResponseObject import io.cucumber.java.en.Then import io.cucumber.java.en.When import net.serenitybdd.screenplay.Actor -import net.serenitybdd.screenplay.rest.interactions.Get -import net.serenitybdd.screenplay.rest.interactions.Post +import interactions.Get +import interactions.Post import net.serenitybdd.screenplay.rest.questions.ResponseConsequence import org.apache.http.HttpStatus import org.hamcrest.Matchers diff --git a/tests/e2e-tests/src/test/kotlin/features/did/ManageDidSteps.kt b/tests/e2e-tests/src/test/kotlin/features/did/ManageDidSteps.kt index 826dcde765..f7d599df31 100644 --- a/tests/e2e-tests/src/test/kotlin/features/did/ManageDidSteps.kt +++ b/tests/e2e-tests/src/test/kotlin/features/did/ManageDidSteps.kt @@ -10,8 +10,8 @@ import io.cucumber.java.en.Then import io.cucumber.java.en.When import net.serenitybdd.rest.SerenityRest.lastResponse import net.serenitybdd.screenplay.Actor -import net.serenitybdd.screenplay.rest.interactions.Get -import net.serenitybdd.screenplay.rest.interactions.Post +import interactions.Get +import interactions.Post import net.serenitybdd.screenplay.rest.questions.ResponseConsequence import org.apache.http.HttpStatus.SC_CREATED import org.assertj.core.api.Assertions diff --git a/tests/e2e-tests/src/test/kotlin/features/did/PublishDidSteps.kt b/tests/e2e-tests/src/test/kotlin/features/did/PublishDidSteps.kt index 638a8f2dd5..9e2a67fb06 100644 --- a/tests/e2e-tests/src/test/kotlin/features/did/PublishDidSteps.kt +++ b/tests/e2e-tests/src/test/kotlin/features/did/PublishDidSteps.kt @@ -10,8 +10,8 @@ import io.cucumber.java.en.Then import io.cucumber.java.en.When import net.serenitybdd.rest.SerenityRest import net.serenitybdd.screenplay.Actor -import net.serenitybdd.screenplay.rest.interactions.Get -import net.serenitybdd.screenplay.rest.interactions.Post +import interactions.Get +import interactions.Post import net.serenitybdd.screenplay.rest.questions.ResponseConsequence import org.apache.http.HttpStatus.* import org.assertj.core.api.Assertions.assertThat diff --git a/tests/e2e-tests/src/test/kotlin/features/did/UpdateDidSteps.kt b/tests/e2e-tests/src/test/kotlin/features/did/UpdateDidSteps.kt index aada98bf8c..3d566291de 100644 --- a/tests/e2e-tests/src/test/kotlin/features/did/UpdateDidSteps.kt +++ b/tests/e2e-tests/src/test/kotlin/features/did/UpdateDidSteps.kt @@ -7,8 +7,8 @@ import common.Utils.wait import io.cucumber.java.en.Then import io.cucumber.java.en.When import net.serenitybdd.screenplay.Actor -import net.serenitybdd.screenplay.rest.interactions.Get -import net.serenitybdd.screenplay.rest.interactions.Post +import interactions.Get +import interactions.Post import net.serenitybdd.screenplay.rest.questions.ResponseConsequence import org.apache.http.HttpStatus import org.hamcrest.Matchers.emptyString diff --git a/tests/e2e-tests/src/test/kotlin/features/issue_credentials/IssueCredentialsSteps.kt b/tests/e2e-tests/src/test/kotlin/features/issue_credentials/IssueCredentialsSteps.kt index 23949e2788..bdf431e9ec 100644 --- a/tests/e2e-tests/src/test/kotlin/features/issue_credentials/IssueCredentialsSteps.kt +++ b/tests/e2e-tests/src/test/kotlin/features/issue_credentials/IssueCredentialsSteps.kt @@ -8,8 +8,8 @@ import common.Utils.wait import io.cucumber.java.en.Then import io.cucumber.java.en.When import net.serenitybdd.screenplay.Actor -import net.serenitybdd.screenplay.rest.interactions.Get -import net.serenitybdd.screenplay.rest.interactions.Post +import interactions.Get +import interactions.Post import net.serenitybdd.screenplay.rest.questions.ResponseConsequence import org.apache.http.HttpStatus.SC_CREATED import org.apache.http.HttpStatus.SC_OK diff --git a/tests/e2e-tests/src/test/kotlin/features/present_proof/PresentProofSteps.kt b/tests/e2e-tests/src/test/kotlin/features/present_proof/PresentProofSteps.kt index 2347bbf3d6..9fe3f28751 100644 --- a/tests/e2e-tests/src/test/kotlin/features/present_proof/PresentProofSteps.kt +++ b/tests/e2e-tests/src/test/kotlin/features/present_proof/PresentProofSteps.kt @@ -9,9 +9,9 @@ import common.Utils.wait import io.cucumber.java.en.Then import io.cucumber.java.en.When import net.serenitybdd.screenplay.Actor -import net.serenitybdd.screenplay.rest.interactions.Get -import net.serenitybdd.screenplay.rest.interactions.Patch -import net.serenitybdd.screenplay.rest.interactions.Post +import interactions.Get +import interactions.Post +import interactions.Patch import net.serenitybdd.screenplay.rest.questions.ResponseConsequence import org.apache.http.HttpStatus.SC_CREATED import org.apache.http.HttpStatus.SC_OK diff --git a/tests/e2e-tests/src/test/kotlin/features/system/SystemSteps.kt b/tests/e2e-tests/src/test/kotlin/features/system/SystemSteps.kt index 4ece1f80c0..9835c7246b 100644 --- a/tests/e2e-tests/src/test/kotlin/features/system/SystemSteps.kt +++ b/tests/e2e-tests/src/test/kotlin/features/system/SystemSteps.kt @@ -5,7 +5,7 @@ import common.Utils.lastResponseObject import io.cucumber.java.en.Then import io.cucumber.java.en.When import net.serenitybdd.screenplay.Actor -import net.serenitybdd.screenplay.rest.interactions.Get +import interactions.Get import net.serenitybdd.screenplay.rest.questions.ResponseConsequence import org.apache.http.HttpStatus.SC_OK import org.assertj.core.api.Assertions.assertThat diff --git a/tests/e2e-tests/src/test/kotlin/features/verification_policies/VerificationPoliciesSteps.kt b/tests/e2e-tests/src/test/kotlin/features/verification_policies/VerificationPoliciesSteps.kt index 0ae6b16cf6..c1494036c3 100644 --- a/tests/e2e-tests/src/test/kotlin/features/verification_policies/VerificationPoliciesSteps.kt +++ b/tests/e2e-tests/src/test/kotlin/features/verification_policies/VerificationPoliciesSteps.kt @@ -7,8 +7,8 @@ import io.cucumber.java.en.Then import io.cucumber.java.en.When import net.serenitybdd.rest.SerenityRest import net.serenitybdd.screenplay.Actor -import net.serenitybdd.screenplay.rest.interactions.Post -import net.serenitybdd.screenplay.rest.interactions.Put +import interactions.Put +import interactions.Post import net.serenitybdd.screenplay.rest.questions.ResponseConsequence import org.apache.http.HttpStatus import org.hamcrest.CoreMatchers diff --git a/tests/e2e-tests/src/test/kotlin/interactions/Delete.kt b/tests/e2e-tests/src/test/kotlin/interactions/Delete.kt new file mode 100644 index 0000000000..76d7af80d0 --- /dev/null +++ b/tests/e2e-tests/src/test/kotlin/interactions/Delete.kt @@ -0,0 +1,30 @@ +package interactions + +import common.Environments +import net.serenitybdd.screenplay.Actor +import net.serenitybdd.screenplay.Tasks +import net.serenitybdd.screenplay.rest.abilities.CallAnApi +import net.serenitybdd.screenplay.rest.interactions.RestInteraction +import net.thucydides.core.annotations.Step + + +/** + * This class is a copy of the class Delete from serenity rest interactions + * to add a custom authentication header to the request on-the-fly. + */ +open class Delete(private val resource: String) : RestInteraction() { + @Step("{0} executes a DELETE on the resource #resource") + override fun performAs(actor: T) { + val spec = rest() + if (Environments.AGENT_AUTH_REQUIRED) { + spec.header(Environments.AGENT_AUTH_HEADER, actor!!.recall("AUTH_KEY")) + } + spec.delete(CallAnApi.`as`(actor).resolve(resource)) + } + + companion object { + fun from(resource: String?): Delete { + return Tasks.instrumented(Delete::class.java, resource) + } + } +} diff --git a/tests/e2e-tests/src/test/kotlin/interactions/Get.kt b/tests/e2e-tests/src/test/kotlin/interactions/Get.kt new file mode 100644 index 0000000000..192a29c765 --- /dev/null +++ b/tests/e2e-tests/src/test/kotlin/interactions/Get.kt @@ -0,0 +1,29 @@ +package interactions + +import common.Environments +import net.serenitybdd.screenplay.Actor +import net.serenitybdd.screenplay.Tasks +import net.serenitybdd.screenplay.rest.abilities.CallAnApi +import net.serenitybdd.screenplay.rest.interactions.RestInteraction +import net.thucydides.core.annotations.Step + +/** + * This class is a copy of the class Get from serenity rest interactions + * to add a custom authentication header to the request on-the-fly. + */ +open class Get(private val resource: String) : RestInteraction() { + @Step("{0} executes a GET on the resource #resource") + override fun performAs(actor: T) { + val spec = rest() + if (Environments.AGENT_AUTH_REQUIRED) { + spec.header(Environments.AGENT_AUTH_HEADER, actor!!.recall("AUTH_KEY")) + } + spec.get(CallAnApi.`as`(actor).resolve(resource)) + } + + companion object { + fun resource(resource: String?): Get { + return Tasks.instrumented(Get::class.java, resource) + } + } +} diff --git a/tests/e2e-tests/src/test/kotlin/interactions/Patch.kt b/tests/e2e-tests/src/test/kotlin/interactions/Patch.kt new file mode 100644 index 0000000000..cb2901f042 --- /dev/null +++ b/tests/e2e-tests/src/test/kotlin/interactions/Patch.kt @@ -0,0 +1,29 @@ +package interactions + +import common.Environments +import net.serenitybdd.screenplay.Actor +import net.serenitybdd.screenplay.Tasks +import net.serenitybdd.screenplay.rest.abilities.CallAnApi +import net.serenitybdd.screenplay.rest.interactions.RestInteraction +import net.thucydides.core.annotations.Step + +/** + * This class is a copy of the class Patch from serenity rest interactions + * to add a custom authentication header to the request on-the-fly. + */ +open class Patch(private val resource: String) : RestInteraction() { + @Step("{0} executes a PATCH on the resource #resource") + override fun performAs(actor: T) { + val spec = rest() + if (Environments.AGENT_AUTH_REQUIRED) { + spec.header(Environments.AGENT_AUTH_HEADER, actor!!.recall("AUTH_KEY")) + } + spec.patch(CallAnApi.`as`(actor).resolve(resource)) + } + + companion object { + fun to(resource: String?): Patch { + return Tasks.instrumented(Patch::class.java, resource) + } + } +} diff --git a/tests/e2e-tests/src/test/kotlin/interactions/Post.kt b/tests/e2e-tests/src/test/kotlin/interactions/Post.kt new file mode 100644 index 0000000000..5810159e3d --- /dev/null +++ b/tests/e2e-tests/src/test/kotlin/interactions/Post.kt @@ -0,0 +1,29 @@ +package interactions + +import common.Environments +import net.serenitybdd.screenplay.Actor +import net.serenitybdd.screenplay.Tasks +import net.serenitybdd.screenplay.rest.abilities.CallAnApi +import net.serenitybdd.screenplay.rest.interactions.RestInteraction +import net.thucydides.core.annotations.Step + +/** + * This class is a copy of the class Post from serenity rest interactions + * to add a custom authentication header to the request on-the-fly. + */ +open class Post(private val resource: String) : RestInteraction() { + @Step("{0} executes a POST on the resource #resource") + override fun performAs(actor: T) { + val spec = rest() + if (Environments.AGENT_AUTH_REQUIRED) { + spec.header(Environments.AGENT_AUTH_HEADER, actor!!.recall("AUTH_KEY")) + } + spec.post(CallAnApi.`as`(actor).resolve(resource)) + } + + companion object { + fun to(resource: String?): Post { + return Tasks.instrumented(Post::class.java, resource) + } + } +} diff --git a/tests/e2e-tests/src/test/kotlin/interactions/Put.kt b/tests/e2e-tests/src/test/kotlin/interactions/Put.kt new file mode 100644 index 0000000000..29ecc62bb3 --- /dev/null +++ b/tests/e2e-tests/src/test/kotlin/interactions/Put.kt @@ -0,0 +1,30 @@ +package interactions + +import common.Environments +import net.serenitybdd.screenplay.Actor +import net.serenitybdd.screenplay.Tasks +import net.serenitybdd.screenplay.rest.abilities.CallAnApi +import net.serenitybdd.screenplay.rest.interactions.RestInteraction +import net.thucydides.core.annotations.Step + + +/** + * This class is a copy of the class Put from serenity rest interactions + * to add a custom authentication header to the request on-the-fly. + */ +open class Put(private val resource: String) : RestInteraction() { + @Step("{0} executes a PUT on the resource #resource") + override fun performAs(actor: T) { + val spec = rest() + if (Environments.AGENT_AUTH_REQUIRED) { + spec.header(Environments.AGENT_AUTH_HEADER, actor!!.recall("AUTH_KEY")) + } + spec.put(CallAnApi.`as`(actor).resolve(resource)) + } + + companion object { + fun to(resource: String?): Put { + return Tasks.instrumented(Put::class.java, resource) + } + } +}