diff --git a/.github/workflows/go_test.yml b/.github/workflows/go_test.yml index 3400115..7edf9de 100644 --- a/.github/workflows/go_test.yml +++ b/.github/workflows/go_test.yml @@ -20,11 +20,19 @@ jobs: - name: Check out code uses: actions/checkout@v3 - - name: Build + - name: Build listener run: | cd ./listener go build -a -installsuffix cgo -o bin/listener ./cmd/listener + - name: Build jwt-generator + run: | + cd ./listener + go build -a -installsuffix cgo -o bin/jwt-generator ./cmd/jwt-generator + + - name: Setup Integration Test Environment + run: | + docker compose -f docker-compose-ci.yml up --build -d - name: Test run: | cd ./listener diff --git a/.gitignore b/.gitignore index 89eea8f..58a92d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .env ./listener/tmp/* ./listener/bin/* -jwt private.pem public.pem \ No newline at end of file diff --git a/ci.env b/ci.env new file mode 100644 index 0000000..70cb140 --- /dev/null +++ b/ci.env @@ -0,0 +1,11 @@ +MONGO_INITDB_ROOT_USERNAME=dappnode +MONGO_INITDB_ROOT_PASSWORD=dappnode +MONGO_DB_API_PORT=27017 +API_PORT=8080 +LOG_LEVEL=DEBUG +MAX_ENTRIES_PER_BSON=30 +BEACON_NODE_URL_MAINNET=http://172.33.0.27:3500 +BEACON_NODE_URL_HOLESKY=http://172.33.0.27:3500 +BEACON_NODE_URL_GNOSIS=http://172.33.0.27:3500 +BEACON_NODE_URL_LUKSO=http://172.33.0.27:3500 +JWT_USERS_FILE=users.json.example \ No newline at end of file diff --git a/docker-compose-ci.yml b/docker-compose-ci.yml new file mode 100644 index 0000000..90b71cd --- /dev/null +++ b/docker-compose-ci.yml @@ -0,0 +1,41 @@ +version: "3.9" + +networks: + listener-net-ci: + driver: bridge + +volumes: + mongo_data_ci: {} + +services: + listener: + build: + context: listener + dockerfile: Dockerfile + env_file: + - ci.env + environment: + MONGO_DB_URI: "mongodb://dappnode:dappnode@mongo:27017" + depends_on: + - mongo + container_name: listener + restart: always + volumes: + - ./jwt:/app/jwt ## listener expects /app/jwt to exist, careful when changing this path + networks: + - listener-net-ci + ports: + - "8080:8080" # should be same as API_PORT of ci.env + + mongo: + build: + context: mongo + volumes: + - mongo_data_ci:/data/db + env_file: + - ci.env + command: ["mongod", "--config", "/etc/mongo/mongod.conf"] + container_name: mongo + restart: always + networks: + - listener-net-ci \ No newline at end of file diff --git a/listener/Dockerfile b/listener/Dockerfile index 9fd2bc9..4a57aa4 100644 --- a/listener/Dockerfile +++ b/listener/Dockerfile @@ -1,5 +1,5 @@ # Start from the latest golang base image -FROM golang:1.22.0-alpine3.19 as builder +FROM golang:1.22.3 as builder # Set the Current Working Directory inside the container. WORKDIR /app @@ -14,7 +14,7 @@ COPY internal/ ./internal/ COPY cmd/ ./cmd/ # Build the application, outputting the executable to /bin directory. -RUN CGO_ENABLED=0 GOOS=linux go build -v -o /bin/listener ./cmd/listener/main.go +RUN CGO_ENABLED=1 GOOS=linux go build -v -o /bin/listener ./cmd/listener/main.go # Use a Docker multi-stage build to create a lean production image. # # build-essential required by dependency github.com/herumi/bls-eth-go-binary diff --git a/listener/cmd/jwt-generator/main.go b/listener/cmd/jwt-generator/main.go index 507e237..5d7dbfc 100644 --- a/listener/cmd/jwt-generator/main.go +++ b/listener/cmd/jwt-generator/main.go @@ -4,73 +4,36 @@ import ( "flag" "fmt" "os" - "time" + "github.com/dappnode/validator-monitoring/listener/internal/jwt" "github.com/dappnode/validator-monitoring/listener/internal/logger" - - "github.com/golang-jwt/jwt/v5" ) func main() { - // Define flags for the command-line input privateKeyPath := flag.String("private-key", "", "Path to the RSA private key file (mandatory)") subject := flag.String("sub", "", "Subject claim for the JWT (optional)") - expiration := flag.String("exp", "", "Expiration duration for the JWT in hours (optional, e.g., '24h' for 24 hours). If no value is provided, the generated token will not expire.") + expiration := flag.String("exp", "", "Expiration duration for the JWT in hours (optional)") kid := flag.String("kid", "", "Key ID (kid) for the JWT (mandatory)") - outputFilePath := flag.String("output", "token.jwt", "Output file path for the JWT. Defaults to ./token.jwt") + outputFilePath := flag.String("output", "token.jwt", "Output file path for the JWT") flag.Parse() - // Check for mandatory parameters if *kid == "" || *privateKeyPath == "" { logger.Fatal("Key ID (kid) and private key path must be provided") } - // Read the private key file - privateKeyData, err := os.ReadFile(*privateKeyPath) - if err != nil { - logger.Fatal(fmt.Sprintf("Failed to read private key file: %v", err)) - } - - // Parse the RSA private key - privateKey, err := jwt.ParseRSAPrivateKeyFromPEM(privateKeyData) + tokenString, err := jwt.GenerateJWT(*kid, *privateKeyPath, *subject, *expiration) if err != nil { - logger.Fatal(fmt.Sprintf("Failed to parse private key: %v", err)) - } - - // Prepare the claims for the JWT. These are optional - claims := jwt.MapClaims{} - if *subject != "" { - claims["sub"] = *subject - } - if *expiration != "" { - duration, err := time.ParseDuration(*expiration) - if err != nil { - logger.Fatal(fmt.Sprintf("Failed to parse expiration duration: %v", err)) - } - claims["exp"] = time.Now().Add(duration).Unix() + logger.Fatal(fmt.Sprintf("Error generating JWT: %v", err)) } - // Create a new token object, specifying signing method and claims - token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims) - - // Set the key ID (kid) in the token header - token.Header["kid"] = *kid - - // Sign the token with the private key - tokenString, err := token.SignedString(privateKey) - if err != nil { - logger.Fatal(fmt.Sprintf("Failed to sign token: %v", err)) - } - - // Output the token to the console fmt.Println("JWT generated successfully:") fmt.Println(tokenString) - // Save the token to a file err = os.WriteFile(*outputFilePath, []byte(tokenString), 0644) if err != nil { logger.Fatal(fmt.Sprintf("Failed to write the JWT to file: %v", err)) } + fmt.Println("JWT saved to file:", *outputFilePath) } diff --git a/listener/go.mod b/listener/go.mod index 3d41fea..08b73c8 100644 --- a/listener/go.mod +++ b/listener/go.mod @@ -3,6 +3,7 @@ module github.com/dappnode/validator-monitoring/listener go 1.22.0 require ( + github.com/gavv/httpexpect/v2 v2.16.0 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/gorilla/mux v1.8.1 github.com/herumi/bls-eth-go-binary v1.35.0 @@ -11,14 +12,46 @@ require ( ) require ( + github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 // indirect + github.com/ajg/form v1.5.1 // indirect + github.com/andybalholm/brotli v1.0.4 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fatih/color v1.15.0 // indirect + github.com/fatih/structs v1.1.0 // indirect + github.com/gobwas/glob v0.2.3 // indirect github.com/golang/snappy v0.0.1 // indirect - github.com/klauspost/compress v1.13.6 // indirect + github.com/google/go-querystring v1.1.0 // indirect + github.com/gorilla/websocket v1.4.2 // indirect + github.com/hpcloud/tail v1.0.0 // indirect + github.com/imkira/go-interpol v1.1.0 // indirect + github.com/klauspost/compress v1.15.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.18 // indirect + github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/sanity-io/litter v1.5.5 // indirect + github.com/sergi/go-diff v1.0.0 // indirect + github.com/stretchr/testify v1.5.0 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasthttp v1.34.0 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect + github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect + github.com/xeipuuv/gojsonschema v1.2.0 // indirect + github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect + github.com/yudai/gojsondiff v1.0.0 // indirect + github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect golang.org/x/crypto v0.17.0 // indirect + golang.org/x/net v0.10.0 // indirect golang.org/x/sync v0.1.0 // indirect + golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect + gopkg.in/fsnotify.v1 v1.4.7 // indirect + gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + moul.io/http2curl/v2 v2.3.0 // indirect ) diff --git a/listener/go.sum b/listener/go.sum index b272ac8..01feaaf 100644 --- a/listener/go.sum +++ b/listener/go.sum @@ -1,60 +1,169 @@ +github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 h1:ZBbLwSJqkHBuFDA6DUhhse0IGJ7T5bemHyNILUjvOq4= +github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2/go.mod h1:VSw57q4QFiWDbRnjdX8Cb3Ow0SFncRw+bA/ofY6Q83w= +github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= +github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= +github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= +github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= +github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= +github.com/gavv/httpexpect/v2 v2.16.0 h1:Ty2favARiTYTOkCRZGX7ojXXjGyNAIohM1lZ3vqaEwI= +github.com/gavv/httpexpect/v2 v2.16.0/go.mod h1:uJLaO+hQ25ukBJtQi750PsztObHybNllN+t+MbbW8PY= +github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= +github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/herumi/bls-eth-go-binary v1.35.0 h1:4CgrKurBK4g0ZMKBdHq5CwK9slYe7Ei+HF+/n6RSkOI= github.com/herumi/bls-eth-go-binary v1.35.0/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= -github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= -github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f h1:7LYC+Yfkj3CTRcShK0KOL/w6iTiKyqqBA9a41Wnggw8= +github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f/go.mod h1:pFlLw2CfqZiIBOx6BuCeRLCrfxBJipTY0nIOF/VbGcI= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/imkira/go-interpol v1.1.0 h1:KIiKr0VSG2CUW1hl1jpiyuzuJeKUUpC8iM1AIE7N1Vk= +github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA= +github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U= +github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= +github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= +github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo= +github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= +github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pkg/diff v0.0.0-20200914180035-5b29258ca4f7/go.mod h1:zO8QMzTeZd5cpnIkz/Gn6iK0jDfGicM1nynOkkPIl28= +github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ= github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k= +github.com/sanity-io/litter v1.5.5 h1:iE+sBxPBzoK6uaEP5Lt3fHNgpKcHXc/A2HGETy0uJQo= +github.com/sanity-io/litter v1.5.5/go.mod h1:9gzJgR2i4ZpjZHsKvUXIRQVk7P+yM3e+jAF7bU2UI5U= +github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.0 h1:DMOzIV76tmoDNE9pX6RSN0aDtCYeCg5VueieJaAo1uw= +github.com/stretchr/testify v1.5.0/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502/go.mod h1:p9lPsd+cx33L3H9nNoecRRxPssFKUwwI50I3pZ0yT+8= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.34.0 h1:d3AAQJ2DRcxJYHm7OXNXtXt2as1vMDfxeIcFvhmGGm4= +github.com/valyala/fasthttp v1.34.0/go.mod h1:epZA5N+7pY6ZaEKRmstzOuYJx9HI8DI1oaCGZpdH4h0= +github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo= +github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= +github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= +github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 h1:6fRhSjgLCkTD3JnJxvaJ4Sj+TYblw757bqYgZaOq5ZY= +github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= +github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= +github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= +github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= +github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= +github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI= +github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80= go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= 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-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +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-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/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.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 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-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= 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.0.0-20201211185031-d93e913c1a58/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +moul.io/http2curl/v2 v2.3.0 h1:9r3JfDzWPcbIklMOs2TnIFzDYvfAZvjeavG6EzP7jYs= +moul.io/http2curl/v2 v2.3.0/go.mod h1:RW4hyBjTWSYDOxapodpNEtX0g5Eb16sxklBqmd2RHcE= diff --git a/listener/internal/api/handlers/postSignatures.go b/listener/internal/api/handlers/postSignatures.go index 74b2863..f57168b 100644 --- a/listener/internal/api/handlers/postSignatures.go +++ b/listener/internal/api/handlers/postSignatures.go @@ -39,14 +39,26 @@ func PostSignatures(w http.ResponseWriter, r *http.Request, dbCollection *mongo. return } + if len(requests) == 0 { + logger.Error("No valid requests in payload") + respondError(w, http.StatusBadRequest, "No requests in payload") + return + } + + // Process each request and validate requestsValidatedAndDecoded, err := validation.ValidateAndDecodeRequests(requests) - if err != nil || len(requestsValidatedAndDecoded) == 0 { + if err != nil { logger.Error("Failed to validate and decode requests: " + err.Error()) respondError(w, http.StatusBadRequest, "No valid requests") return } + if len(requestsValidatedAndDecoded) == 0 { + logger.Error("All signature requests are invalid after decoding") + respondError(w, http.StatusBadRequest, "No valid requests") + return + } - // Get active validators + // Get active validators and process signatures pubkeys := getPubkeys(requestsValidatedAndDecoded) validatorsStatusMap, err := validation.GetValidatorsStatus(pubkeys, beaconNodeUrl) if err != nil { @@ -55,7 +67,6 @@ func PostSignatures(w http.ResponseWriter, r *http.Request, dbCollection *mongo. return } - // Filter and verify signatures validSignatures := filterAndVerifySignatures(requestsValidatedAndDecoded, validatorsStatusMap) if len(validSignatures) == 0 { respondError(w, http.StatusBadRequest, "No valid signatures") diff --git a/listener/internal/api/validation/validateAndDecodeRequests.go b/listener/internal/api/validation/validateAndDecodeRequests.go index 490b0a3..82d3851 100644 --- a/listener/internal/api/validation/validateAndDecodeRequests.go +++ b/listener/internal/api/validation/validateAndDecodeRequests.go @@ -47,6 +47,24 @@ func isValidCodedRequest(req *types.SignatureRequest) bool { return false } + // Define a map for quick lookup of valid tags. + validTags := map[types.Tag]bool{ + types.Obol: true, + types.Diva: true, + types.Ssv: true, + types.Rocketpool: true, + types.Stakewise: true, + types.Stakehouse: true, + types.Solo: true, + types.Stader: true, + } + + // If the req.tag is not true, it's invalid + if _, ok := validTags[req.Tag]; !ok { + logger.Debug("Received Invalid Request: Invalid tag.") + return false + } + // Check if the signature format is correct (should start with '0x' and be 194 characters long) if len(req.Signature) != 194 || req.Signature[:2] != "0x" { logger.Debug("Received Invalid Request: Signature format is incorrect.") diff --git a/listener/internal/api/validation/validateAndDecodeRequests_test.go b/listener/internal/api/validation/validateAndDecodeRequests_test.go index 05b45ff..da1c16a 100644 --- a/listener/internal/api/validation/validateAndDecodeRequests_test.go +++ b/listener/internal/api/validation/validateAndDecodeRequests_test.go @@ -39,7 +39,7 @@ func TestValidateAndDecodeRequests(t *testing.T) { Payload: validEncodedPayload, Pubkey: validBlsPubkey, Signature: "0x" + repeatString("a", 192), // valid signature - Tag: "tag1", + Tag: "solo", }, { // Missing fields Payload: "", @@ -51,25 +51,25 @@ func TestValidateAndDecodeRequests(t *testing.T) { Payload: validEncodedPayload, Pubkey: validBlsPubkey, Signature: "bad_signature", - Tag: "tag2", + Tag: "solo", }, { // Old timestamp Payload: oldEncodedPayload, Pubkey: validBlsPubkey, Signature: "0x" + repeatString("a", 192), - Tag: "tag3", + Tag: "solo", }, { // Invalid type Payload: invalidTypePayload, Pubkey: validBlsPubkey, Signature: "0x" + repeatString("a", 192), - Tag: "tag4", + Tag: "solo", }, { // Invalid BLS public key Payload: validEncodedPayload, Pubkey: invalidBlsPubkey, Signature: "0x" + repeatString("a", 192), - Tag: "tag5", + Tag: "solo", }, } diff --git a/listener/internal/jwt/generateJWT.go b/listener/internal/jwt/generateJWT.go new file mode 100644 index 0000000..eefe9e6 --- /dev/null +++ b/listener/internal/jwt/generateJWT.go @@ -0,0 +1,52 @@ +package jwt + +import ( + "os" + "time" + + "github.com/dappnode/validator-monitoring/listener/internal/logger" + "github.com/golang-jwt/jwt/v5" +) + +func GenerateJWT(kid, privateKeyPath, subject, expiration string) (string, error) { + logger.Info("Starting JWT generation") + + privateKeyData, err := os.ReadFile(privateKeyPath) + if err != nil { + logger.Error("Failed to read private key file: " + err.Error()) + return "", err + } + privateKey, err := jwt.ParseRSAPrivateKeyFromPEM(privateKeyData) + if err != nil { + logger.Error("Failed to parse private key: " + err.Error()) + return "", err + } + + claims := jwt.MapClaims{} + if subject != "" { + claims["sub"] = subject + logger.Info("Subject claim set: " + subject) + } + if expiration != "" { + duration, err := time.ParseDuration(expiration) + if err != nil { + logger.Error("Failed to parse expiration duration: " + err.Error()) + return "", err + } + claims["exp"] = time.Now().Add(duration).Unix() + logger.Info("Expiration claim set: " + expiration) + } + + token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims) + token.Header["kid"] = kid + logger.Info("JWT claims prepared") + + tokenString, err := token.SignedString(privateKey) + if err != nil { + logger.Error("Failed to sign token: " + err.Error()) + return "", err + } + logger.Info("JWT generated and signed successfully") + + return tokenString, nil +} diff --git a/listener/test/sendSignatures_test.go b/listener/test/sendSignatures_test.go new file mode 100644 index 0000000..801b5df --- /dev/null +++ b/listener/test/sendSignatures_test.go @@ -0,0 +1,130 @@ +package test + +import ( + "encoding/base64" + "encoding/json" + "net/http" + "strconv" + "testing" + "time" + + "github.com/dappnode/validator-monitoring/listener/internal/api/types" + "github.com/gavv/httpexpect/v2" + "github.com/herumi/bls-eth-go-binary/bls" +) + +// TestPostSignaturesIntegration tests the POST /signatures endpoint. It expects a "listener" service to be running at +// http://localhost:8080, with the proper mongoDB connected to it. The test sends a series of requests with different payloads, +// public keys, signatures, and tags to the endpoint and checks the response status code. +func TestPostSignaturesIntegration(t *testing.T) { + // Initialize BLS for the test + if err := bls.Init(bls.BLS12_381); err != nil { + t.Fatalf("Failed to initialize BLS: %v", err) + } + + // Create a new HTTPExpect instance + e := httpexpect.Default(t, "http://localhost:8080") + + // Generate valid BLS keys and signature + var secretKey bls.SecretKey + secretKey.SetByCSPRNG() + publicKey := secretKey.GetPublicKey() + publicKeyHex := "0x" + publicKey.SerializeToHexStr() + + // Prepare timestamps and payloads + currentTime := time.Now() + validTimestamp := currentTime.AddDate(0, 0, -10).UnixMilli() // timestamp is 10 days ago + + validDecodedPayload := types.DecodedPayload{ + Type: "PROOF_OF_VALIDATION", + Platform: "dappnode", + Timestamp: strconv.FormatInt(validTimestamp, 10), + } + payloadBytes, _ := json.Marshal(validDecodedPayload) + validPayload := base64.StdEncoding.EncodeToString(payloadBytes) + signature := secretKey.SignByte(payloadBytes) + validSignature := "0x" + signature.SerializeToHexStr() + invalidDecodedPayload := types.DecodedPayload{ + Type: "INVALID_TYPE", + Platform: "dappnode", + Timestamp: strconv.FormatInt(validTimestamp, 10), + } + invalidPayloadBytes, _ := json.Marshal(invalidDecodedPayload) + invalidPayload := base64.StdEncoding.EncodeToString(invalidPayloadBytes) + + // Define test cases + // TODO: we should add the expected message for each case too, besides the expected code + tests := []struct { + description string + payload string + pubkey string + signature string + tag types.Tag + expectedCode int + }{ + { + description: "Valid request", + payload: validPayload, + pubkey: publicKeyHex, + signature: validSignature, + tag: types.Solo, + expectedCode: http.StatusOK, + }, + { + description: "Invalid payload format", + payload: invalidPayload, + pubkey: publicKeyHex, + signature: validSignature, + tag: types.Solo, + expectedCode: http.StatusBadRequest, + }, + { + description: "Valid signature format arbitrary bytes signed, shouldnt pass the crypto verification", + payload: validPayload, + pubkey: publicKeyHex, + signature: "0x8bc341f083e34d27b8df9f48b0bfcdaa7ed009146969cee0d0d4e03afd383242e1767627d5e2ef50cce410dd02ed88280bb91309f96e5ad1ad31b204f1ed5e64a43cdf3c32603450b477a40df366f3ae145014cade0f22d588786f4f07bc7c7d", + tag: types.Solo, + expectedCode: http.StatusBadRequest, + }, + { + description: "Invalid BLS public key", + payload: validPayload, + pubkey: "0xinvalidKey", + signature: validSignature, + tag: types.Solo, + expectedCode: http.StatusBadRequest, + }, + { + description: "Invalid JSON format", + payload: `{bad json}`, + pubkey: publicKeyHex, + signature: validSignature, + tag: types.Solo, + expectedCode: http.StatusBadRequest, + }, + { + description: "Invalid tag", + payload: validPayload, + pubkey: publicKeyHex, + signature: validSignature, + tag: "invalidTag", + expectedCode: http.StatusBadRequest, + }, + } + + // Execute tests + for _, tc := range tests { + t.Run(tc.description, func(t *testing.T) { + e.POST("/signatures"). + WithQuery("network", "mainnet"). + WithJSON([]types.SignatureRequest{{ + Payload: tc.payload, + Pubkey: tc.pubkey, + Signature: tc.signature, + Tag: tc.tag, + }}). + Expect(). + Status(tc.expectedCode) + }) + } +}