generated from keploy/template
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Akash Jaiswal <akashjaiswal3846@gmail.com>
- Loading branch information
Showing
12 changed files
with
808 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
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,19 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
wrapperVersion=3.3.2 | ||
distributionType=only-script | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip |
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,17 @@ | ||
# Use an official OpenJDK runtime as a parent image | ||
FROM openjdk:22-bookworm | ||
|
||
# Set the working directory to /app | ||
WORKDIR /app | ||
|
||
# Install Maven | ||
RUN apt-get update && apt-get install -y maven | ||
|
||
# Copy the current directory contents into the container at /app | ||
COPY . /app/ | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 8080 | ||
|
||
# Run the application when the container launches | ||
CMD ["/usr/share/maven/bin/mvn", "spring-boot:run"] |
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,112 @@ | ||
# Keploy Sample Java - JWT Token Verification and Spring Boot | ||
|
||
This repository contains a sample project that demonstrates the integration of Keploy with JWT (JSON Web Token) authentication in a Spring Boot application. | ||
|
||
## Prerequisites | ||
|
||
Before getting started, make sure you have the following installed: | ||
|
||
- Latest version of JDK | ||
- Install [Keploy](https://keploy.io/docs/server/installation/) | ||
- Postman for testing APIs | ||
|
||
## Getting Started | ||
|
||
To get started, clone the repository: | ||
|
||
```bash | ||
git clone https://github.com/jaiakash/samples-java.git | ||
cd spring-boot-jwt | ||
``` | ||
|
||
## API Endpoints | ||
|
||
The following API endpoints are available: | ||
|
||
#### Login | ||
|
||
- POST `/users/login` | ||
|
||
Authenticate a user and receive a JWT token. | ||
|
||
Request Body: | ||
|
||
```json | ||
{ | ||
"username": "your_username", | ||
"password": "your_password" | ||
} | ||
``` | ||
|
||
Response: | ||
|
||
```json | ||
{ | ||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." | ||
} | ||
``` | ||
|
||
#### Token Verification | ||
|
||
- POST `/users/tokenVerification` | ||
|
||
Verify the validity of a JWT token. | ||
|
||
Request Body: | ||
|
||
```json | ||
{ | ||
"token": "your_jwt_token_here" | ||
} | ||
``` | ||
|
||
Response: | ||
|
||
```json | ||
{ | ||
"isValid": true | ||
} | ||
``` | ||
|
||
## Integration with Keploy | ||
|
||
#### RECORD Mode | ||
|
||
1. To run the application, run | ||
|
||
``` | ||
keploy run -c "./mvnw spring-boot:run" --delay 240 | ||
``` | ||
|
||
2. To generate testcases, you can make API calls using Postman or `curl`: | ||
|
||
- Login | ||
|
||
```bash | ||
curl --location --request POST 'http://localhost:8080/users/login' \ | ||
--header 'Content-Type: application/json' \ | ||
--data-raw '{ | ||
"username": "akash@example.com", | ||
"password": "password" | ||
}' | ||
``` | ||
|
||
- Verify | ||
|
||
```bash | ||
curl --location --request POST 'http://localhost:8080/users/verify' \ | ||
--header 'Content-Type: application/json' \ | ||
--data-raw '{ | ||
"token": "your_jwt_token_here" | ||
}' | ||
``` | ||
|
||
#### TEST mode | ||
|
||
To test the application, start Keploy in test mode. In the root directory, run the following command: | ||
|
||
```bash | ||
keploy test -c "./mvnw spring-boot:run" --delay 240 | ||
``` | ||
|
||
This command will run the tests and generate the report in the `Keploy/reports` directory in the current working directory. |
Oops, something went wrong.