Skip to content

Commit

Permalink
refactor: rmove /rdf from rdf-endpoints, add /internal for json
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsOveTen committed Nov 30, 2023
1 parent cced383 commit 039ca93
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.springframework.web.bind.annotation.RequestMapping

@Controller
@CrossOrigin
@RequestMapping(value = ["/catalogs/{catalogId}/public-services"])
@RequestMapping(value = ["/internal/catalogs/{catalogId}/public-services"])
class PublicServiceController(private val publicServiceService: PublicServiceService, private val endpointPermissions: EndpointPermissions) {

@GetMapping
Expand Down Expand Up @@ -103,6 +103,6 @@ class PublicServiceController(private val publicServiceService: PublicServiceSer

private fun locationHeaderForCreated(newId: String, catalogId: String): HttpHeaders =
HttpHeaders().apply {
add(HttpHeaders.LOCATION, "/catalogs/$catalogId/public-services/$newId")
add(HttpHeaders.LOCATION, "/internal/catalogs/$catalogId/public-services/$newId")
add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.LOCATION)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RequestMapping
@RequestMapping(
produces = ["text/turtle", "text/n3", "application/rdf+json", "application/rdf+xml",
"application/n-triples", "application/n-quads", "application/trig", "application/trix"],
value = ["/rdf/catalogs"])
value = ["/catalogs"])
class RDFController(private val rdfService: RDFService) {

@GetMapping(value = ["/{catalogId}"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping

@Controller
@CrossOrigin
@RequestMapping(value = ["/catalogs/{catalogId}/services"])
@RequestMapping(value = ["/internal/catalogs/{catalogId}/services"])
class ServiceController(private val serviceService: ServiceService, private val endpointPermissions: EndpointPermissions) {

@GetMapping
Expand Down Expand Up @@ -104,6 +104,6 @@ class ServiceController(private val serviceService: ServiceService, private val

private fun locationHeaderForCreated(newId: String, catalogId: String): HttpHeaders =
HttpHeaders().apply {
add(HttpHeaders.LOCATION, "/catalogs/$catalogId/services/$newId")
add(HttpHeaders.LOCATION, "/internal/catalogs/$catalogId/services/$newId")
add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.LOCATION)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ open class SecurityConfig {
authorizeHttpRequests {
authorize(HttpMethod.GET, "/actuator/health/readiness", permitAll)
authorize(HttpMethod.GET, "/actuator/health/liveness", permitAll)
authorize(HttpMethod.GET, "/rdf/**", permitAll)
authorize(HttpMethod.GET, "/internal/**", authenticated)
authorize(HttpMethod.GET, "/**", permitAll)
authorize(anyRequest, authenticated)
}
oauth2ResourceServer { jwt { } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PublicServices: ApiTestContext() {
@Test
fun `able to get all public services`() {
val response = apiAuthorizedRequest(
"/catalogs/910244132/public-services",
"/internal/catalogs/910244132/public-services",
port,
null,
JwtToken(Access.ORG_READ).toString(),
Expand All @@ -48,7 +48,7 @@ class PublicServices: ApiTestContext() {
@Test
fun `unauthorized when missing token`() {
val response = apiAuthorizedRequest(
"/catalogs/910244132/public-services",
"/internal/catalogs/910244132/public-services",
port,
null,
null,
Expand All @@ -59,7 +59,7 @@ class PublicServices: ApiTestContext() {
@Test
fun `forbidden when authorized for other catalog`() {
val response = apiAuthorizedRequest(
"/catalogs/910244132/public-services",
"/internal/catalogs/910244132/public-services",
port,
null,
JwtToken(Access.WRONG_ORG_WRITE).toString(),
Expand All @@ -73,7 +73,7 @@ class PublicServices: ApiTestContext() {
@Test
fun `able to get public service by id`() {
val response = apiAuthorizedRequest(
"/catalogs/910244132/public-services/1",
"/internal/catalogs/910244132/public-services/1",
port,
null,
JwtToken(Access.ORG_READ).toString(),
Expand All @@ -86,7 +86,7 @@ class PublicServices: ApiTestContext() {
@Test
fun `receive not found when public service is not found`() {
val response = apiAuthorizedRequest(
"/catalogs/910244132/public-services/1000",
"/internal/catalogs/910244132/public-services/1000",
port,
null,
JwtToken(Access.ORG_READ).toString(),
Expand All @@ -97,7 +97,7 @@ class PublicServices: ApiTestContext() {

@Nested
internal inner class PatchPublicService {
val pathService1 = "/catalogs/910244132/public-services/1"
val pathService1 = "/internal/catalogs/910244132/public-services/1"
val replaceOperation = JsonPatchOperation(
op = OpEnum.REPLACE,
path = "/title/nb",
Expand Down Expand Up @@ -182,7 +182,7 @@ class PublicServices: ApiTestContext() {
path = "/description",
value = LocalizedStrings("added nb description", null, null)))
val response = apiAuthorizedRequest(
"/catalogs/910244132/public-services/2",
"/internal/catalogs/910244132/public-services/2",
port,
mapper.writeValueAsString(operations),
JwtToken(Access.ORG_WRITE).toString(),
Expand Down Expand Up @@ -242,7 +242,7 @@ class PublicServices: ApiTestContext() {
fun `not found when public service not in database`() {
val operations = listOf(replaceOperation)
val response = apiAuthorizedRequest(
"/catalogs/910244132/public-services/1000",
"/internal/catalogs/910244132/public-services/1000",
port,
mapper.writeValueAsString(operations),
JwtToken(Access.ORG_WRITE).toString(),
Expand All @@ -254,7 +254,7 @@ class PublicServices: ApiTestContext() {
fun `not found when public service in different catalog`() {
val operations = listOf(replaceOperation)
val response = apiAuthorizedRequest(
"/catalogs/123456789/public-services/1",
"/internal/catalogs/123456789/public-services/1",
port,
mapper.writeValueAsString(operations),
JwtToken(Access.WRONG_ORG_WRITE).toString(),
Expand All @@ -265,7 +265,7 @@ class PublicServices: ApiTestContext() {

@Nested
internal inner class DeletePublicService {
val pathService1 = "/catalogs/910244132/public-services/1"
val pathService1 = "/internal/catalogs/910244132/public-services/1"

@Test
fun `unauthorized when missing token` () {
Expand Down Expand Up @@ -294,7 +294,7 @@ class PublicServices: ApiTestContext() {
@Test
fun `not found when public service in different catalog`() {
val response = apiAuthorizedRequest(
"/catalogs/123456789/public-services/1",
"/internal/catalogs/123456789/public-services/1",
port,
null,
JwtToken(Access.WRONG_ORG_WRITE).toString(),
Expand All @@ -305,7 +305,7 @@ class PublicServices: ApiTestContext() {
@Test
fun `not found when public service not in database`() {
val response = apiAuthorizedRequest(
"/catalogs/910244132/public-services/1000",
"/internal/catalogs/910244132/public-services/1000",
port,
null,
JwtToken(Access.ORG_WRITE).toString(),
Expand Down Expand Up @@ -335,7 +335,7 @@ class PublicServices: ApiTestContext() {

@Nested
internal inner class CreatePublicService {
private val path = "/catalogs/910244132/public-services"
private val path = "/internal/catalogs/910244132/public-services"

@Test
fun `create PublicService as OrgWrite`() {
Expand Down Expand Up @@ -411,7 +411,7 @@ class PublicServices: ApiTestContext() {

@Nested
internal inner class PublishPublicService {
val pathService1 = "/catalogs/910244132/public-services/1/publish"
val pathService1 = "/internal/catalogs/910244132/public-services/1/publish"
@Test
fun `unauthorized when missing token` () {
val response = apiAuthorizedRequest(
Expand Down Expand Up @@ -439,7 +439,7 @@ class PublicServices: ApiTestContext() {
@Test
fun `not found when public service in different catalog`() {
val response = apiAuthorizedRequest(
"/catalogs/123456789/public-services/1/publish",
"/internal/catalogs/123456789/public-services/1/publish",
port,
null,
JwtToken(Access.WRONG_ORG_WRITE).toString(),
Expand All @@ -450,7 +450,7 @@ class PublicServices: ApiTestContext() {
@Test
fun `not found when public service not in database`() {
val response = apiAuthorizedRequest(
"/catalogs/910244132/public-services/1000/publish",
"/internal/catalogs/910244132/public-services/1000/publish",
port,
null,
JwtToken(Access.ORG_WRITE).toString(),
Expand Down Expand Up @@ -480,7 +480,7 @@ class PublicServices: ApiTestContext() {
path = "/isPublished",
value = true))
val response = apiAuthorizedRequest(
"/catalogs/910244132/public-services/1",
"/internal/catalogs/910244132/public-services/1",
port,
mapper.writeValueAsString(operations),
JwtToken(Access.ORG_WRITE).toString(),
Expand Down
10 changes: 5 additions & 5 deletions src/test/kotlin/no/digdir/servicecatalog/integration/RDF.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RDF: ApiTestContext() {

@Nested
internal inner class GetCatalogRDF {
private val catalogPath = "/rdf/catalogs/910244132"
private val catalogPath = "/catalogs/910244132"

@Test
fun `able to get rdf catalog`() {
Expand Down Expand Up @@ -64,8 +64,8 @@ class RDF: ApiTestContext() {

@Nested
internal inner class GetPublicServiceRDF {
private val publicServicePath = "/rdf/catalogs/910244132/public-services/0"
private val notExistingPublicServicePath = "/rdf/catalogs/910244132/public-services/1000"
private val publicServicePath = "/catalogs/910244132/public-services/0"
private val notExistingPublicServicePath = "/catalogs/910244132/public-services/1000"

@Test
fun `able to get rdf for public service`() {
Expand Down Expand Up @@ -104,8 +104,8 @@ class RDF: ApiTestContext() {

@Nested
internal inner class GetServiceRDF {
private val servicePath = "/rdf/catalogs/910244132/services/00"
private val notExistingServicePath = "/rdf/catalogs/910244132/services/1000"
private val servicePath = "/catalogs/910244132/services/00"
private val notExistingServicePath = "/catalogs/910244132/services/1000"

@Test
fun `able to get rdf for service`() {
Expand Down
28 changes: 14 additions & 14 deletions src/test/kotlin/no/digdir/servicecatalog/integration/Services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Services: ApiTestContext() {

@Nested
internal inner class GetServices {
val path = "/catalogs/910244132/services"
val path = "/internal/catalogs/910244132/services"
@Test
fun `able to get all services`() {
val response = apiAuthorizedRequest(
Expand Down Expand Up @@ -78,7 +78,7 @@ class Services: ApiTestContext() {

@Nested
internal inner class GetService {
val path = "/catalogs/910244132/services/01"
val path = "/internal/catalogs/910244132/services/01"
@Test
fun `able to get service by id`() {
val response = apiAuthorizedRequest(
Expand Down Expand Up @@ -106,7 +106,7 @@ class Services: ApiTestContext() {
@Test
fun `receive not found when service is not found`() {
val response = apiAuthorizedRequest(
"/catalogs/910244132/services/1000",
"/internal/catalogs/910244132/services/1000",
port,
null,
JwtToken(Access.ORG_READ).toString(),
Expand All @@ -117,7 +117,7 @@ class Services: ApiTestContext() {

@Nested
internal inner class PatchService {
val path = "/catalogs/910244132/services/02"
val path = "/internal/catalogs/910244132/services/02"
val replaceOperation = JsonPatchOperation(
op = OpEnum.REPLACE,
path = "/title/nb",
Expand Down Expand Up @@ -271,7 +271,7 @@ class Services: ApiTestContext() {
fun `not found when service not in database`() {
val operations = listOf(replaceOperation)
val response = apiAuthorizedRequest(
"/catalogs/910244132/services/1000",
"/internal/catalogs/910244132/services/1000",
port,
mapper.writeValueAsString(operations),
JwtToken(Access.ORG_WRITE).toString(),
Expand All @@ -283,7 +283,7 @@ class Services: ApiTestContext() {
fun `not found when service in different catalog`() {
val operations = listOf(replaceOperation)
val response = apiAuthorizedRequest(
"/catalogs/123456789/services/01",
"/internal/catalogs/123456789/services/01",
port,
mapper.writeValueAsString(operations),
JwtToken(Access.WRONG_ORG_WRITE).toString(),
Expand All @@ -294,7 +294,7 @@ class Services: ApiTestContext() {

@Nested
internal inner class DeleteService {
val path = "/catalogs/910244132/services/02"
val path = "/internal/catalogs/910244132/services/02"

@Test
fun `unauthorized when missing token` () {
Expand Down Expand Up @@ -323,7 +323,7 @@ class Services: ApiTestContext() {
@Test
fun `not found when service in different catalog`() {
val response = apiAuthorizedRequest(
"/catalogs/123456789/services/01",
"/internal/catalogs/123456789/services/01",
port,
null,
JwtToken(Access.WRONG_ORG_WRITE).toString(),
Expand All @@ -334,7 +334,7 @@ class Services: ApiTestContext() {
@Test
fun `not found when service not in database`() {
val response = apiAuthorizedRequest(
"/catalogs/910244132/services/1000",
"/internal/catalogs/910244132/services/1000",
port,
null,
JwtToken(Access.ORG_WRITE).toString(),
Expand Down Expand Up @@ -364,7 +364,7 @@ class Services: ApiTestContext() {

@Nested
internal inner class CreateService {
private val path = "/catalogs/910244132/services"
private val path = "/internal/catalogs/910244132/services"

@Test
fun `create Service as OrgWrite`() {
Expand Down Expand Up @@ -433,7 +433,7 @@ class Services: ApiTestContext() {

@Nested
internal inner class PublishService {
val path = "/catalogs/910244132/services/01/publish"
val path = "/internal/catalogs/910244132/services/01/publish"
@Test
fun `unauthorized when missing token` () {
val response = apiAuthorizedRequest(
Expand Down Expand Up @@ -461,7 +461,7 @@ class Services: ApiTestContext() {
@Test
fun `not found when service in different catalog`() {
val response = apiAuthorizedRequest(
"/catalogs/123456789/services/01/publish",
"/internal/catalogs/123456789/services/01/publish",
port,
null,
JwtToken(Access.WRONG_ORG_WRITE).toString(),
Expand All @@ -472,7 +472,7 @@ class Services: ApiTestContext() {
@Test
fun `not found when service not in database`() {
val response = apiAuthorizedRequest(
"/catalogs/910244132/services/1000/publish",
"/internal/catalogs/910244132/services/1000/publish",
port,
null,
JwtToken(Access.ORG_WRITE).toString(),
Expand Down Expand Up @@ -504,7 +504,7 @@ class Services: ApiTestContext() {
value = true)
)
val response = apiAuthorizedRequest(
"/catalogs/910244132/services/01",
"/internal/catalogs/910244132/services/01",
port,
mapper.writeValueAsString(operations),
JwtToken(Access.ORG_WRITE).toString(),
Expand Down

0 comments on commit 039ca93

Please sign in to comment.