prysm-pulse/validator/rpc/handlers_auth_test.go
james-prysm 394bd1786a
HTTP validator API: beacon and account endpoints (#13191)
* fixing squashing changes, migrates beacon , account, and auth endpoints on validator client

* adding accounts endpoints

* fixing tests and query endpoints

* adding auth endpoint and fixing unit tests

* removing unused files and updating node file to skip gRPC

* ineffectual assignment fix

* rolling back a change to fix e2e

* fixing issues with ui

* updating with webui version 2.0.5

* updating package name flag in readme

* removing restore assets functions

* adding nomemcopy flag to see if vulenerability scan passes

* making data non compressed to avoid copy vulnerability

* Update beacon-chain/rpc/eth/shared/structs_validator.go

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>

* updating site_data, and skipping static analysis on file

* adding back deprecation comment notice

* updating workflows to ignore generated

* addressing radek comments

* missed a conversion

---------

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2023-12-01 20:40:09 +00:00

61 lines
1.6 KiB
Go

package rpc
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"github.com/prysmaticlabs/prysm/v4/testing/require"
"github.com/prysmaticlabs/prysm/v4/validator/accounts"
"github.com/prysmaticlabs/prysm/v4/validator/keymanager"
)
func TestInitialize(t *testing.T) {
// Step 1: Create a temporary directory
localWalletDir := setupWalletDir(t)
// Step 2: Optionally create a temporary 'auth-token' file
authTokenPath := filepath.Join(localWalletDir, AuthTokenFileName)
_, err := os.Create(authTokenPath)
require.NoError(t, err)
// Create an instance of the Server with the temporary directory
opts := []accounts.Option{
accounts.WithWalletDir(localWalletDir),
accounts.WithKeymanagerType(keymanager.Derived),
accounts.WithWalletPassword(strongPass),
accounts.WithSkipMnemonicConfirm(true),
}
acc, err := accounts.NewCLIManager(opts...)
require.NoError(t, err)
_, err = acc.WalletCreate(context.Background())
require.NoError(t, err)
server := &Server{walletDir: localWalletDir}
// Step 4: Create an HTTP request and response recorder
req := httptest.NewRequest(http.MethodGet, "/initialize", nil)
w := httptest.NewRecorder()
// Step 5: Call the Initialize function
server.Initialize(w, req)
// Step 6: Assert expectations
result := w.Result()
defer func() {
err := result.Body.Close()
require.NoError(t, err)
}()
var response InitializeAuthResponse
err = json.NewDecoder(result.Body).Decode(&response)
require.NoError(t, err)
// Assert the expected response
require.Equal(t, true, response.HasSignedUp)
require.Equal(t, true, response.HasWallet)
}