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

[WM-2555] Cromwell -> ECM contract test #7405

Merged
merged 4 commits into from
Apr 12, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.broadinstitute.dsde.workbench.cromwell.consumer

import au.com.dius.pact.consumer.dsl._
import au.com.dius.pact.consumer.{ConsumerPactBuilder, PactTestExecutionContext}
import au.com.dius.pact.core.model.RequestResponsePact
import cromwell.core.TestKitSuite
import cromwell.services.auth.GithubAuthVending.{GithubToken, TerraToken}
import cromwell.services.auth.ecm.EcmService
import org.scalatest.flatspec.AnyFlatSpecLike

import scala.concurrent.{Await, ExecutionContextExecutor}
import org.scalatest.matchers.should.Matchers
import pact4s.scalatest.RequestResponsePactForger

import scala.concurrent.duration.DurationInt

class EcmServiceContractSpec extends TestKitSuite with AnyFlatSpecLike with Matchers with RequestResponsePactForger {

implicit val ec: ExecutionContextExecutor = system.dispatcher

/*
Define the folder that the pact contracts get written to upon completion of this test suite.
*/
override val pactTestExecutionContext: PactTestExecutionContext =
new PactTestExecutionContext(
"./target/pacts"
)

val consumerPactBuilder: ConsumerPactBuilder = ConsumerPactBuilder
.consumer("cromwell")

val pactProvider: PactDslWithProvider = consumerPactBuilder
.hasPactWith("ecm")

var testUser: String = "[email protected]"
var testBearerToken: String = "cromwellBearerToken"
var testGithubToken: String = "githubToken"

var pactDslResponse: PactDslResponse = pactProvider
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally added another buildInteraction helper method, but it seemed cleaner to do this directly

.`given`("a user is registered",
Map[String, String](
"userEmail" -> testUser,
"bearerToken" -> testBearerToken
)
)
.uponReceiving("a github token request")
.method("GET")
.path("/api/oauth/v1/github/access-token")
.headers(Map[String, String]("Authorization" -> s"Bearer $testBearerToken"))
.willRespondWith()
.status(200)
.bodyMatchingContentType("text/plain", testGithubToken)

override val pact: RequestResponsePact = pactDslResponse.toPact

it should "get a github token" in {
Await.result(
new EcmService(mockServer.getUrl)
.getGithubAccessToken(TerraToken(testBearerToken)),
10.seconds
) shouldBe GithubToken(testGithubToken)
}
}
Loading