-
Notifications
You must be signed in to change notification settings - Fork 96
Changing the 1 seconds check to 1.5 seconds #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c4408fd
d3049f6
66380cb
416bf06
15171d1
876f60b
2b8a3e0
b9b9a66
35e0b10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,7 @@ Install keploy via one-click:- | |||||
| curl --silent -O -L https://keploy.io/install.sh && source install.sh | ||||||
| ``` | ||||||
|
|
||||||
| ### Start the Postgres Database | ||||||
| ### Start the MySQL Database | ||||||
|
|
||||||
| ```zsh | ||||||
| docker compose up -d db | ||||||
|
|
@@ -35,13 +35,13 @@ Once we have our binary file ready,this command will start the recording of API | |||||
| sudo -E keploy record -c "./go-jwt" | ||||||
| ``` | ||||||
|
|
||||||
| Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. | ||||||
| Make API Calls using Hoppscotch, Postman or cURL command. Keploy will capture those calls to generate the test-suites containing testcases and data mocks. | ||||||
|
|
||||||
| #### Generate testcases | ||||||
|
|
||||||
| To genereate testcases we just need to make some API calls. You can use [Postman](https://www.postman.com/), [Hoppscotch](https://hoppscotch.io/), or simply `curl` | ||||||
|
||||||
| To genereate testcases we just need to make some API calls. You can use [Postman](https://www.postman.com/), [Hoppscotch](https://hoppscotch.io/), or simply `curl` | |
| To generate testcases we just need to make some API calls. You can use [Postman](https://www.postman.com/), [Hoppscotch](https://hoppscotch.io/), or simply `curl` |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation is incomplete - the sentence "This will send a request to the /check-time endpoint and you should see a successful response:" appears to be cut off. It should either end with a period or continue with more details about what the response looks like.
| This will send a request to the `/check-time` endpoint and you should see a successful response: | |
| This will send a request to the `/check-time` endpoint and you should see a successful response. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,18 +1,19 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // Package main is the entry point for the JWT-based user authentication service | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // using Gin framework and PostgreSQL database. It provides endpoints for | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // health check, token generation, and token validation. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| package main | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "log" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "net/http" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "strconv" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/dgrijalva/jwt-go" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/gin-gonic/gin" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/jinzhu/gorm" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| _ "github.com/jinzhu/gorm/dialects/postgres" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Change: Imported MySQL dialect instead of Postgres | ||||||||||||||||||||||||||||||||||||||||||||||||||
| _ "github.com/jinzhu/gorm/dialects/mysql" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| var ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -36,12 +37,30 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| func initDB() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| dsn := "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| db, err = gorm.Open("postgres", dsn) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Printf("Failed to connect to database: %s", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| dsn := "myuser:mypassword@tcp(localhost:3306)/mydb?charset=utf8&parseTime=True&loc=Local&timeout=60s&readTimeout=60s" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+41
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| dsn := "myuser:mypassword@tcp(localhost:3306)/mydb?charset=utf8&parseTime=True&loc=Local&timeout=60s&readTimeout=60s" | |
| dbUser := os.Getenv("DB_USER") | |
| if dbUser == "" { | |
| dbUser = "myuser" | |
| } | |
| dbPassword := os.Getenv("DB_PASSWORD") | |
| if dbPassword == "" { | |
| dbPassword = "mypassword" | |
| } | |
| dbHost := os.Getenv("DB_HOST") | |
| if dbHost == "" { | |
| dbHost = "localhost" | |
| } | |
| dbPort := os.Getenv("DB_PORT") | |
| if dbPort == "" { | |
| dbPort = "3306" | |
| } | |
| dbName := os.Getenv("DB_NAME") | |
| if dbName == "" { | |
| dbName = "mydb" | |
| } | |
| dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=True&loc=Local&timeout=60s&readTimeout=60s", | |
| dbUser, dbPassword, dbHost, dbPort, dbName) |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The retry loop doesn't update the error state when ping fails. If gorm.Open succeeds but db.DB().Ping() fails (lines 48-50), the loop continues but connectionErr remains nil. This means the error check at line 57 may pass even though the connection is not functional. The ping error should be captured and assigned to connectionErr.
| if err := db.DB().Ping(); err == nil { | |
| break | |
| } | |
| if pingErr := db.DB().Ping(); pingErr == nil { | |
| break | |
| } | |
| // Treat ping failure as a connection error for retry logic | |
| connectionErr = pingErr |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug print statements should be removed before merging to production. Use proper logging with log.Printf() if this information is needed for operational purposes.
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug print statements should be removed before merging to production. Use proper logging with log.Printf() if this information is needed for operational purposes.
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "within 1 second" but the code now checks for 1.5 seconds (line 198). Update the comment to reflect the actual behavior: "within 1.5 seconds".
| // CheckTimeHandler checks if a client-provided timestamp is within 1 second of the server time. | |
| // CheckTimeHandler checks if a client-provided timestamp is within 1.5 seconds of the server time. |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR title states "Changing the 1 seconds check to 1.5 seconds" but this PR contains significantly more changes including: migration from PostgreSQL to MySQL, architecture change from arm64 to amd64, new /check-time endpoint, retry logic for database connections, and documentation updates. The PR title should accurately reflect the scope of changes, or these changes should be split into separate PRs for better reviewability.
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The time.Sleep call introduces an unconditional 1-second delay in the handler, which will significantly impact performance and user experience. This sleep appears to serve no functional purpose and should be removed. If this was added for testing purposes, it should not be in production code.
| time.Sleep(1 * time.Second) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #!/bin/bash | ||
|
|
||
| # This script sends a request to the /check-time endpoint. | ||
| # - If run without arguments, it uses the current Unix timestamp (should succeed). | ||
| # - If run with a number as an argument, it uses that number as the timestamp. | ||
|
|
||
| # --- Configuration --- | ||
| HOSTNAME="localhost" | ||
| PORT="8000" | ||
| ENDPOINT="/check-time" | ||
| # --------------------- | ||
|
|
||
| # Check if a command-line argument (a custom timestamp) was provided | ||
| if [ -n "$1" ]; then | ||
| # Use the provided argument as the timestamp | ||
| TIMESTAMP_TO_SEND="$1" | ||
| echo "Using provided timestamp: $TIMESTAMP_TO_SEND" | ||
| else | ||
| # No argument provided, get the current Unix timestamp | ||
| TIMESTAMP_TO_SEND=$(date +%s) | ||
| echo "Using current timestamp: $TIMESTAMP_TO_SEND" | ||
| fi | ||
|
|
||
| # Construct the full URL | ||
| URL="http://${HOSTNAME}:${PORT}${ENDPOINT}?ts=${TIMESTAMP_TO_SEND}" | ||
|
|
||
| # Send the request using curl and print the result | ||
| echo "Sending request to: ${URL}" | ||
| curl -s "${URL}" # The -s flag makes curl silent (no progress meter) | ||
| echo # Add a newline for cleaner terminal output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This Dockerfile downloads and executes a binary (
go_freeze_time_amd64) directly from a remote URL (https://keploy-enterprise.s3.us-west-2.amazonaws.com/releases/latest/assets/go_freeze_time_amd64) during the image build without any integrity verification or pinning to an immutable identifier. If that S3 asset (or the path behindlatest) is compromised or replaced, an attacker can run arbitrary code in the build environment and tamper with the resulting image. To mitigate this supply-chain risk, fetch a versioned artifact pinned to an immutable identifier (e.g., content hash or exact version) and/or verify its integrity (checksum or signature) before execution, or vendor the tool into the repository instead of downloading it at build time.