-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add integration tests for backend security
- Loading branch information
tungkhanhh
committed
Oct 7, 2024
1 parent
cdf3679
commit e7cc231
Showing
2 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
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
79 changes: 79 additions & 0 deletions
79
backend/src/test/java/org/acme/security/jpa/JpaSecurityRealmTest.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,79 @@ | ||
package org.acme.security.jpa; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import jakarta.inject.Inject; | ||
import org.apache.http.HttpStatus; | ||
import org.eclipse.microprofile.config.Config; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.get; | ||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.core.Is.is; | ||
|
||
@QuarkusTest | ||
public class JpaSecurityRealmTest { | ||
@Inject | ||
Config config; | ||
|
||
@Test | ||
void shouldNotAccessLoginWhenAnonymous() { | ||
get("/login") | ||
.then() | ||
.statusCode(HttpStatus.SC_UNAUTHORIZED); | ||
} | ||
|
||
@Test | ||
void shouldNotAccessRoomsWhenAnonymous() { | ||
get("/rooms") | ||
.then() | ||
.statusCode(HttpStatus.SC_UNAUTHORIZED); | ||
} | ||
|
||
@Test | ||
void shouldNotAccessUnitsWhenAnonymous() { | ||
get("/units") | ||
.then() | ||
.statusCode(HttpStatus.SC_UNAUTHORIZED); | ||
} | ||
|
||
@Test | ||
void shouldAccessLoginWhenUserAuthenticated() { | ||
String username = config.getValue("frontend.username", String.class); | ||
String password = config.getValue("frontend.password", String.class); | ||
|
||
given() | ||
.auth().preemptive().basic(username, password) | ||
.when() | ||
.get("/login") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is(username)); | ||
} | ||
|
||
@Test | ||
void shouldAccessRoomsWhenUserAuthenticated() { | ||
String username = config.getValue("frontend.username", String.class); | ||
String password = config.getValue("frontend.password", String.class); | ||
|
||
given() | ||
.auth().preemptive().basic(username, password) | ||
.when() | ||
.get("/rooms") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK); | ||
} | ||
|
||
@Test | ||
void shouldAccessUnitsWhenUserAuthenticated() { | ||
String username = config.getValue("frontend.username", String.class); | ||
String password = config.getValue("frontend.password", String.class); | ||
|
||
given() | ||
.auth().preemptive().basic(username, password) | ||
.when() | ||
.get("/units") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK); | ||
} | ||
|
||
} |