From 1b581d0fd29a6e5a12da38a245c55cc40907aac1 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Fri, 4 Jul 2025 17:09:12 -0400 Subject: [PATCH] [Chore] General Updates July 2025. * GQLGen * Validator * Req * Go-Redis --- .golangci.yaml | 14 +++++++ docs/docs.go | 2 +- docs/swagger.json | 2 +- docs/swagger.yaml | 2 +- go.mod | 40 +++++++++---------- go.sum | 40 +++++++++++++++++++ pkg/auth/auth.go | 5 +-- pkg/common/common.go | 1 - pkg/common/common_test.go | 2 + pkg/common/crypto.go | 1 - pkg/common/crypto_test.go | 6 +++ pkg/common/fiat.go | 3 -- pkg/common/fiat_test.go | 7 ++++ pkg/common/healthcheck_test.go | 1 + pkg/common/users.go | 4 -- pkg/common/users_test.go | 4 ++ pkg/graphql/resolvers/authorization.go | 1 - pkg/graphql/resolvers/authorization_test.go | 1 + .../resolvers/crypto.resolvers_test.go | 7 ++++ pkg/graphql/resolvers/fiat.resolvers_test.go | 8 ++++ pkg/graphql/resolvers/handlers_test.go | 1 + .../resolvers/healthcheck.resolvers_test.go | 1 + pkg/graphql/resolvers/user.resolvers_test.go | 4 ++ pkg/logger/logger.go | 1 - pkg/logger/main_test.go | 1 + pkg/models/http.go | 9 +++-- pkg/models/postgres/user.go | 2 + pkg/postgres/models_sqlc_test.go | 4 ++ pkg/postgres/queries_users_test.go | 1 + pkg/quotes/quotes_test.go | 2 + pkg/redis/redis.go | 1 - pkg/redis/redis_test.go | 2 + pkg/rest/handlers/authorization_test.go | 2 + pkg/rest/handlers/crypto.go | 7 ---- pkg/rest/handlers/crypto_test.go | 7 ++++ pkg/rest/handlers/fiat.go | 8 ---- pkg/rest/handlers/fiat_test.go | 8 ++++ pkg/rest/handlers/users.go | 4 -- pkg/rest/handlers/users_test.go | 4 ++ pkg/rest/rest.go | 2 +- pkg/validator/validator.go | 2 +- pkg/validator/validator_test.go | 1 + 42 files changed, 163 insertions(+), 62 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index e5527b79..c37009bf 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -12,6 +12,8 @@ linters: - ireturn - nonamedreturns - testpackage + - wsl + - noinlineerr settings: cyclop: max-complexity: 12 @@ -39,6 +41,18 @@ linters: - K any - V any - m map[string]int + wsl_v5: + allow-first-in-block: true + allow-whole-block: false + branch-max-lines: 2 + revive: + severity: warning + rules: + - name: var-naming + arguments: + - [ ] # AllowList + - [ ] # DenyList + - - skip-package-name-checks: true exclusions: generated: lax presets: diff --git a/docs/docs.go b/docs/docs.go index 8b4c0a8a..d6d44955 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1462,7 +1462,7 @@ const docTemplate = `{ // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ - Version: "1.2.8", + Version: "1.2.9", Host: "localhost:33723", BasePath: "/api/rest/v1", Schemes: []string{"http"}, diff --git a/docs/swagger.json b/docs/swagger.json index 63c0cce6..01207a24 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -21,7 +21,7 @@ "name": "GPL-3.0", "url": "https://opensource.org/licenses/GPL-3.0" }, - "version": "1.2.8" + "version": "1.2.9" }, "host": "localhost:33723", "basePath": "/api/rest/v1", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index a9f1b0a0..bc487af5 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -149,7 +149,7 @@ info: name: GPL-3.0 url: https://opensource.org/licenses/GPL-3.0 title: FTeX, Inc. (Formerly Crypto-Bro's Bank, Inc.) - version: 1.2.8 + version: 1.2.9 paths: /crypto/exchange/: post: diff --git a/go.mod b/go.mod index 07bfeec0..c33d56e8 100644 --- a/go.mod +++ b/go.mod @@ -5,15 +5,15 @@ go 1.24 toolchain go1.24.2 require ( - github.com/99designs/gqlgen v0.17.73 + github.com/99designs/gqlgen v0.17.76 github.com/gin-gonic/gin v1.10.1 - github.com/go-playground/validator/v10 v10.26.0 + github.com/go-playground/validator/v10 v10.27.0 github.com/gofrs/uuid v4.4.0+incompatible github.com/golang-jwt/jwt/v5 v5.2.2 github.com/golang/mock v1.6.0 - github.com/imroc/req/v3 v3.52.2 + github.com/imroc/req/v3 v3.54.0 github.com/jackc/pgx/v5 v5.7.5 - github.com/redis/go-redis/v9 v9.8.0 + github.com/redis/go-redis/v9 v9.11.0 github.com/rs/xid v1.6.0 github.com/shopspring/decimal v1.4.0 github.com/spf13/afero v1.14.0 @@ -22,18 +22,18 @@ require ( github.com/swaggo/files v1.0.1 github.com/swaggo/gin-swagger v1.6.0 github.com/swaggo/swag v1.16.4 - github.com/vektah/gqlparser/v2 v2.5.27 + github.com/vektah/gqlparser/v2 v2.5.30 go.uber.org/automaxprocs v1.6.0 go.uber.org/zap v1.27.0 - golang.org/x/crypto v0.38.0 + golang.org/x/crypto v0.39.0 gopkg.in/yaml.v3 v3.0.1 ) require ( github.com/KyleBanks/depth v1.2.1 // indirect github.com/agnivade/levenshtein v1.2.1 // indirect - github.com/andybalholm/brotli v1.1.1 // indirect - github.com/bytedance/sonic v1.13.2 // indirect + github.com/andybalholm/brotli v1.2.0 // indirect + github.com/bytedance/sonic v1.13.3 // indirect github.com/bytedance/sonic/loader v0.2.4 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudflare/circl v1.6.1 // indirect @@ -51,7 +51,7 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect - github.com/go-viper/mapstructure/v2 v2.2.1 // indirect + github.com/go-viper/mapstructure/v2 v2.3.0 // indirect github.com/goccy/go-json v0.10.5 // indirect github.com/google/pprof v0.0.0-20250501235452-c0086092b71a // indirect github.com/google/uuid v1.6.0 // indirect @@ -66,7 +66,7 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.18.0 // indirect - github.com/klauspost/cpuid/v2 v2.2.10 // indirect + github.com/klauspost/cpuid/v2 v2.2.11 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mailru/easyjson v0.9.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -76,27 +76,27 @@ require ( github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/quic-go/qpack v0.5.1 // indirect - github.com/quic-go/quic-go v0.52.0 // indirect + github.com/quic-go/quic-go v0.53.0 // indirect github.com/refraction-networking/utls v1.7.3 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.9.0 // indirect github.com/sosodev/duration v1.3.1 // indirect github.com/sourcegraph/conc v0.3.0 // indirect - github.com/spf13/cast v1.8.0 // indirect + github.com/spf13/cast v1.9.2 // indirect github.com/spf13/pflag v1.0.6 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.12 // indirect - github.com/urfave/cli/v2 v2.27.6 // indirect + github.com/ugorji/go/codec v1.3.0 // indirect + github.com/urfave/cli/v2 v2.27.7 // indirect github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect go.uber.org/mock v0.5.2 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/arch v0.17.0 // indirect - golang.org/x/mod v0.24.0 // indirect - golang.org/x/net v0.40.0 // indirect - golang.org/x/sync v0.14.0 // indirect + golang.org/x/arch v0.18.0 // indirect + golang.org/x/mod v0.25.0 // indirect + golang.org/x/net v0.41.0 // indirect + golang.org/x/sync v0.15.0 // indirect golang.org/x/sys v0.33.0 // indirect - golang.org/x/text v0.25.0 // indirect - golang.org/x/tools v0.33.0 // indirect + golang.org/x/text v0.26.0 // indirect + golang.org/x/tools v0.34.0 // indirect google.golang.org/protobuf v1.36.6 // indirect ) diff --git a/go.sum b/go.sum index 1d73b821..17670eb1 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/99designs/gqlgen v0.17.73 h1:A3Ki+rHWqKbAOlg5fxiZBnz6OjW3nwupDHEG15gEsrg= github.com/99designs/gqlgen v0.17.73/go.mod h1:2RyGWjy2k7W9jxrs8MOQthXGkD3L3oGr0jXW3Pu8lGg= +github.com/99designs/gqlgen v0.17.76 h1:YsJBcfACWmXWU2t1yCjoGdOmqcTfOFpjbLAE443fmYI= +github.com/99designs/gqlgen v0.17.76/go.mod h1:miiU+PkAnTIDKMQ1BseUOIVeQHoiwYDZGCswoxl7xec= github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/PuerkitoBio/goquery v1.10.3 h1:pFYcNSqHxBD06Fpj/KsbStFRsgRATgnf3LeXiUkhzPo= @@ -10,6 +12,8 @@ github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNg github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA= github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA= +github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ= +github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM= github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= @@ -20,6 +24,8 @@ github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ= github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= +github.com/bytedance/sonic v1.13.3 h1:MS8gmaH16Gtirygw7jV91pDCN33NyMrPbN7qiYhEsF0= +github.com/bytedance/sonic v1.13.3/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY= github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= @@ -70,10 +76,14 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k= github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= +github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4= +github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/go-viper/mapstructure/v2 v2.3.0 h1:27XbWsHIqhbdR5TIC911OfYvgSaW93HM+dX7970Q7jk= +github.com/go-viper/mapstructure/v2 v2.3.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= @@ -102,6 +112,8 @@ github.com/icholy/digest v1.1.0 h1:HfGg9Irj7i+IX1o1QAmPfIBNu/Q5A5Tu3n/MED9k9H4= github.com/icholy/digest v1.1.0/go.mod h1:QNrsSGQ5v7v9cReDI0+eyjsXGUoRSUZQHeQ5C4XLa0Y= github.com/imroc/req/v3 v3.52.2 h1:xJocr1aIv0a2K9knfBQ4JnZHk+kWTITdjf0mgDg229I= github.com/imroc/req/v3 v3.52.2/go.mod h1:dBGsDloOSZJcFs6PnTjZXYBJK70OXbZpizHBLNqcH2k= +github.com/imroc/req/v3 v3.54.0 h1:kwWJSpT7OvjJ/Q8ykp+69Ye5H486RKDcgEoepw1Ren4= +github.com/imroc/req/v3 v3.54.0/go.mod h1:P8gCJjG/XNUFeP6WOi40VAXfYwT+uPM00xvoBWiwzUQ= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= @@ -119,6 +131,8 @@ github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYW github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= +github.com/klauspost/cpuid/v2 v2.2.11 h1:0OwqZRYI2rFrjS4kvkDnqJkKHdHaRnCm68/DY4OxRzU= +github.com/klauspost/cpuid/v2 v2.2.11/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -150,8 +164,12 @@ github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI= github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg= github.com/quic-go/quic-go v0.52.0 h1:/SlHrCRElyaU6MaEPKqKr9z83sBg2v4FLLvWM+Z47pA= github.com/quic-go/quic-go v0.52.0/go.mod h1:MFlGGpcpJqRAfmYi6NC2cptDPSxRWTOGNuP4wqrWmzQ= +github.com/quic-go/quic-go v0.53.0 h1:QHX46sISpG2S03dPeZBgVIZp8dGagIaiu2FiVYvpCZI= +github.com/quic-go/quic-go v0.53.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY= github.com/redis/go-redis/v9 v9.8.0 h1:q3nRvjrlge/6UD7eTu/DSg2uYiU2mCL0G/uzBWqhicI= github.com/redis/go-redis/v9 v9.8.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw= +github.com/redis/go-redis/v9 v9.11.0 h1:E3S08Gl/nJNn5vkxd2i78wZxWAPNZgUNTp8WIJUAiIs= +github.com/redis/go-redis/v9 v9.11.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw= github.com/refraction-networking/utls v1.7.3 h1:L0WRhHY7Oq1T0zkdzVZMR6zWZv+sXbHB9zcuvsAEqCo= github.com/refraction-networking/utls v1.7.3/go.mod h1:TUhh27RHMGtQvjQq+RyO11P6ZNQNBb3N0v7wsEjKAIQ= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= @@ -174,6 +192,8 @@ github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA= github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo= github.com/spf13/cast v1.8.0 h1:gEN9K4b8Xws4EX0+a0reLmhq8moKn7ntRlQYgjPeCDk= github.com/spf13/cast v1.8.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cast v1.9.2 h1:SsGfm7M8QOFtEzumm7UZrZdLLquNdzFYfIbEXntcFbE= +github.com/spf13/cast v1.9.2/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4= @@ -200,10 +220,16 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA= +github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4= github.com/urfave/cli/v2 v2.27.6 h1:VdRdS98FNhKZ8/Az8B7MTyGQmpIr36O1EHybx/LaZ4g= github.com/urfave/cli/v2 v2.27.6/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ= +github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU= +github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4= github.com/vektah/gqlparser/v2 v2.5.27 h1:RHPD3JOplpk5mP5JGX8RKZkt2/Vwj/PZv0HxTdwFp0s= github.com/vektah/gqlparser/v2 v2.5.27/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo= +github.com/vektah/gqlparser/v2 v2.5.30 h1:EqLwGAFLIzt1wpx1IPpY67DwUujF1OfzgEyDsLrN6kE= +github.com/vektah/gqlparser/v2 v2.5.30/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo= github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4= github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU= @@ -222,15 +248,21 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/arch v0.17.0 h1:4O3dfLzd+lQewptAHqjewQZQDyEdejz3VwgeYwkZneU= golang.org/x/arch v0.17.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk= +golang.org/x/arch v0.18.0 h1:WN9poc33zL4AzGxqf8VtpKUnGvMi8O9lhNyBMF/85qc= +golang.org/x/arch v0.18.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= +golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM= +golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= +golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w= +golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -239,11 +271,15 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= +golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw= +golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8= +golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -265,12 +301,16 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= +golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M= +golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc= golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI= +golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo= +golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index f7ff2907..e66b37af 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -114,8 +114,9 @@ func (a *authImpl) CheckPassword(hashed, plaintext string) (err error) { // jwtClaim is used internally by the JWT generation and validation routines. type jwtClaim struct { - ClientID uuid.UUID `json:"clientId" yaml:"clientId"` jwt.RegisteredClaims + + ClientID uuid.UUID `json:"clientId" yaml:"clientId"` } // GenerateJWT creates a payload consisting of the JWT with the Client ID and expiration time. @@ -150,8 +151,6 @@ func (a *authImpl) GenerateJWT(clientID uuid.UUID) (*models.JWTAuthResponse, err } // ValidateJWT will validate a signed JWT and extracts the Client ID and unix expiration timestamp from it. -// -//nolint:revive func (a *authImpl) ValidateJWT(signedToken string) (uuid.UUID, int64, error) { token, err := jwt.ParseWithClaims(signedToken, &jwtClaim{}, func(token *jwt.Token) (interface{}, error) { return []byte(a.conf.JWTConfig.Key), nil diff --git a/pkg/common/common.go b/pkg/common/common.go index 171cd155..f7b15134 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -145,7 +145,6 @@ func HTTPTransactionUnpackPageCursor(auth auth.Auth, pageCursor string) ( buffer []byte err error ) - if buffer, err = auth.DecryptFromString(pageCursor); err != nil { return startPGTS, "", endPGTS, "", -1, fmt.Errorf("failed to decrypt page cursor %w", err) } diff --git a/pkg/common/common_test.go b/pkg/common/common_test.go index f614310e..dd2d18ef 100644 --- a/pkg/common/common_test.go +++ b/pkg/common/common_test.go @@ -115,6 +115,7 @@ func TestCommon_HTTPGetCachedOffer(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockCache := mocks.NewMockRedis(mockCtrl) gomock.InOrder( @@ -621,6 +622,7 @@ func TestCommon_HTTPTxDetails(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockPostgres := mocks.NewMockPostgres(mockCtrl) gomock.InOrder( diff --git a/pkg/common/crypto.go b/pkg/common/crypto.go index 280cf780..adb5fd80 100644 --- a/pkg/common/crypto.go +++ b/pkg/common/crypto.go @@ -24,7 +24,6 @@ import ( func HTTPCryptoOpen(db postgres.Postgres, logger *logger.Logger, clientID uuid.UUID, ticker string) ( int, string, error) { var err error - if err = db.CryptoCreateAccount(clientID, ticker); err != nil { var createErr *postgres.Error if !errors.As(err, &createErr) { diff --git a/pkg/common/crypto_test.go b/pkg/common/crypto_test.go index cefeb34f..dccdaa1d 100644 --- a/pkg/common/crypto_test.go +++ b/pkg/common/crypto_test.go @@ -60,6 +60,7 @@ func TestCommon_HTTPCryptoOpen(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockDB := mocks.NewMockPostgres(mockCtrl) mockDB.EXPECT().CryptoCreateAccount(gomock.Any(), gomock.Any()). @@ -135,6 +136,7 @@ func TestCommon_HTTPCryptoBalance(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockDB := mocks.NewMockPostgres(mockCtrl) mockDB.EXPECT().CryptoBalance(gomock.Any(), gomock.Any()). @@ -327,6 +329,7 @@ func TestCommon_HTTPCryptoTxPaginated(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) @@ -585,6 +588,7 @@ func TestCommon_HTTPCryptoOffer(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockCache := mocks.NewMockRedis(mockCtrl) mockQuotes := quotes.NewMockQuotes(mockCtrl) @@ -875,6 +879,7 @@ func TestCommon_HTTPExchangeCrypto(t *testing.T) { //nolint: maintidx // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockCache := mocks.NewMockRedis(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) @@ -1180,6 +1185,7 @@ func TestCommon_HTTPCryptoBalancePaginated(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) diff --git a/pkg/common/fiat.go b/pkg/common/fiat.go index f86f70ca..9b09fa04 100644 --- a/pkg/common/fiat.go +++ b/pkg/common/fiat.go @@ -57,7 +57,6 @@ func HTTPFiatDeposit(db postgres.Postgres, logger *logger.Logger, clientID uuid. err error transferReceipt *postgres.FiatAccountTransferResult ) - if err = validator.ValidateStruct(request); err != nil { return nil, http.StatusBadRequest, constants.ValidationString(), err.Error(), fmt.Errorf("%w", err) } @@ -98,7 +97,6 @@ func HTTPFiatOffer(auth auth.Auth, cache redis.Redis, logger *logger.Logger, quo offer models.HTTPExchangeOfferResponse offerID = xid.New().String() ) - if err = validator.ValidateStruct(request); err != nil { return nil, http.StatusBadRequest, constants.ValidationString(), err.Error(), fmt.Errorf("%w", err) } @@ -157,7 +155,6 @@ func HTTPFiatTransfer(auth auth.Auth, cache redis.Redis, db postgres.Postgres, l offerID string parsedCurrencies []postgres.Currency ) - if err = validator.ValidateStruct(request); err != nil { return nil, http.StatusBadRequest, constants.ValidationString(), err.Error(), fmt.Errorf("%w", err) } diff --git a/pkg/common/fiat_test.go b/pkg/common/fiat_test.go index 57e0c211..d1b178ff 100644 --- a/pkg/common/fiat_test.go +++ b/pkg/common/fiat_test.go @@ -69,6 +69,7 @@ func TestCommon_HTTPFiatOpen(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockDB := mocks.NewMockPostgres(mockCtrl) mockDB.EXPECT().FiatCreateAccount(gomock.Any(), gomock.Any()). @@ -185,6 +186,7 @@ func TestCommon_HTTPFiatDeposit(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockDB := mocks.NewMockPostgres(mockCtrl) mockDB.EXPECT().FiatExternalTransfer(gomock.Any(), gomock.Any()). @@ -336,6 +338,7 @@ func TestCommon_HTTPFiatOffer(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockCache := mocks.NewMockRedis(mockCtrl) mockQuotes := quotes.NewMockQuotes(mockCtrl) @@ -658,6 +661,7 @@ func TestCommon_HTTPFiatTransfer(t *testing.T) { //nolint:maintidx // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockCache := mocks.NewMockRedis(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) @@ -754,6 +758,7 @@ func TestCommon_HTTPFiatBalance(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockDB := mocks.NewMockPostgres(mockCtrl) mockDB.EXPECT().FiatBalance(gomock.Any(), gomock.Any()). @@ -999,6 +1004,7 @@ func TestCommon_HTTPFiatBalancePaginated(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) @@ -1180,6 +1186,7 @@ func TestHandler_TxDetailsFiatPaginated(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) diff --git a/pkg/common/healthcheck_test.go b/pkg/common/healthcheck_test.go index ae51459a..6d7d6795 100644 --- a/pkg/common/healthcheck_test.go +++ b/pkg/common/healthcheck_test.go @@ -61,6 +61,7 @@ func TestCommon_HTTPHealthcheck(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockDB := mocks.NewMockPostgres(mockCtrl) mockCache := mocks.NewMockRedis(mockCtrl) diff --git a/pkg/common/users.go b/pkg/common/users.go index f0db7694..8fc78f80 100644 --- a/pkg/common/users.go +++ b/pkg/common/users.go @@ -50,7 +50,6 @@ func HTTPRegisterUser(auth auth.Auth, db postgres.Postgres, logger *logger.Logge clientID uuid.UUID err error ) - if err = validator.ValidateStruct(user); err != nil { return nil, constants.ValidationString(), http.StatusBadRequest, fmt.Errorf("%w", err), fmt.Errorf("%w", err) } @@ -90,7 +89,6 @@ func HTTPLoginUser(auth auth.Auth, db postgres.Postgres, logger *logger.Logger, clientID uuid.UUID hashedPassword string ) - if err = validator.ValidateStruct(loginRequest); err != nil { return nil, constants.ValidationString(), http.StatusBadRequest, fmt.Errorf("%w", err), fmt.Errorf("%w", err) } @@ -120,7 +118,6 @@ func HTTPRefreshLogin(auth auth.Auth, db postgres.Postgres, logger *logger.Logge freshToken *models.JWTAuthResponse accountInfo modelsPostgres.User ) - if accountInfo, err = db.UserGetInfo(clientID); err != nil { logger.Warn("failed to read user record for a valid JWT", zap.String("username", accountInfo.Username), zap.Error(err)) @@ -158,7 +155,6 @@ func HTTPDeleteUser(auth auth.Auth, db postgres.Postgres, logger *logger.Logger, err error userAccount modelsPostgres.User ) - if err = validator.ValidateStruct(deleteRequest); err != nil { return constants.ValidationString(), http.StatusBadRequest, fmt.Errorf("%w", err), fmt.Errorf("%w", err) } diff --git a/pkg/common/users_test.go b/pkg/common/users_test.go index 0abd585f..b68dfbf7 100644 --- a/pkg/common/users_test.go +++ b/pkg/common/users_test.go @@ -129,6 +129,7 @@ func TestCommon_HTTPUserRegister(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) @@ -256,6 +257,7 @@ func TestCommon_HTTPUserLogin(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) @@ -388,6 +390,7 @@ func TestCommon_HTTPLoginRefresh(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) @@ -617,6 +620,7 @@ func TestCommon_DeleteUser(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) diff --git a/pkg/graphql/resolvers/authorization.go b/pkg/graphql/resolvers/authorization.go index 74cc7806..d3969554 100644 --- a/pkg/graphql/resolvers/authorization.go +++ b/pkg/graphql/resolvers/authorization.go @@ -45,7 +45,6 @@ func AuthorizationCheck(ctx context.Context, auth auth.Auth, db postgres.Postgre isDeleted bool ginContext *gin.Context ) - if ginContext, err = GinContextFromContext(ctx, logger); err != nil { return clientID, -1, err } diff --git a/pkg/graphql/resolvers/authorization_test.go b/pkg/graphql/resolvers/authorization_test.go index 7517f984..19579333 100644 --- a/pkg/graphql/resolvers/authorization_test.go +++ b/pkg/graphql/resolvers/authorization_test.go @@ -152,6 +152,7 @@ func TestAuthorizationCheck(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) diff --git a/pkg/graphql/resolvers/crypto.resolvers_test.go b/pkg/graphql/resolvers/crypto.resolvers_test.go index 86097fad..b6fe2c01 100644 --- a/pkg/graphql/resolvers/crypto.resolvers_test.go +++ b/pkg/graphql/resolvers/crypto.resolvers_test.go @@ -99,6 +99,7 @@ func TestCryptoResolver_OpenCrypto(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // Not called. @@ -393,6 +394,7 @@ func TestCryptoResolver_OfferCrypto(t *testing.T) { //nolint:maintidx // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) // Not called. mockRedis := mocks.NewMockRedis(mockCtrl) @@ -654,6 +656,7 @@ func TestCryptoResolver_ExchangeCrypto(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) @@ -874,6 +877,7 @@ func TestCryptoResolver_BalanceCrypto(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // Not called. @@ -1126,6 +1130,7 @@ func TestCryptoResolver_BalanceAllCrypto(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // not called. @@ -1289,6 +1294,7 @@ func TestCryptoResolver_TransactionDetailsCrypto(t *testing.T) { //nolint:dupl // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // Not called. @@ -1536,6 +1542,7 @@ func TestCryptoResolver_TransactionDetailsAllCrypto(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // not called. diff --git a/pkg/graphql/resolvers/fiat.resolvers_test.go b/pkg/graphql/resolvers/fiat.resolvers_test.go index 9ad5d6e5..bf834b6e 100644 --- a/pkg/graphql/resolvers/fiat.resolvers_test.go +++ b/pkg/graphql/resolvers/fiat.resolvers_test.go @@ -112,6 +112,7 @@ func TestFiatResolver_OpenFiat(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // Not called. @@ -337,6 +338,7 @@ func TestFiatResolver_DepositFiat(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // Not called. @@ -639,6 +641,7 @@ func TestFiatResolver_ExchangeOfferFiat(t *testing.T) { //nolint:maintidx // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) // Not called. mockRedis := mocks.NewMockRedis(mockCtrl) @@ -1011,6 +1014,7 @@ func TestFiatResolver_ExchangeTransferFiat(t *testing.T) { //nolint:maintidx // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) @@ -1236,6 +1240,7 @@ func TestFiatResolver_BalanceFiat(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // not called. @@ -1488,6 +1493,7 @@ func TestFiatResolver_BalanceAllFiat(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // not called. @@ -1717,6 +1723,7 @@ func TestFiatResolver_TransactionDetailsFiat(t *testing.T) { //nolint:dupl // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // Not called. @@ -1970,6 +1977,7 @@ func TestFiatResolver_TransactionDetailsAllFiat(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // not called. diff --git a/pkg/graphql/resolvers/handlers_test.go b/pkg/graphql/resolvers/handlers_test.go index bce370b3..5df94cb1 100644 --- a/pkg/graphql/resolvers/handlers_test.go +++ b/pkg/graphql/resolvers/handlers_test.go @@ -16,6 +16,7 @@ func TestQueryHandler(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) diff --git a/pkg/graphql/resolvers/healthcheck.resolvers_test.go b/pkg/graphql/resolvers/healthcheck.resolvers_test.go index f70f5d11..4f89bd08 100644 --- a/pkg/graphql/resolvers/healthcheck.resolvers_test.go +++ b/pkg/graphql/resolvers/healthcheck.resolvers_test.go @@ -70,6 +70,7 @@ func TestQueryResolver_Healthcheck(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) // Not called. mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) diff --git a/pkg/graphql/resolvers/user.resolvers_test.go b/pkg/graphql/resolvers/user.resolvers_test.go index c05203d8..a0cc66b1 100644 --- a/pkg/graphql/resolvers/user.resolvers_test.go +++ b/pkg/graphql/resolvers/user.resolvers_test.go @@ -107,6 +107,7 @@ func TestUserResolver_RegisterUser(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // Not called. @@ -382,6 +383,7 @@ func TestUserResolver_DeleteUser(t *testing.T) { //nolint:maintidx // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // Not called. @@ -529,6 +531,7 @@ func TestUserResolver_LoginUser(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // Not called. @@ -770,6 +773,7 @@ func TestUserResolver_RefreshToken(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) mockRedis := mocks.NewMockRedis(mockCtrl) // Not called. diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index f6d99120..55f3d4e1 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -31,7 +31,6 @@ func NewTestLogger() (*Logger, error) { err error zapLogger *zap.Logger ) - if zapLogger, err = baseConfig.Build(zap.AddCallerSkip(1)); err != nil { log.Printf("failure configuring logger: %v\n", err) diff --git a/pkg/logger/main_test.go b/pkg/logger/main_test.go index 5f969bfe..1f2c5270 100644 --- a/pkg/logger/main_test.go +++ b/pkg/logger/main_test.go @@ -14,6 +14,7 @@ var loggerConfigTestData = configTestData() // testLogSpy is a testing.TB that captures logged messages. type testLogSpy struct { testing.TB + failed bool Messages []string } diff --git a/pkg/models/http.go b/pkg/models/http.go index e6840f17..bbd6fa87 100644 --- a/pkg/models/http.go +++ b/pkg/models/http.go @@ -32,6 +32,7 @@ type HTTPSuccess struct { // as well as a confirmation message. type HTTPDeleteUserRequest struct { modelsPostgres.UserLoginCredentials + Confirmation string `json:"confirmation" validate:"required" yaml:"confirmation"` } @@ -55,13 +56,15 @@ type HTTPExchangeOfferRequest struct { // HTTPCryptoOfferRequest is a request to convert a source to destination currency in the source currency amount. type HTTPCryptoOfferRequest struct { - HTTPExchangeOfferRequest `json:"request" validate:"required" yaml:"request"` - IsPurchase *bool `json:"isPurchase" validate:"required" yaml:"isPurchase"` + HTTPExchangeOfferRequest `json:"request" validate:"required" yaml:"request"` + + IsPurchase *bool `json:"isPurchase" validate:"required" yaml:"isPurchase"` } // HTTPExchangeOfferResponse is an offer to convert a source to destination currency in the source currency amount. type HTTPExchangeOfferResponse struct { - PriceQuote `json:"offer" yaml:"offer"` + PriceQuote `json:"offer" yaml:"offer"` + DebitAmount decimal.Decimal `json:"debitAmount" yaml:"debitAmount"` OfferID string `json:"offerId" yaml:"offerId"` Expires int64 `json:"expires" yaml:"expires"` diff --git a/pkg/models/postgres/user.go b/pkg/models/postgres/user.go index 023ff1b4..3cd0687e 100644 --- a/pkg/models/postgres/user.go +++ b/pkg/models/postgres/user.go @@ -7,6 +7,7 @@ import ( // User represents a user's account and is a row in the user table. type User struct { *UserAccount + ClientID uuid.UUID `json:"clientId,omitempty"` IsDeleted bool `json:"isDeleted"` } @@ -14,6 +15,7 @@ type User struct { // UserAccount is the core user account information. type UserAccount struct { UserLoginCredentials + FirstName string `json:"firstName,omitempty" validate:"required,max=64"` LastName string `json:"lastName,omitempty" validate:"required,max=64"` Email string `json:"email,omitempty" validate:"required,email,max=64"` diff --git a/pkg/postgres/models_sqlc_test.go b/pkg/postgres/models_sqlc_test.go index 985ee854..31b30e0e 100644 --- a/pkg/postgres/models_sqlc_test.go +++ b/pkg/postgres/models_sqlc_test.go @@ -9,24 +9,28 @@ import ( func TestModels_CurrencyScan(t *testing.T) { t.Run("Byte Array", func(t *testing.T) { var curr Currency + err := curr.Scan([]byte(CurrencyUSD)) require.NoError(t, err, "valid byte array") }) t.Run("String", func(t *testing.T) { var curr Currency + err := curr.Scan("USD") require.NoError(t, err, "valid string") }) t.Run("Valid string, invalid currency", func(t *testing.T) { var curr Currency + err := curr.Scan("UVW") require.NoError(t, err, "valid string") }) t.Run("Invalid Type", func(t *testing.T) { var curr Currency + err := curr.Scan(123) require.Error(t, err, "invalid type") }) diff --git a/pkg/postgres/queries_users_test.go b/pkg/postgres/queries_users_test.go index 6c5deaea..c4cf924c 100644 --- a/pkg/postgres/queries_users_test.go +++ b/pkg/postgres/queries_users_test.go @@ -84,6 +84,7 @@ func TestQueries_UserGetInfo(t *testing.T) { // Get valid account information. const uname = "username1" + expectedAccount := getTestUsers()[uname] clientID, err := connection.queries.userGetClientId(t.Context(), uname) diff --git a/pkg/quotes/quotes_test.go b/pkg/quotes/quotes_test.go index 9d8ff223..194510ff 100644 --- a/pkg/quotes/quotes_test.go +++ b/pkg/quotes/quotes_test.go @@ -217,6 +217,7 @@ func TestQuotesImpl_FiatConversion_Mock(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockQuotes := NewMockQuotes(mockCtrl) quote := models.FiatQuote{Info: models.FiatInfo{Rate: test.rate}} @@ -428,6 +429,7 @@ func TestQuotesImpl_CryptoConversion_Mock(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockQuotes := NewMockQuotes(mockCtrl) quote := models.CryptoQuote{Rate: test.rate} diff --git a/pkg/redis/redis.go b/pkg/redis/redis.go index c166fe99..cf3f093c 100644 --- a/pkg/redis/redis.go +++ b/pkg/redis/redis.go @@ -166,7 +166,6 @@ func (r *redisImpl) Get(key string, value any) error { err error rawData []byte ) - if rawData, err = r.redisDB.Get(context.Background(), key).Bytes(); err != nil { return NewError(err.Error()).errorCacheMiss() } diff --git a/pkg/redis/redis_test.go b/pkg/redis/redis_test.go index d24c9171..404b658e 100644 --- a/pkg/redis/redis_test.go +++ b/pkg/redis/redis_test.go @@ -236,6 +236,7 @@ func TestRedisImpl_Set_Get_Del(t *testing.T) { // Check to see if data has been removed. var deleted *string + err = connection.Get(test.key, deleted) require.Nil(t, deleted, "returned data from a deleted record should be nil") require.Error(t, err, "deleted record should not be found on redis Redis server") @@ -253,6 +254,7 @@ func TestRedisImpl_Set_Get_Del(t *testing.T) { t.Run("Expiration check: "+test.name, func(t *testing.T) { var deleted *string + err := connection.Get(test.key, deleted) require.Nil(t, deleted, "returned data from a deleted record should be nil") require.Error(t, err, "deleted record should not be found on redis Redis server") diff --git a/pkg/rest/handlers/authorization_test.go b/pkg/rest/handlers/authorization_test.go index f9d1e39f..a467cd91 100644 --- a/pkg/rest/handlers/authorization_test.go +++ b/pkg/rest/handlers/authorization_test.go @@ -18,6 +18,7 @@ func TestAuthMiddleware(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) @@ -113,6 +114,7 @@ func TestAuthMiddleware_Handler(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) diff --git a/pkg/rest/handlers/crypto.go b/pkg/rest/handlers/crypto.go index b944c480..f8958710 100644 --- a/pkg/rest/handlers/crypto.go +++ b/pkg/rest/handlers/crypto.go @@ -42,7 +42,6 @@ func OpenCrypto(logger *logger.Logger, auth auth.Auth, db postgres.Postgres) gin httpStatus int httpMessage string ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -98,7 +97,6 @@ func OfferCrypto(logger *logger.Logger, auth auth.Auth, cache redis.Redis, quote status int statusMessage string ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -161,7 +159,6 @@ func ExchangeCrypto(logger *logger.Logger, auth auth.Auth, cache redis.Redis, db clientID uuid.UUID request models.HTTPTransferRequest ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -220,7 +217,6 @@ func BalanceCrypto(logger *logger.Logger, auth auth.Auth, db postgres.Postgres) httpMessage string payload any ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -261,7 +257,6 @@ func TxDetailsCrypto(logger *logger.Logger, auth auth.Auth, db postgres.Postgres transactionID = ginCtx.Param("transactionID") err error ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -310,7 +305,6 @@ func BalanceCryptoPaginated(logger *logger.Logger, auth auth.Auth, db postgres.P clientID uuid.UUID err error ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -372,7 +366,6 @@ func TxDetailsCryptoPaginated(logger *logger.Logger, auth auth.Auth, db postgres YearStr: ginCtx.Query("year"), } ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) diff --git a/pkg/rest/handlers/crypto_test.go b/pkg/rest/handlers/crypto_test.go index 85181aa0..aac6ec67 100644 --- a/pkg/rest/handlers/crypto_test.go +++ b/pkg/rest/handlers/crypto_test.go @@ -91,6 +91,7 @@ func TestHandlers_OpenCrypto(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) @@ -428,6 +429,7 @@ func TestHandlers_OfferCrypto(t *testing.T) { //nolint:maintidx // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockCache := mocks.NewMockRedis(mockCtrl) mockQuotes := quotes.NewMockQuotes(mockCtrl) @@ -630,6 +632,7 @@ func TestHandlers_ExchangeCrypto(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockCache := mocks.NewMockRedis(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) @@ -767,6 +770,7 @@ func TestHandler_BalanceCrypto(t *testing.T) { //nolint:dupl // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) @@ -872,6 +876,7 @@ func TestHandler_TxDetailsCrypto(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) @@ -1080,6 +1085,7 @@ func TestHandler_BalanceCurrencyCryptoPaginated(t *testing.T) { //nolint:dupl // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) @@ -1275,6 +1281,7 @@ func TestHandler_TxDetailsCryptoPaginated(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) diff --git a/pkg/rest/handlers/fiat.go b/pkg/rest/handlers/fiat.go index cdf663e2..1f53ddcc 100644 --- a/pkg/rest/handlers/fiat.go +++ b/pkg/rest/handlers/fiat.go @@ -42,7 +42,6 @@ func OpenFiat(logger *logger.Logger, auth auth.Auth, db postgres.Postgres) gin.H httpStatus int httpMessage string ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -99,7 +98,6 @@ func DepositFiat(logger *logger.Logger, auth auth.Auth, db postgres.Postgres) gi request models.HTTPDepositCurrencyRequest transferReceipt *postgres.FiatAccountTransferResult ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -149,7 +147,6 @@ func ExchangeOfferFiat(logger *logger.Logger, auth auth.Auth, cache redis.Redis, request models.HTTPExchangeOfferRequest offer *models.HTTPExchangeOfferResponse ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -204,7 +201,6 @@ func ExchangeTransferFiat( httpMessage string payload any ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -256,7 +252,6 @@ func BalanceFiat(logger *logger.Logger, auth auth.Auth, db postgres.Postgres) gi httpMessage string payload any ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -297,7 +292,6 @@ func TxDetailsFiat(logger *logger.Logger, auth auth.Auth, db postgres.Postgres) transactionID = ginCtx.Param("transactionID") err error ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -346,7 +340,6 @@ func BalanceFiatPaginated(logger *logger.Logger, auth auth.Auth, db postgres.Pos httpStatus int httpMessage string ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -408,7 +401,6 @@ func TxDetailsFiatPaginated(logger *logger.Logger, auth auth.Auth, db postgres.P YearStr: ginCtx.Query("year"), } ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) diff --git a/pkg/rest/handlers/fiat_test.go b/pkg/rest/handlers/fiat_test.go index 67bbc0eb..0f812e4b 100644 --- a/pkg/rest/handlers/fiat_test.go +++ b/pkg/rest/handlers/fiat_test.go @@ -101,6 +101,7 @@ func TestHandlers_OpenFiat(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) @@ -236,6 +237,7 @@ func TestHandlers_DepositFiat(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) @@ -488,6 +490,7 @@ func TestHandlers_ExchangeOfferFiat(t *testing.T) { //nolint:maintidx // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockCache := mocks.NewMockRedis(mockCtrl) mockQuotes := quotes.NewMockQuotes(mockCtrl) @@ -844,6 +847,7 @@ func TestHandler_ExchangeTransferFiat(t *testing.T) { //nolint:maintidx // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockCache := mocks.NewMockRedis(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) @@ -975,6 +979,7 @@ func TestHandler_BalanceFiat(t *testing.T) { //nolint:dupl // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) @@ -1124,6 +1129,7 @@ func TestHandler_TxDetailsFiat(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) @@ -1332,6 +1338,7 @@ func TestHandler_BalanceFiatPaginated(t *testing.T) { //nolint:dupl // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) @@ -1543,6 +1550,7 @@ func TestHandler_TxDetailsFiatPaginated(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockDB := mocks.NewMockPostgres(mockCtrl) diff --git a/pkg/rest/handlers/users.go b/pkg/rest/handlers/users.go index 4f09229d..570b1482 100644 --- a/pkg/rest/handlers/users.go +++ b/pkg/rest/handlers/users.go @@ -37,7 +37,6 @@ func RegisterUser(logger *logger.Logger, auth auth.Auth, db postgres.Postgres) g httpStatus int payload any ) - if err = ginCtx.ShouldBindJSON(&user); err != nil { ginCtx.AbortWithStatusJSON(http.StatusBadRequest, &models.HTTPError{Message: err.Error()}) @@ -78,7 +77,6 @@ func LoginUser(logger *logger.Logger, auth auth.Auth, db postgres.Postgres) gin. httpStatus int payload any ) - if err = ginCtx.ShouldBindJSON(&loginRequest); err != nil { ginCtx.AbortWithStatusJSON(http.StatusBadRequest, &models.HTTPError{Message: err.Error()}) @@ -118,7 +116,6 @@ func LoginRefresh(logger *logger.Logger, auth auth.Auth, db postgres.Postgres) g httpMsg string httpStatus int ) - if clientID, expiresAt, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) @@ -161,7 +158,6 @@ func DeleteUser(logger *logger.Logger, auth auth.Auth, db postgres.Postgres) gin httpStatus int payload any ) - if clientID, _, err = auth.TokenInfoFromGinCtx(ginCtx); err != nil { ginCtx.AbortWithStatusJSON(http.StatusForbidden, &models.HTTPError{Message: "malformed authentication token"}) diff --git a/pkg/rest/handlers/users_test.go b/pkg/rest/handlers/users_test.go index 63efe094..fa7de0a9 100644 --- a/pkg/rest/handlers/users_test.go +++ b/pkg/rest/handlers/users_test.go @@ -115,6 +115,7 @@ func TestHandlers_UserRegister(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) @@ -231,6 +232,7 @@ func TestHandlers_UserLogin(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) @@ -402,6 +404,7 @@ func TestHandlers_LoginRefresh(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) @@ -659,6 +662,7 @@ func TestHandlers_DeleteUser(t *testing.T) { // Mock configurations. mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() + mockAuth := mocks.NewMockAuth(mockCtrl) mockPostgres := mocks.NewMockPostgres(mockCtrl) diff --git a/pkg/rest/rest.go b/pkg/rest/rest.go index c4431945..39f073cb 100644 --- a/pkg/rest/rest.go +++ b/pkg/rest/rest.go @@ -118,7 +118,7 @@ func (s *Server) initialize() { s.router = gin.Default() // @title FTeX, Inc. (Formerly Crypto-Bro's Bank, Inc.) - // @version 1.2.8 + // @version 1.2.9 // @description FTeX Fiat and Cryptocurrency Banking API. // @description Bank, buy, and sell Fiat and Cryptocurrencies. Prices for all currencies are retrieved from real-time quote providers. // diff --git a/pkg/validator/validator.go b/pkg/validator/validator.go index 5d4fcd20..4e199b5d 100644 --- a/pkg/validator/validator.go +++ b/pkg/validator/validator.go @@ -20,10 +20,10 @@ func ValidateStruct(body any) error { validationErr ValidationError errs validator.ValidationErrors ) - if errors.As(structValidator.Struct(body), &errs) { for _, issue := range errs { var ev FieldError + ev.Field = issue.Field() ev.Tag = issue.Tag() ev.Value = issue.Value() diff --git a/pkg/validator/validator_test.go b/pkg/validator/validator_test.go index 528e81a0..e8c17880 100644 --- a/pkg/validator/validator_test.go +++ b/pkg/validator/validator_test.go @@ -11,6 +11,7 @@ import ( func TestErrorField_Error(t *testing.T) { const errorStr = "Field: %s, Tag: %s, Value: %s\n" + testCases := []struct { name string input *FieldError