Skip to content

Commit

Permalink
Implements #155 enables CORS for capabilities endpoint with contracts…
Browse files Browse the repository at this point in the history
….cross.origin property
  • Loading branch information
Karol Kalinski authored and karolkalinski committed Nov 25, 2020
1 parent 789f42c commit 0fd8d7e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public ServiceContractsDto getContracts(@PathVariable(name = "serviceName") Stri

@GetMapping(value = "services/{serviceName}/versions/{version:.+}/capabilities/{protocol}", produces = MediaType.ALL_VALUE)
@ApiOperation(value = "Get capabilities of a version of a service for a protocol", nickname = "get capabilities by protocol")
@CrossOrigin(origins = "${contracts.cross.origin}")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = ServiceContractsDto.class),
@ApiResponse(code = 400, message = "Bad Request"),
Expand Down
9 changes: 6 additions & 3 deletions judge-d-server/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ logging.level.root=INFO

# database
spring.datasource.initialization-mode=always
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.h2.console.enabled=false
spring.h2.console.enabled=false
spring.jpa.hibernate.ddl-auto=none
liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml

#endpoint settings
contracts.cross.origin=http://localhost
3 changes: 3 additions & 0 deletions judge-d-server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}
spring.jpa.hibernate.ddl-auto=none
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml

#endpoint settings
contracts.cross.origin=http://localhost
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ class ContractsControllerIT extends Specification {
)
}

def 'cors configuration to allow using get capabilities url as input for web applications presenting swagger specs' () {
when:
def response = mockMvc.perform(options("/contracts/services/{serviceName}/versions/{version}/capabilities/{protocol}", "1", "2", "rest" )
.header("Access-Control-Request-Method", "GET")
.header("Origin", "http://localhost")
).andReturn().getResponse()
then:
response.getStatus() == 200

}

@TestConfiguration
static class TestConfig extends com.hltech.judged.server.config.BeanFactory {

Expand Down

0 comments on commit 0fd8d7e

Please sign in to comment.