-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked tests to be integration tests
- Loading branch information
1 parent
70b614c
commit b1b9931
Showing
8 changed files
with
152 additions
and
136 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/test/java/org/icatproject/authn_db/AuthenticateIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.icatproject.authn_db; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
import jakarta.ws.rs.core.Response; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
@QuarkusIntegrationTest | ||
public class AuthenticateIT { | ||
|
||
@Test | ||
public void testValidLoginUser() { | ||
// JSON string to be sent as form data | ||
String jsonString = "{\"credentials\":[{\"username\":\"user1\"},{\"password\":\"sunshine\"}]}"; | ||
|
||
given() | ||
.header("Content-Type", "application/x-www-form-urlencoded") | ||
.formParam("json", jsonString) | ||
.when() | ||
.post("/authn.db/authenticate") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()) // Expect a 200 OK status | ||
.body("username", equalTo("user1")) // Validate the response body | ||
.body("mechanism", equalTo("db")); // Validate the response body | ||
} | ||
@Test | ||
public void testInvalidUsername() { | ||
String jsonString = "{\"credentials\":[{\"username\":\"invaliduser\"},{\"password\":\"sunshine\"}]}"; | ||
|
||
// Perform an HTTP POST with invalid username, sending the JSON as a form parameter | ||
given() | ||
.header("Content-Type", "application/x-www-form-urlencoded") // Set Content-Type for form-urlencoded | ||
.formParam("json", jsonString) // Send the JSON string as a form parameter with the key 'json' | ||
.when() | ||
.post("/authn.db/authenticate") // Ensure the path is correct | ||
.then() | ||
.statusCode(Response.Status.FORBIDDEN.getStatusCode()) // Expect 403 Forbidden | ||
.body("message", equalTo("The username and password do not match")); | ||
} | ||
@Test | ||
public void testInvalidPassword() { | ||
String jsonString = "{\"credentials\":[{\"username\":\"user1\"},{\"password\":\"trainspotting\"}]}"; | ||
|
||
// Perform an HTTP POST with invalid password, sending the JSON as a form parameter | ||
given() | ||
.header("Content-Type", "application/x-www-form-urlencoded") // Set Content-Type for form-urlencoded | ||
.formParam("json", jsonString) // Send the JSON string as a form parameter with the key 'json' | ||
.when() | ||
.post("/authn.db/authenticate") // Ensure the path is correct | ||
.then() | ||
.statusCode(Response.Status.FORBIDDEN.getStatusCode()) // Expect 403 Forbidden | ||
.body("message", equalTo("The username and password do not match")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.icatproject.authn_db; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
import io.restassured.RestAssured; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
@QuarkusIntegrationTest | ||
public class DescriptionIT { | ||
|
||
@Test | ||
public void getDescription() { | ||
RestAssured.given() | ||
.when().get("/authn.db/description") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("{\"keys\":[{\"name\":\"username\"},{\"name\":\"password\",\"hide\":true}]}")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.icatproject.authn_db; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
import io.quarkus.test.junit.TestProfile; | ||
import jakarta.ws.rs.core.Response; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
@QuarkusIntegrationTest | ||
@TestProfile(IPTestProfile.class) | ||
public class IPTestsIT { | ||
|
||
@Test | ||
public void testNoIpInRequest() { | ||
String jsonString = "{\"credentials\":[{\"username\":\"user1\"},{\"password\":\"sunshine\"}]}"; | ||
|
||
// Perform an HTTP POST request without IP in the request body | ||
given() | ||
.header("Content-Type", "application/x-www-form-urlencoded") // Set Content-Type for form-urlencoded | ||
.formParam("json", jsonString) // Send the JSON string as a form parameter with the key 'json' | ||
.when() | ||
.post("/authn.db/authenticate") | ||
.then() | ||
.statusCode(Response.Status.BAD_REQUEST.getStatusCode()) // Expect 400 Bad Request | ||
.body("message", equalTo("An Ip address must be provided")); | ||
} | ||
|
||
@Test | ||
public void badIpInRequest() { | ||
String jsonString = "{\"credentials\":[{\"username\":\"user1\"},{\"password\":\"sunshine\"}], \"ip\":\"192.167.0.125\"}"; | ||
|
||
// Perform an HTTP POST request with a bad IP address | ||
given() | ||
.header("Content-Type", "application/x-www-form-urlencoded") // Set Content-Type for form-urlencoded | ||
.formParam("json", jsonString) // Send the JSON string as a form parameter with the key 'json' | ||
.when() | ||
.post("/authn.db/authenticate") | ||
.then() | ||
.statusCode(Response.Status.FORBIDDEN.getStatusCode()) // Expect 403 Forbidden | ||
.body("message", equalTo("authn_db does not allow log in from your IP address 192.167.0.125")); | ||
} | ||
|
||
@Test | ||
public void goodIpInRequest() { | ||
String jsonString = "{\"credentials\":[{\"username\":\"user1\"},{\"password\":\"sunshine\"}], \"ip\":\"192.168.0.125\"}"; | ||
|
||
// Perform an HTTP POST request with a valid IP address | ||
given() | ||
.header("Content-Type", "application/x-www-form-urlencoded") // Set Content-Type for form-urlencoded | ||
.formParam("json", jsonString) // Send the JSON string as a form parameter with the key 'json' | ||
.when() | ||
.post("/authn.db/authenticate") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()) // Expect 200 OK | ||
.body("username", equalTo("user1")) | ||
.body("mechanism", equalTo("db")); // Adjust this based on your actual mechanism | ||
} | ||
|
||
} |
50 changes: 0 additions & 50 deletions
50
src/test/java/org/icatproject/authn_db/TestAuthenticate.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/test/java/org/icatproject/authn_db/TestGetDescription.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters