From 9a244b3918a663a11729802add54765fc85d9ccb Mon Sep 17 00:00:00 2001 From: Jonas Natten Date: Tue, 29 Aug 2023 07:36:14 +0200 Subject: [PATCH] integration-tests: Fix tests after fixing explicit auth to `NdlaClient` --- .../draftapi/DraftApiClientTest.scala | 37 ------------------- .../articleapi/ArticleApiClientTest.scala | 14 ++++--- 2 files changed, 8 insertions(+), 43 deletions(-) diff --git a/integration-tests/src/test/scala/no/ndla/integrationtests/articleapi/draftapi/DraftApiClientTest.scala b/integration-tests/src/test/scala/no/ndla/integrationtests/articleapi/draftapi/DraftApiClientTest.scala index 5bbf14013c..6616e7359b 100644 --- a/integration-tests/src/test/scala/no/ndla/integrationtests/articleapi/draftapi/DraftApiClientTest.scala +++ b/integration-tests/src/test/scala/no/ndla/integrationtests/articleapi/draftapi/DraftApiClientTest.scala @@ -7,11 +7,9 @@ package no.ndla.integrationtests.articleapi.draftapi -import no.ndla.articleapi.model.api import no.ndla.common.model.NDLADate import no.ndla.draftapi.DraftApiProperties import no.ndla.integrationtests.UnitSuite -import no.ndla.network.AuthUser import no.ndla.scalatestsuite.IntegrationSuite import no.ndla.{articleapi, draftapi} import org.eclipse.jetty.server.Server @@ -49,39 +47,4 @@ class DraftApiClientTest draftApiServer.stop() } - private def setupAgreements() = - (1L to 10) - .map(id => { - draftApi.componentRegistry.agreementRepository.insert( - draftapi.TestData.sampleBySaDomainAgreement.copy(id = Some(id)) - ) - }) - - test("should be able to fetch agreements' copyright") { - setupAgreements() - - val expectedCopyright = api.Copyright( - api.License( - "CC-BY-SA-4.0", - Some("Creative Commons Attribution-ShareAlike 4.0 International"), - Some("https://creativecommons.org/licenses/by-sa/4.0/") - ), - "Origin", - Seq.empty, - Seq.empty, - Seq.empty, - None, - None, - None - ) - - val exampleToken = - "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlF6bEVPVFE1TTBOR01EazROakV4T0VKR01qYzJNalZGT0RoRVFrRTFOVUkyTmtFMFJUUXlSZyJ9.eyJodHRwczovL25kbGEubm8vbmRsYV9pZCI6IjQyWDkxUmEyY0M0d0xQSDZhUHloajVWQSIsImh0dHBzOi8vbmRsYS5uby91c2VyX25hbWUiOiJIdXJkaUR1cmR5IiwiaHR0cHM6Ly9uZGxhLm5vL2NsaWVudF9pZCI6IktFMjZMTTJSS05heFBsS1c5M0xMTGtPc0Vnb01Ma3BXIiwiaXNzIjoiaHR0cHM6Ly9uZGxhLXRlc3QuZXUuYXV0aDAuY29tLyIsInN1YiI6Imdvb2dsZS1vYXV0aDIiLCJhdWQiOiJuZGxhX3N5c3RlbSIsImlhdCI6MTU0NzQ1ODExNiwiZXhwIjoxNTQ3NDY1MzE2LCJhenAiOiJGSzM1RkQzWUhPZWFZY1hHODBFVkNiQm1BZmlGR3ppViIsInNjb3BlIjoibGlzdGluZzp3cml0ZSBkcmFmdHM6YWRtaW4gbGVhcm5pbmdwYXRoOmFkbWluIGRyYWZ0czpzZXRfdG9fcHVibGlzaCBhdWRpbzp3cml0ZSBpbWFnZXM6d3JpdGUgY29uY2VwdDp3cml0ZSBkcmFmdHM6d3JpdGUgdGF4b25vbXk6d3JpdGUgYXJ0aWNsZXM6d3JpdGUgIn0K.hgk3TpqXpCerofnVaE17ZH7r4Cr3ehaiOl95hsipQrL9OuJvzDx1Y7-DrGfk6Y3-cE4qwScEahpYVf_aOIuXPNNKfbtRYPV3H84T1B02j1olhlLzEbJ-BGyvN2J6CpVy2PHfSUpTVjOMB7q4IDti2NUlhYSXCY4_ZAZhN20wXqID71ZjWqwNRJh1xUXfBQFOkFkCRxgYgEUA_oBrVBgx66iXhIrTDVcGPNyLRui40LMDnQFTU7lel-c1BdK393MHq9lQq5Yg3x5tFJ3k3HA682_UCiN8HzNvLaE5bUyskXPT-Qy57uWNuO0bpUkiRxB2rYwUR5OGYSCWz9fSbIKptQ" - - AuthUser.setHeader(s"Bearer $exampleToken") - val draftApiClient = new DraftApiClient(draftApiBaseUrl) - val copyright = draftApiClient.getAgreementCopyright(1) - copyright.get should be(expectedCopyright) - } - } diff --git a/integration-tests/src/test/scala/no/ndla/integrationtests/draftapi/articleapi/ArticleApiClientTest.scala b/integration-tests/src/test/scala/no/ndla/integrationtests/draftapi/articleapi/ArticleApiClientTest.scala index c4d20fcf9b..2bcdcecd54 100644 --- a/integration-tests/src/test/scala/no/ndla/integrationtests/draftapi/articleapi/ArticleApiClientTest.scala +++ b/integration-tests/src/test/scala/no/ndla/integrationtests/draftapi/articleapi/ArticleApiClientTest.scala @@ -14,6 +14,7 @@ import no.ndla.common.model.{NDLADate, domain => common} import no.ndla.draftapi.model.api.ContentId import no.ndla.integrationtests.UnitSuite import no.ndla.network.AuthUser +import no.ndla.network.tapir.auth.TokenUser import no.ndla.scalatestsuite.IntegrationSuite import org.json4s.Formats import org.testcontainers.containers.PostgreSQLContainer @@ -67,7 +68,6 @@ class ArticleApiClientTest Seq.empty, Seq.empty, None, - None, None ) @@ -114,6 +114,7 @@ class ArticleApiClientTest val exampleToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6Ik9FSTFNVVU0T0RrNU56TTVNekkyTXpaRE9EazFOMFl3UXpkRE1EUXlPRFZDUXpRM1FUSTBNQSJ9.eyJodHRwczovL25kbGEubm8vbmRsYV9pZCI6Inh4eHl5eSIsImlzcyI6Imh0dHBzOi8vbmRsYS5ldS5hdXRoMC5jb20vIiwic3ViIjoieHh4eXl5QGNsaWVudHMiLCJhdWQiOiJuZGxhX3N5c3RlbSIsImlhdCI6MTUxMDMwNTc3MywiZXhwIjoxNTEwMzkyMTczLCJwZXJtaXNzaW9ucyI6WyJhcnRpY2xlczpwdWJsaXNoIiwiZHJhZnRzOndyaXRlIiwiZHJhZnRzOnNldF90b19wdWJsaXNoIiwiYXJ0aWNsZXM6d3JpdGUiXSwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIn0.v6q6y6owx9VXri1h4FJJHDAnMllmNYFAAT2b9CJLm88" val authHeaderMap: Map[String, String] = Map("Authorization" -> s"Bearer $exampleToken") + val authUser = TokenUser.SystemUser.copy(originalToken = Some(exampleToken)) class LocalArticleApiTestData extends articleapi.Props with articleapi.TestData { override val props: ArticleApiProperties = articleApiProperties @@ -150,7 +151,8 @@ class ArticleApiClientTest testArticle, List("1234"), useImportValidation = false, - useSoftValidation = false + useSoftValidation = false, + authUser ) response.isSuccess should be(true) } @@ -160,14 +162,14 @@ class ArticleApiClientTest val contentId = ContentId(1) AuthUser.setHeader(s"Bearer $exampleToken") val articleApiClient = new ArticleApiClient(articleApiBaseUrl) - articleApiClient.deleteArticle(1).get should be(contentId) + articleApiClient.deleteArticle(1, authUser).get should be(contentId) } test("that unpublishing an article returns 200") { dataFixer.setupArticles() AuthUser.setHeader(s"Bearer $exampleToken") val articleApiCient = new ArticleApiClient(articleApiBaseUrl) - articleApiCient.unpublishArticle(testArticle).get + articleApiCient.unpublishArticle(testArticle, authUser).get } test("that verifying an article returns 200 if valid") { @@ -175,7 +177,7 @@ class ArticleApiClientTest val articleApiCient = new ArticleApiClient(articleApiBaseUrl) val result = converterService .toArticleApiArticle(testArticle) - .flatMap(article => articleApiCient.validateArticle(article, importValidate = false)) + .flatMap(article => articleApiCient.validateArticle(article, importValidate = false, None)) println(result) result.isSuccess should be(true) } @@ -185,7 +187,7 @@ class ArticleApiClientTest val articleApiCient = new ArticleApiClient(articleApiBaseUrl) val result = converterService .toArticleApiArticle(testArticle.copy(title = Seq(common.Title("", "nb")))) - .flatMap(article => articleApiCient.validateArticle(article, importValidate = false)) + .flatMap(article => articleApiCient.validateArticle(article, importValidate = false, None)) result.isSuccess should be(false) } }