Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions code/go/0chain.net/blobbercore/constants/context_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package constants

import "0chain.net/core/common"

const ALLOCATION_CONTEXT_KEY common.ContextKey = "allocation"
const CLIENT_CONTEXT_KEY common.ContextKey = "client"
const CLIENT_KEY_CONTEXT_KEY common.ContextKey = "client_key"
const (
ALLOCATION_CONTEXT_KEY common.ContextKey = "allocation"
CLIENT_CONTEXT_KEY common.ContextKey = "client"
CLIENT_KEY_CONTEXT_KEY common.ContextKey = "client_key"

// CLIENT_SIGNATURE_HEADER_KEY represents key for context value passed with common.ClientSignatureHeader request header.
CLIENT_SIGNATURE_HEADER_KEY common.ContextKey = "signature"
)
69 changes: 1 addition & 68 deletions code/go/0chain.net/blobbercore/handler/grpc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@ package handler

import (
"context"
"encoding/json"
"errors"
"net"
"net/http"
"net/http/httptest"
"regexp"
"testing"
"time"

"0chain.net/blobbercore/allocation"
"0chain.net/blobbercore/blobbergrpc"
"0chain.net/blobbercore/datastore"
"0chain.net/core/chain"
"0chain.net/core/common"
"0chain.net/core/logging"
"github.com/0chain/gosdk/core/zcncrypto"
"github.com/0chain/gosdk/zcncore"
"github.com/DATA-DOG/go-sqlmock"
"github.com/gorilla/mux"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -45,63 +37,6 @@ func startGRPCServer(t *testing.T) {
}()
}

func initChain(t *testing.T) error {
chain.SetServerChain(&chain.Chain{})
logging.Logger = zap.NewNop()

setupWallet()

sUrl := setupServers(t)

if err := zcncore.InitZCNSDK(sUrl, "ed25519"); err != nil {
return err
}

return nil
}

func setupWallet() error {
w, err := zcncrypto.NewBLS0ChainScheme().GenerateKeys()
if err != nil {
return err
}
wBlob, err := json.Marshal(w)
if err != nil {
return err
}
if err := zcncore.SetWalletInfo(string(wBlob), true); err != nil {
return err
}

return nil
}

func setupServers(t *testing.T) (serverUr string) {
sharderServ := httptest.NewServer(
http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
},
),
)
server := httptest.NewServer(
http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
n := zcncore.Network{Miners: []string{"miner 1"}, Sharders: []string{sharderServ.URL}}
blob, err := json.Marshal(n)
if err != nil {
t.Error(err)
}

if _, err := w.Write(blob); err != nil {
t.Error(err)
}
},
),
)

return server.URL
}

func makeTestClient() (blobbergrpc.BlobberClient, *grpc.ClientConn, error) {
var (
ctx = context.Background()
Expand Down Expand Up @@ -134,9 +69,7 @@ func makeTestAllocation(exp common.Timestamp) *allocation.Allocation {
}

func Test_GetAllocation(t *testing.T) {
if err := initChain(t); err != nil {
t.Fatal(err)
}
setup(t)

startGRPCServer(t)

Expand Down
2 changes: 2 additions & 0 deletions code/go/0chain.net/blobbercore/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func setupHandlerContext(ctx context.Context, r *http.Request) context.Context {
r.Header.Get(common.ClientKeyHeader))
ctx = context.WithValue(ctx, constants.ALLOCATION_CONTEXT_KEY,
vars["allocation"])
// signature is not requered for all requests, but if header is empty it won`t affect anything
ctx = context.WithValue(ctx, constants.CLIENT_SIGNATURE_HEADER_KEY, r.Header.Get(common.ClientSignatureHeader))
return ctx
}

Expand Down
Loading