I made a test but I don't know how to test

This commit is contained in:
Minecon724 2024-08-24 09:12:54 +02:00
parent f4b7e0abde
commit 809e045c0b
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
2 changed files with 61 additions and 0 deletions

11
pom.xml
View file

@ -54,6 +54,17 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View file

@ -0,0 +1,50 @@
package eu.m724;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.json.JsonPath;
import jakarta.json.Json;
import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.get;
import static io.restassured.RestAssured.given;
@QuarkusTest
public class TokenTest {
@Test
void anonymousAccessTest() {
get("/api/tokens/me").then().statusCode(HttpStatus.SC_UNAUTHORIZED);
get("/api/tokens/create").then().statusCode(HttpStatus.SC_UNAUTHORIZED);
}
@Test
void createTokenTest() {
String tokenEncoded = given()
.header("X-Token", "AAAAAAAAAAAAAAAAAAAAAAAA")
.body(Json.createObjectBuilder().add("accessLimits", "kilo").build().toString())
.when()
.get("/api/tokens/create")
.then()
.statusCode(HttpStatus.SC_OK)
.extract().jsonPath().getString("token");
System.out.println("New token: " + tokenEncoded);
given()
.header("X-Token", tokenEncoded)
.when()
.get("/api/tokens/create")
.then()
.statusCode(HttpStatus.SC_FORBIDDEN);
JsonPath response = given()
.header("X-Token", tokenEncoded)
.when()
.get("/api/tokens/me")
.then()
.statusCode(HttpStatus.SC_OK)
.extract().jsonPath();
System.out.println(response.toString());
}
}