Skip to content

Commit

Permalink
Merge pull request #5 from qbicsoftware/patch/security
Browse files Browse the repository at this point in the history
Enables secured endpoints
  • Loading branch information
wow-such-code authored Dec 9, 2019
2 parents 972f652 + c4e37d1 commit 6fa8c92
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<!--groupId>life.qbic</groupId -->
<artifactId>sampletracking</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
<parent>
<groupId>life.qbic</groupId>
<artifactId>service-parent-pom</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
micronaut:
application:
name: sampletracking
security:
enabled: true
endpoints:
login:
enabled: true
datasources:
default:
url: jdbc:hsqldb:mem:mymemdb;shutdown=true/test?maxPoolSize=150&pool
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ micronaut:
name: sampletracking
server:
port: ${tr-server-port:8080}
security:
enabled: true
endpoints:
login:
enabled: true
datasources:
default:
url: jdbc:mariadb://${tr-db-host}/${tr-db-name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ class SamplesControllerIntegrationTest {
assertEquals(error, "Bad Request")
}

@Test
void testAuthenticationRequired() throws Exception {
HttpRequest request = HttpRequest.GET("/samples/" + validCode1)
def statusCode
try {
HttpResponse response = client.toBlocking().exchange(request)
} catch (HttpClientResponseException e) {
statusCode = e.getStatus().code
}
assertEquals(401, statusCode)
}

@Test
void testSample() throws Exception {
String email1 = "[email protected]"
Expand Down Expand Up @@ -264,7 +276,7 @@ class SamplesControllerIntegrationTest {
String body = client.toBlocking().retrieve(request)
assertEquals(body, "Sample status updated.")

request = HttpRequest.GET("/samples/"+validCode2)
request = HttpRequest.GET("/samples/"+validCode2).basicAuth("servicewriter", "123456!")
body = client.toBlocking().retrieve(request)
JSONObject json = new JSONObject(body);
json = json.get("current_location")
Expand Down

0 comments on commit 6fa8c92

Please sign in to comment.