Repository: aehrc/pathling (language: python)

Issue:
CORS configuration is not working
The CORS configuration on the server does not seem to be working with either of the following values:

```
pathling.cors.allowedOrigins=*
```

```
pathling.cors.allowedOriginPatterns=*
```


Discussion / hints:

Fix patch:
diff --git a/deployment/helm/pom.xml b/deployment/helm/pom.xml
index 588328f2bb..ef8cb0bf52 100644
--- a/deployment/helm/pom.xml
+++ b/deployment/helm/pom.xml
@@ -24,7 +24,7 @@
   <parent>
     <groupId>au.csiro.pathling</groupId>
     <artifactId>pathling</artifactId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
     <relativePath>../../pom.xml</relativePath>
   </parent>
   <artifactId>helm</artifactId>
diff --git a/encoders/pom.xml b/encoders/pom.xml
index 72809902f1..60d920ca50 100644
--- a/encoders/pom.xml
+++ b/encoders/pom.xml
@@ -30,7 +30,7 @@
   <parent>
     <groupId>au.csiro.pathling</groupId>
     <artifactId>pathling</artifactId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
   </parent>
   <artifactId>encoders</artifactId>
   <packaging>jar</packaging>
diff --git a/fhir-server/pom.xml b/fhir-server/pom.xml
index 65cf0c9b90..d16bb7e5f8 100644
--- a/fhir-server/pom.xml
+++ b/fhir-server/pom.xml
@@ -24,7 +24,7 @@
   <parent>
     <groupId>au.csiro.pathling</groupId>
     <artifactId>pathling</artifactId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
   </parent>
   <artifactId>fhir-server</artifactId>
   <packaging>jar</packaging>
diff --git a/fhir-server/src/main/java/au/csiro/pathling/security/SecurityConfiguration.java b/fhir-server/src/main/java/au/csiro/pathling/security/SecurityConfiguration.java
index 7c36edde31..d2c7404497 100644
--- a/fhir-server/src/main/java/au/csiro/pathling/security/SecurityConfiguration.java
+++ b/fhir-server/src/main/java/au/csiro/pathling/security/SecurityConfiguration.java
@@ -100,7 +100,9 @@ public SecurityFilterChain securityFilterChain(@Nonnull final HttpSecurity http)
               .requestMatchers(HttpMethod.GET, "/fhir/.well-known/**").permitAll()
               // Anything else needs to be authenticated.
               .anyRequest().authenticated())
+          // Enable CORS as per the configuration.
           .cors((cors) -> cors.configurationSource(corsConfigurationSource()))
+          // Use the provided JWT decoder and authentication converter.
           .oauth2ResourceServer(oauth2 -> oauth2
               .jwt((jwt) -> jwt
                   .jwtAuthenticationConverter(authenticationConverter)
@@ -109,6 +111,8 @@ public SecurityFilterChain securityFilterChain(@Nonnull final HttpSecurity http)
 
     } else {
       http.authorizeHttpRequests(authz -> authz.anyRequest().permitAll())
+          // Enable CORS as per the configuration.
+          .cors((cors) -> cors.configurationSource(corsConfigurationSource()))
           // Without this POST requests fail with 403 Forbidden.
           .csrf(AbstractHttpConfigurer::disable);
     }
diff --git a/fhirpath/pom.xml b/fhirpath/pom.xml
index 079ea025e2..efa1d3d9d8 100644
--- a/fhirpath/pom.xml
+++ b/fhirpath/pom.xml
@@ -24,7 +24,7 @@
   <parent>
     <groupId>au.csiro.pathling</groupId>
     <artifactId>pathling</artifactId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
   </parent>
   <artifactId>fhirpath</artifactId>
   <packaging>jar</packaging>
diff --git a/lib/R/pom.xml b/lib/R/pom.xml
index ee8bed4a79..3359612f91 100644
--- a/lib/R/pom.xml
+++ b/lib/R/pom.xml
@@ -24,7 +24,7 @@
   <parent>
     <groupId>au.csiro.pathling</groupId>
     <artifactId>pathling</artifactId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
     <relativePath>../../pom.xml</relativePath>
   </parent>
   <artifactId>r</artifactId>
diff --git a/lib/import/pom.xml b/lib/import/pom.xml
index 2c5cb16e19..8f493173f7 100644
--- a/lib/import/pom.xml
+++ b/lib/import/pom.xml
@@ -24,7 +24,7 @@
   <parent>
     <groupId>au.csiro.pathling</groupId>
     <artifactId>pathling</artifactId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
     <relativePath>../../pom.xml</relativePath>
   </parent>
   <artifactId>import</artifactId>
diff --git a/lib/js/pom.xml b/lib/js/pom.xml
index 4dc0b58dbd..bec150b6d3 100644
--- a/lib/js/pom.xml
+++ b/lib/js/pom.xml
@@ -24,7 +24,7 @@
   <parent>
     <groupId>au.csiro.pathling</groupId>
     <artifactId>pathling</artifactId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
     <relativePath>../../pom.xml</relativePath>
   </parent>
   <artifactId>js</artifactId>
diff --git a/lib/python/Dockerfile b/lib/python/Dockerfile
index 5e908e7b55..d8c1af5bf5 100644
--- a/lib/python/Dockerfile
+++ b/lib/python/Dockerfile
@@ -1,7 +1,7 @@
 FROM jupyter/all-spark-notebook
 
 USER root
-RUN echo "spark.jars.packages au.csiro.pathling:library-runtime:7.0.0" >> /usr/local/spark/conf/spark-defaults.conf
+RUN echo "spark.jars.packages au.csiro.pathling:library-runtime:7.0.1-SNAPSHOT" >> /usr/local/spark/conf/spark-defaults.conf
 
 USER ${NB_UID}
 
diff --git a/lib/python/pom.xml b/lib/python/pom.xml
index 253c25d8a6..e64cfdaab6 100644
--- a/lib/python/pom.xml
+++ b/lib/python/pom.xml
@@ -24,7 +24,7 @@
   <parent>
     <groupId>au.csiro.pathling</groupId>
     <artifactId>pathling</artifactId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
     <relativePath>../../pom.xml</relativePath>
   </parent>
   <artifactId>python</artifactId>
diff --git a/library-api/pom.xml b/library-api/pom.xml
index b60b1b2995..c15b8c4294 100644
--- a/library-api/pom.xml
+++ b/library-api/pom.xml
@@ -25,7 +25,7 @@
   <parent>
     <artifactId>pathling</artifactId>
     <groupId>au.csiro.pathling</groupId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
   </parent>
   <artifactId>library-api</artifactId>
   <packaging>jar</packaging>
diff --git a/library-runtime/pom.xml b/library-runtime/pom.xml
index f28511dcdc..4c1954cc86 100644
--- a/library-runtime/pom.xml
+++ b/library-runtime/pom.xml
@@ -25,7 +25,7 @@
   <parent>
     <artifactId>pathling</artifactId>
     <groupId>au.csiro.pathling</groupId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
   </parent>
   <artifactId>library-runtime</artifactId>
   <packaging>jar</packaging>
diff --git a/pom.xml b/pom.xml
index 2d1a9eeb2c..209f887079 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>au.csiro.pathling</groupId>
   <artifactId>pathling</artifactId>
-  <version>7.0.0</version>
+  <version>7.0.1-SNAPSHOT</version>
   <packaging>pom</packaging>
 
   <name>Pathling</name>
diff --git a/site/docs/libraries/installation/spark.md b/site/docs/libraries/installation/spark.md
index c6e457a914..8255f49b3f 100644
--- a/site/docs/libraries/installation/spark.md
+++ b/site/docs/libraries/installation/spark.md
@@ -35,7 +35,7 @@ from pyspark.sql import SparkSession
 spark = (
     SparkSession.builder.config(
             "spark.jars.packages",
-            "au.csiro.pathling:library-runtime:7.0.0,"
+            "au.csiro.pathling:library-runtime:7.0.1-SNAPSHOT,"
             "io.delta:delta-spark_2.12:3.1.0,"
     )
     .config(
@@ -75,7 +75,7 @@ pc <- pathling_connect(sc)
 import au.csiro.pathling.library.PathlingContext
 
 val spark = SparkSession.builder
-  .config("spark.jars.packages", "au.csiro.pathling:library-runtime:7.0.0," +
+  .config("spark.jars.packages", "au.csiro.pathling:library-runtime:7.0.1-SNAPSHOT," +
       "io.delta:delta-spark_2.12:3.1.0")
   .config("spark.sql.extensions", "io.delta.sql.DeltaSparkSessionExtension")
   .config("spark.sql.catalog.spark_catalog",
@@ -97,7 +97,7 @@ class MyApp {
     public static void main(String[] args) {
         SparkSession spark = SparkSession.builder()
             .config("spark.jars.packages", 
-                    "au.csiro.pathling:library-runtime:7.0.0," +
+                    "au.csiro.pathling:library-runtime:7.0.1-SNAPSHOT," +
                     "io.delta:delta-spark_2.12:3.1.0")
             .config("spark.sql.extensions", 
                     "io.delta.sql.DeltaSparkSessionExtension")
diff --git a/site/pom.xml b/site/pom.xml
index b17a25967c..a9b44afbab 100644
--- a/site/pom.xml
+++ b/site/pom.xml
@@ -13,7 +13,7 @@
   <parent>
     <groupId>au.csiro.pathling</groupId>
     <artifactId>pathling</artifactId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
     <relativePath>../pom.xml</relativePath>
   </parent>
   <artifactId>site</artifactId>
diff --git a/terminology/pom.xml b/terminology/pom.xml
index 9ffd3426fe..5f3feab6f4 100644
--- a/terminology/pom.xml
+++ b/terminology/pom.xml
@@ -25,7 +25,7 @@
   <parent>
     <artifactId>pathling</artifactId>
     <groupId>au.csiro.pathling</groupId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
   </parent>
   <artifactId>terminology</artifactId>
   <packaging>jar</packaging>
diff --git a/utilities/pom.xml b/utilities/pom.xml
index d265de28dc..b64f13067b 100644
--- a/utilities/pom.xml
+++ b/utilities/pom.xml
@@ -8,7 +8,7 @@
   <parent>
     <artifactId>pathling</artifactId>
     <groupId>au.csiro.pathling</groupId>
-    <version>7.0.0</version>
+    <version>7.0.1-SNAPSHOT</version>
   </parent>
   <artifactId>utilities</artifactId>
   <packaging>jar</packaging>


Test patch:
diff --git a/fhir-server/src/test/java/au/csiro/pathling/test/integration/CapabilityStatementTest.java b/fhir-server/src/test/java/au/csiro/pathling/test/integration/CapabilityStatementTest.java
index eecd0f23c6..551e4c8b88 100644
--- a/fhir-server/src/test/java/au/csiro/pathling/test/integration/CapabilityStatementTest.java
+++ b/fhir-server/src/test/java/au/csiro/pathling/test/integration/CapabilityStatementTest.java
@@ -18,7 +18,10 @@
 package au.csiro.pathling.test.integration;
 
 import static au.csiro.pathling.test.TestResources.assertJson;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
+import java.util.Arrays;
+import java.util.Collections;
 import org.json.JSONException;
 import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
@@ -29,11 +32,19 @@
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.TestPropertySource;
 
 /**
  * @author John Grimes
  */
+@TestPropertySource(properties = {
+    "pathling.cors.maxAge=800",
+    "pathling.cors.allowedMethods=GET,POST",
+    "pathling.cors.allowedOrigins=http://foo.bar,http://boo.bar",
+    "pathling.cors.allowedHeaders=X-Mine,X-Other"
+})
 @Tag("Tranche2")
 class CapabilityStatementTest extends IntegrationTest {
 
@@ -56,12 +67,20 @@ void cors() throws JSONException {
     final HttpHeaders corsHeaders = new HttpHeaders();
     corsHeaders.setOrigin("http://foo.bar");
     corsHeaders.setAccessControlRequestMethod(HttpMethod.GET);
+    corsHeaders.setAccessControlRequestHeaders(Arrays.asList("X-Mine", "X-Skip"));
 
     final ResponseEntity<String> response = restTemplate.exchange(
         "http://localhost:" + port + "/fhir/metadata", HttpMethod.OPTIONS,
         new HttpEntity<String>(corsHeaders), String.class);
 
-    System.out.println(response);
+    final HttpHeaders responseHeaders = response.getHeaders();
+    assertEquals(HttpStatus.OK, response.getStatusCode());
+    assertEquals("http://foo.bar", responseHeaders.getAccessControlAllowOrigin());
+    assertEquals(Arrays.asList(HttpMethod.GET, HttpMethod.POST),
+        responseHeaders.getAccessControlAllowMethods());
+    assertEquals(800L, responseHeaders.getAccessControlMaxAge());
+    assertEquals(Collections.singletonList("X-Mine"),
+        responseHeaders.getAccessControlAllowHeaders());
   }
 
 }