Skip to content
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

fix(captcha): handle negative remaining time #62

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM golang:1.21-bookworm AS builder
FROM golang:1.22-bookworm AS builder

WORKDIR /app

COPY . .

RUN go build -o captcha-bot -ldflags="-X main.version=$(git rev-parse HEAD)" ./cmd/captcha
RUN go build -o captcha-bot -ldflags="-X main.version=$(git rev-parse HEAD)" ./cmd/captcha

FROM debian:bookworm-slim AS runtime

Expand Down
8 changes: 8 additions & 0 deletions captcha/answer.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@
// Check if the answer is correct or not
if answer != captcha.Answer {
remainingTime := time.Until(captcha.Expiry)
// If the current time is after the expiry time, we should return immediately.
// We don't need to delete any message since sometimes those messages are a valid one,
// and we are having a race due to network issues. This is not something that
// we can easily fix, since network is not always consistent.
if remainingTime < 0 {
return
}

Check warning on line 98 in captcha/answer.go

View check run for this annotation

Codecov / codecov/patch

captcha/answer.go#L92-L98

Added lines #L92 - L98 were not covered by tests

wrongMsg, err := d.Bot.Send(
ctx,
m.Chat,
Expand Down
8 changes: 8 additions & 0 deletions captcha/non.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@

// Check if the answer is a media
remainingTime := time.Until(captcha.Expiry)
// If the current time is after the expiry time, we should return immediately.
// We don't need to delete any message since sometimes those messages are a valid one,
// and we are having a race due to network issues. This is not something that
// we can easily fix, since network is not always consistent.
if remainingTime < 0 {
return
}

Check warning on line 81 in captcha/non.go

View check run for this annotation

Codecov / codecov/patch

captcha/non.go#L75-L81

Added lines #L75 - L81 were not covered by tests

wrongMsg, err := d.Bot.Send(
ctx,
m.Chat,
Expand Down
20 changes: 10 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
module github.com/teknologi-umum/captcha

go 1.20
go 1.22

require (
github.com/aldy505/asciitxt v0.0.2
github.com/allegro/bigcache/v3 v3.1.0
github.com/dgraph-io/badger/v4 v4.2.0
github.com/getsentry/sentry-go v0.25.0
github.com/go-chi/chi/v5 v5.0.11
github.com/getsentry/sentry-go v0.27.0
github.com/go-chi/chi/v5 v5.0.12
github.com/goccy/go-yaml v1.9.5
github.com/ilyakaznacheev/cleanenv v1.5.0
github.com/jmoiron/sqlx v1.3.5
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/pkg/errors v0.9.1
github.com/rs/cors v1.10.1
github.com/rs/zerolog v1.31.0
github.com/rs/zerolog v1.32.0
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.2
github.com/unrolled/secure v1.13.0
go.mongodb.org/mongo-driver v1.13.1
github.com/unrolled/secure v1.14.0
go.mongodb.org/mongo-driver v1.14.0
)

require (
Expand Down Expand Up @@ -56,10 +56,10 @@ require (
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
google.golang.org/protobuf v1.33.0 // indirect
Expand Down
Loading
Loading