Skip to content

Commit

Permalink
chore: Remove @accessible (Scala3 preparation) (#3183)
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone authored Apr 11, 2024
1 parent 5a3374a commit 993538d
Show file tree
Hide file tree
Showing 35 changed files with 1,948 additions and 1,613 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ trait TestStartupUtils extends LazyLogging {
tss <- ZIO.service[TriplestoreService]
_ <- tss.resetTripleStoreContent(rdfDataObjects).timeout(480.seconds)
_ <- ZIO.logInfo("... loading test data done.")
_ <- OntologyCache.loadOntologies(KnoraSystemInstances.Users.SystemUser).orDie
_ <- ZIO.serviceWithZIO[OntologyCache](_.loadOntologies(KnoraSystemInstances.Users.SystemUser)).orDie
} yield ()

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.knora.webapi.e2e.admin

import org.apache.pekko.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.model.headers.BasicHttpCredentials
import zio.ZIO

import org.knora.webapi.E2ESpec
import org.knora.webapi.messages.admin.responder.projectsmessages.PermissionCodeAndProjectRestrictedViewSettings
Expand All @@ -28,7 +29,7 @@ class AdminFilesE2ESpec extends E2ESpec with TriplestoreJsonProtocol {
private val normalUserEmail = SharedTestDataADM2.normalUser.userData.email.get
private val testPass = "test"

val KnoraAuthenticationCookieName = UnsafeZioRun.runOrThrow(Authenticator.calculateCookieName())
val KnoraAuthenticationCookieName = UnsafeZioRun.runOrThrow(ZIO.serviceWith[Authenticator](_.calculateCookieName()))

override lazy val rdfDataObjects = List(
RdfDataObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.knora.webapi.e2e.v2

import org.apache.pekko
import zio.ZIO

import scala.concurrent.Await
import scala.concurrent.duration._
Expand Down Expand Up @@ -181,17 +182,19 @@ class AuthenticationV2E2ESpec extends E2ESpec with AuthenticationV2JsonProtocol
}

"authenticate with token in cookie" in {
val KnoraAuthenticationCookieName = UnsafeZioRun.runOrThrow(Authenticator.calculateCookieName())
val cookieHeader = headers.Cookie(KnoraAuthenticationCookieName, token.get)
val KnoraAuthenticationCookieName =
UnsafeZioRun.runOrThrow(ZIO.serviceWith[Authenticator](_.calculateCookieName()))
val cookieHeader = headers.Cookie(KnoraAuthenticationCookieName, token.get)

val request = Get(baseApiUrl + "/v2/authentication") ~> addHeader(cookieHeader)
val response = singleAwaitingRequest(request)
assert(response.status === StatusCodes.OK)
}

"fail authentication with invalid token in cookie" in {
val KnoraAuthenticationCookieName = UnsafeZioRun.runOrThrow(Authenticator.calculateCookieName())
val cookieHeader = headers.Cookie(KnoraAuthenticationCookieName, "not_a_valid_token")
val KnoraAuthenticationCookieName =
UnsafeZioRun.runOrThrow(ZIO.serviceWith[Authenticator](_.calculateCookieName()))
val cookieHeader = headers.Cookie(KnoraAuthenticationCookieName, "not_a_valid_token")

val request = Get(baseApiUrl + "/v2/authentication") ~> addHeader(cookieHeader)
val response = singleAwaitingRequest(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.knora.webapi.it.v2
import org.apache.pekko.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.model.headers.BasicHttpCredentials
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
import zio.ZIO

import java.nio.file.Files
import java.nio.file.Paths
Expand Down Expand Up @@ -64,8 +65,9 @@ class KnoraSipiAuthenticationITSpec

"successfully get an image with provided credentials inside cookie" in {
// using cookie to authenticate when accessing sipi (test for cookie parsing in sipi)
val KnoraAuthenticationCookieName = UnsafeZioRun.runOrThrow(Authenticator.calculateCookieName())
val cookieHeader = headers.Cookie(KnoraAuthenticationCookieName, loginToken)
val KnoraAuthenticationCookieName =
UnsafeZioRun.runOrThrow(ZIO.serviceWith[Authenticator](_.calculateCookieName()))
val cookieHeader = headers.Cookie(KnoraAuthenticationCookieName, loginToken)

// Request the permanently stored image from Sipi.
val sipiGetImageRequest =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ class UserRestServiceSpec extends CoreSpec with ImplicitSender {
// need to be able to authenticate credentials with new password
val cedId = CredentialsIdentifier.UsernameIdentifier(Username.unsafeFrom(normalUser.username))
val credentials = KnoraCredentialsV2.KnoraPasswordCredentialsV2(cedId, newPassword.value)
val resF = UnsafeZioRun.runToFuture(Authenticator.authenticateCredentialsV2(Some(credentials)))
val resF =
UnsafeZioRun.runToFuture(ZIO.serviceWithZIO[Authenticator](_.authenticateCredentialsV2(Some(credentials))))

resF map { res => assert(res) }
}
Expand All @@ -309,7 +310,8 @@ class UserRestServiceSpec extends CoreSpec with ImplicitSender {
// need to be able to authenticate credentials with new password
val cedId = CredentialsIdentifier.UsernameIdentifier(Username.unsafeFrom(normalUser.username))
val credentials = KnoraCredentialsV2.KnoraPasswordCredentialsV2(cedId, "test654321")
val resF = UnsafeZioRun.runToFuture(Authenticator.authenticateCredentialsV2(Some(credentials)))
val resF =
UnsafeZioRun.runToFuture(ZIO.serviceWithZIO[Authenticator](_.authenticateCredentialsV2(Some(credentials))))

resF map { res => assert(res) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.knora.webapi.responders.v2

import org.apache.pekko
import zio.ZIO

import org.knora.webapi.CoreSpec
import org.knora.webapi.messages.store.triplestoremessages.RdfDataObject
Expand Down Expand Up @@ -35,13 +36,13 @@ class LoadOntologiesSpec extends CoreSpec with ImplicitSender {
rdfDataObjs: List[RdfDataObject],
): Either[Status.Failure, SuccessResponseV2] = {
UnsafeZioRun.runOrThrow(
TriplestoreService
.resetTripleStoreContent(rdfDataObjs)
ZIO
.serviceWithZIO[TriplestoreService](_.resetTripleStoreContent(rdfDataObjs))
.timeout(java.time.Duration.ofMinutes(5)),
)

UnsafeZioRun
.run(OntologyCache.loadOntologies(KnoraSystemInstances.Users.SystemUser))
.run(ZIO.serviceWithZIO[OntologyCache](_.loadOntologies(KnoraSystemInstances.Users.SystemUser)))
.toEither
.map(_ => SuccessResponseV2("OK"))
.left
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,9 @@ class OntologyResponderV2Spec extends CoreSpec with ImplicitSender {
assert(!cachedMetadataResponse.ontologies.exists(_.ontologyIri == fooIri.get.toSmartIri))

// Reload the ontologies from the triplestore and check again.
UnsafeZioRun.runOrThrow(OntologyCache.loadOntologies(KnoraSystemInstances.Users.SystemUser))
UnsafeZioRun.runOrThrow(
ZIO.serviceWithZIO[OntologyCache](_.loadOntologies(KnoraSystemInstances.Users.SystemUser)),
)

appActor ! OntologyMetadataGetByProjectRequestV2(
requestingUser = imagesUser,
Expand Down Expand Up @@ -777,7 +779,9 @@ class OntologyResponderV2Spec extends CoreSpec with ImplicitSender {
}

// Reload the ontology cache and see if we get the same result.
UnsafeZioRun.runOrThrow(OntologyCache.loadOntologies(KnoraSystemInstances.Users.SystemUser))
UnsafeZioRun.runOrThrow(
ZIO.serviceWithZIO[OntologyCache](_.loadOntologies(KnoraSystemInstances.Users.SystemUser)),
)

appActor ! PropertiesGetRequestV2(
propertyIris = Set(propertyIri),
Expand Down Expand Up @@ -885,7 +889,9 @@ class OntologyResponderV2Spec extends CoreSpec with ImplicitSender {
}

// Reload the ontology cache and see if we get the same result.
UnsafeZioRun.runOrThrow(OntologyCache.loadOntologies(KnoraSystemInstances.Users.SystemUser))
UnsafeZioRun.runOrThrow(
ZIO.serviceWithZIO[OntologyCache](_.loadOntologies(KnoraSystemInstances.Users.SystemUser)),
)

appActor ! PropertiesGetRequestV2(
propertyIris = Set(propertyIri),
Expand Down Expand Up @@ -3732,7 +3738,9 @@ class OntologyResponderV2Spec extends CoreSpec with ImplicitSender {
}

// Reload the ontology cache and see if we get the same result.
UnsafeZioRun.runOrThrow(OntologyCache.loadOntologies(KnoraSystemInstances.Users.SystemUser))
UnsafeZioRun.runOrThrow(
ZIO.serviceWithZIO[OntologyCache](_.loadOntologies(KnoraSystemInstances.Users.SystemUser)),
)

appActor ! linkPropGetRequest

Expand Down Expand Up @@ -5784,17 +5792,19 @@ class OntologyResponderV2Spec extends CoreSpec with ImplicitSender {

// Check that the correct blank nodes were stored for the cardinalities.
val actual = UnsafeZioRun.runOrThrow(
TriplestoreService.query(
Select(
"""PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
|SELECT ?cardinalityProp
|WHERE {
| <http://www.knora.org/ontology/0001/anything#TestClass> rdfs:subClassOf ?restriction .
| FILTER isBlank(?restriction)
| ?restriction owl:onProperty ?cardinalityProp .
|}""".stripMargin,
ZIO.serviceWithZIO[TriplestoreService](
_.query(
Select(
"""PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
|SELECT ?cardinalityProp
|WHERE {
| <http://www.knora.org/ontology/0001/anything#TestClass> rdfs:subClassOf ?restriction .
| FILTER isBlank(?restriction)
| ?restriction owl:onProperty ?cardinalityProp .
|}""".stripMargin,
),
),
),
)
Expand Down Expand Up @@ -6088,17 +6098,19 @@ class OntologyResponderV2Spec extends CoreSpec with ImplicitSender {

// Check that the correct blank nodes were stored for the cardinalities.
val actual = UnsafeZioRun.runOrThrow(
TriplestoreService.query(
Select(
"""PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
|SELECT ?cardinalityProp
|WHERE {
| <http://www.knora.org/ontology/0001/freetest#BlueFreeTestClass> rdfs:subClassOf ?restriction .
| FILTER isBlank(?restriction)
| ?restriction owl:onProperty ?cardinalityProp .
|}""".stripMargin,
ZIO.serviceWithZIO[TriplestoreService](
_.query(
Select(
"""PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
|SELECT ?cardinalityProp
|WHERE {
| <http://www.knora.org/ontology/0001/freetest#BlueFreeTestClass> rdfs:subClassOf ?restriction .
| FILTER isBlank(?restriction)
| ?restriction owl:onProperty ?cardinalityProp .
|}""".stripMargin,
),
),
),
)
Expand Down
Loading

0 comments on commit 993538d

Please sign in to comment.