I made a test but I don't know how to test
This commit is contained in:
parent
f4b7e0abde
commit
809e045c0b
2 changed files with 61 additions and 0 deletions
11
pom.xml
11
pom.xml
|
@ -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>
|
||||
|
|
50
src/test/java/eu/m724/TokenTest.java
Normal file
50
src/test/java/eu/m724/TokenTest.java
Normal 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());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue