Skip to content

Commit

Permalink
Merge pull request #115 from ipfs-force-community/chore/build-v1.10.0…
Browse files Browse the repository at this point in the history
…-rc2

chore: bump version to v1.10.0-rc2
  • Loading branch information
hunjixin authored Feb 17, 2023
2 parents e385535 + e998a31 commit 9dc368b
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 72 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require (
github.com/filecoin-project/go-jsonrpc v0.1.5
github.com/filecoin-project/go-state-types v0.10.0-rc3
github.com/filecoin-project/specs-storage v0.4.1
github.com/filecoin-project/venus v1.10.0-rc1
github.com/filecoin-project/venus-auth v1.10.0-rc1
github.com/filecoin-project/venus v1.10.0-rc2
github.com/filecoin-project/venus-auth v1.10.0-rc2
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/ipfs-force-community/metrics v1.0.1-0.20220719063006-2c54bb379466
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,11 @@ github.com/filecoin-project/specs-storage v0.4.1/go.mod h1:Z2eK6uMwAOSLjek6+sy0j
github.com/filecoin-project/storetheindex v0.3.5/go.mod h1:0r3d0kSpK63O6AvLr1CjAINLi+nWD49clzcnKV+GLpI=
github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E=
github.com/filecoin-project/venus v1.2.4/go.mod h1:hJULXHGAnWuq5S5KRtPkwbT8DqgM9II7NwyNU7t59D0=
github.com/filecoin-project/venus v1.10.0-rc1 h1:wc28T6LBCji/8wdobTHWYJs1haxkmpJDtVa+s3nm/ms=
github.com/filecoin-project/venus v1.10.0-rc1/go.mod h1:CdPlDeiXO2NjwVDs9+NDDH4KfOwGklvcHoNF5RHa/HM=
github.com/filecoin-project/venus v1.10.0-rc2 h1:bSPtGuLnLFTALFdHuHRpo9bkN4bnZ/2RlpNyiKC68Fs=
github.com/filecoin-project/venus v1.10.0-rc2/go.mod h1:khIm31fH1i/2q1aLBgRo5ULB+LbSKiNsKfwQORKD+PY=
github.com/filecoin-project/venus-auth v1.3.2/go.mod h1:m5Jog2GYxztwP7w3m/iJdv/V1/bTcAVU9rm/CbhxRQU=
github.com/filecoin-project/venus-auth v1.10.0-rc1 h1:4Oo+lLJP/cnAxEoZkVLdcI3+QcmPf4TIpdzb5urlk8o=
github.com/filecoin-project/venus-auth v1.10.0-rc1/go.mod h1:KvTLXbGp0jOKqQ9Rxc3zcZA/MFRPYz64D/jSdvUu+Qc=
github.com/filecoin-project/venus-auth v1.10.0-rc2 h1:mC2kRcUmXaL2nPky8iiogFjrygMTUXGXHjvEV9msPgk=
github.com/filecoin-project/venus-auth v1.10.0-rc2/go.mod h1:bJT0owiiQfQq7u8QBpIf22JHNRZdsx9rAr4wMEsg+ds=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=
Expand Down
4 changes: 2 additions & 2 deletions integrate_test/mock_deamon.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func MockMain(ctx context.Context, validateMiner []address.Address, repoPath str
},
}
authClient := mocks.NewMockAuthClient()
authClient.AddMockUser(user...)
authClient.AddMockUser(ctx, user...)
walletStream := walletevent.NewWalletEventStream(ctx, authClient, requestCfg, true)

proofStream := proofevent.NewProofEventStream(ctx, minerValidator, requestCfg)
Expand Down Expand Up @@ -126,7 +126,7 @@ func MockMain(ctx context.Context, validateMiner []address.Address, repoPath str
return "", nil, fmt.Errorf("failed to generate local jwt client: %v", err)
}

handler := (http.Handler)(jwtclient.NewAuthMux(localJwtCli, authClient, mux))
handler := (http.Handler)(jwtclient.NewAuthMux(localJwtCli, jwtclient.WarpIJwtAuthClient(authClient), mux))

if err := metrics2.SetupMetrics(ctx, cfg.Metrics, gatewayAPIImpl); err != nil {
return "", nil, err
Expand Down
7 changes: 4 additions & 3 deletions marketevent/market_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func TestListMarketConnectionsState(t *testing.T) {
}

func setupMarketEvent(t *testing.T, userName string, miners ...address.Address) *MarketEventStream {
ctx := context.Background()
authClient := mocks.NewMockAuthClient()
user := &auth.OutputUser{
Id: "id",
Expand All @@ -259,14 +260,14 @@ func setupMarketEvent(t *testing.T, userName string, miners ...address.Address)
}
for _, m := range miners {
user.Miners = append(user.Miners, &auth.OutputMiner{
Miner: m.String(),
Miner: m,
User: userName,
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
},
)
}
authClient.AddMockUser(user)
ctx := context.Background()
authClient.AddMockUser(ctx, user)

return NewMarketEventStream(ctx, validator.NewMinerValidator(authClient), types.DefaultConfig())
}
3 changes: 1 addition & 2 deletions validator/miner_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/filecoin-project/go-address"

"github.com/filecoin-project/venus-auth/auth"
"github.com/filecoin-project/venus-auth/core"
"github.com/filecoin-project/venus-auth/jwtclient"
)
Expand All @@ -26,7 +25,7 @@ func (amv *AuthMinerValidator) Validate(ctx context.Context, miner address.Addre
if !exist {
return fmt.Errorf("user name not exist in rpc context")
}
user, err := amv.authClient.GetUserByMiner(&auth.GetUserByMinerRequest{Miner: miner.String()})
user, err := amv.authClient.GetUserByMiner(ctx, miner)
if err != nil {
return fmt.Errorf("get user by miner(%s), failed:%w", miner.String(), err)
}
Expand Down
30 changes: 13 additions & 17 deletions validator/miner_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import (
"github.com/stretchr/testify/require"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/venus/venus-shared/types"

"github.com/filecoin-project/venus-auth/auth"
"github.com/filecoin-project/venus-auth/jwtclient"

"github.com/ipfs-force-community/venus-gateway/validator/mocks"
)

var (
f01001 = types.MustParseAddress("f01001")
f01002 = types.MustParseAddress("f01002")
)

var testArgs = map[string]*struct {
validOk bool
user *auth.OutputUser
Expand All @@ -25,35 +31,36 @@ var testArgs = map[string]*struct {
Name: "test_01",
Comment: "test_01",
State: 1,
Miners: []*auth.OutputMiner{{Miner: "f01001", User: "test_01"}},
Miners: []*auth.OutputMiner{{Miner: f01001, User: "test_01"}},
}},
// test_02, State is disabled, so it should be invalid.
"test_02": {false, &auth.OutputUser{
Id: uuid.NewString(),
Name: "test_02",
Comment: "test_02",
State: 0,
Miners: []*auth.OutputMiner{{Miner: "f01002", User: "test_02"}},
Miners: []*auth.OutputMiner{{Miner: f01002, User: "test_02"}},
}},
// test_03, username is not same as miner
"test_03": {false, &auth.OutputUser{
Id: uuid.NewString(),
Name: "test_02",
Comment: "test_02",
State: 1,
Miners: []*auth.OutputMiner{{Miner: "f01002", User: "test_02"}},
Miners: []*auth.OutputMiner{{Miner: f01002, User: "test_02"}},
}},
// username not exists in rpc context
"": {false, &auth.OutputUser{
Id: uuid.NewString(),
Name: "test_02",
Comment: "test_02",
State: 1,
Miners: []*auth.OutputMiner{{Miner: "f01002", User: "test_02"}},
Miners: []*auth.OutputMiner{{Miner: f01002, User: "test_02"}},
}},
}

func TestAuthMinerValidator_Validate(t *testing.T) {
ctx := context.TODO()
address.CurrentNetwork = address.Mainnet
authClient := mocks.NewMockAuthClient()
validator := NewMinerValidator(authClient)
Expand All @@ -62,23 +69,12 @@ func TestAuthMinerValidator_Validate(t *testing.T) {
require.NoError(t, err)

for userName, arg := range testArgs {
authClient.AddMockUser(arg.user)
authClient.AddMockUser(ctx, arg.user)
var ctx = context.Background()
if userName != "" {
ctx = jwtclient.CtxWithName(ctx, userName)
}
for _, miner := range arg.user.Miners {
addr, err := address.NewFromString(miner.Miner)
require.NoError(t, err)
if arg.validOk {
// stm: @VENUSGATEWAY_VALIDATOR_VALIDATE_001
require.NoError(t, validator.Validate(ctx, addr))
} else {
// user is disabled, username is not same as miner return an error, username not exists in context
// stm: @VENUSGATEWAY_VALIDATOR_VALIDATE_005, @VENUSGATEWAY_VALIDATOR_VALIDATE_002, @VENUSGATEWAY_VALIDATOR_VALIDATE_003
require.Error(t, validator.Validate(ctx, addr))
}
}

// miner not exists
// stm: @VENUSGATEWAY_VALIDATOR_VALIDATE_004
require.Error(t, validator.Validate(ctx, notExistsMiner))
Expand Down
68 changes: 36 additions & 32 deletions validator/mocks/mock_authclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"fmt"
"sync"

rpcAuth "github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/go-address"

"github.com/filecoin-project/venus-auth/auth"
"github.com/filecoin-project/venus-auth/core"
"github.com/filecoin-project/venus-auth/jwtclient"

"github.com/ipfs-force-community/metrics/ratelimit"
Expand All @@ -24,24 +25,24 @@ type AuthClient struct {
lkSigner sync.RWMutex
}

func (m *AuthClient) GetUser(req *auth.GetUserRequest) (*auth.OutputUser, error) {
func (m *AuthClient) GetUser(ctx context.Context, name string) (*auth.OutputUser, error) {
m.lkUser.Lock()
defer m.lkUser.Unlock()

if user, ok := m.users[req.Name]; ok {
if user, ok := m.users[name]; ok {
return user, nil
}

return nil, errors.New("not exist")
}

func (m *AuthClient) GetUserByMiner(req *auth.GetUserByMinerRequest) (*auth.OutputUser, error) {
func (m *AuthClient) GetUserByMiner(ctx context.Context, targetMiner address.Address) (*auth.OutputUser, error) {
m.lkUser.Lock()
defer m.lkUser.Unlock()

for _, user := range m.users {
for _, miner := range user.Miners {
if req.Miner == miner.Miner {
if targetMiner == miner.Miner {
return user, nil
}
}
Expand All @@ -50,9 +51,9 @@ func (m *AuthClient) GetUserByMiner(req *auth.GetUserByMinerRequest) (*auth.Outp
return nil, errors.New("not exist")
}

func (m *AuthClient) GetUserBySigner(signer string) (auth.ListUsersResponse, error) {
func (m *AuthClient) GetUserBySigner(ctx context.Context, signer address.Address) (auth.ListUsersResponse, error) {
m.lkSigner.Lock()
names, ok := m.signers[signer]
names, ok := m.signers[signer.String()]
m.lkSigner.Unlock()
if !ok {
return nil, errors.New("not exist")
Expand All @@ -70,18 +71,18 @@ func (m *AuthClient) GetUserBySigner(signer string) (auth.ListUsersResponse, err
return users, nil
}

func (m *AuthClient) RegisterSigners(userName string, signers []string) error {
_, err := m.GetUser(&auth.GetUserRequest{Name: userName})
func (m *AuthClient) RegisterSigners(ctx context.Context, userName string, signers []address.Address) error {
_, err := m.GetUser(ctx, userName)
if err != nil {
return err
}

m.lkSigner.Lock()
defer m.lkSigner.Unlock()
for _, signer := range signers {
names, ok := m.signers[signer]
names, ok := m.signers[signer.String()]
if !ok {
m.signers[signer] = []string{userName}
m.signers[signer.String()] = []string{userName}
} else {
bCreate := true
for _, name := range names {
Expand All @@ -93,24 +94,24 @@ func (m *AuthClient) RegisterSigners(userName string, signers []string) error {

if bCreate {
names = append(names, userName)
m.signers[signer] = names
m.signers[signer.String()] = names
}
}
}

return nil
}

func (m *AuthClient) UnregisterSigners(userName string, signers []string) error {
_, err := m.GetUser(&auth.GetUserRequest{Name: userName})
func (m *AuthClient) UnregisterSigners(ctx context.Context, userName string, signers []address.Address) error {
_, err := m.GetUser(ctx, userName)
if err != nil {
return err
}

m.lkSigner.Lock()
defer m.lkSigner.Unlock()
for _, signer := range signers {
names, ok := m.signers[signer]
names, ok := m.signers[signer.String()]
if ok {
idx := 0
for _, name := range names {
Expand All @@ -119,14 +120,14 @@ func (m *AuthClient) UnregisterSigners(userName string, signers []string) error
idx++
}
}
m.signers[signer] = names[:idx]
m.signers[signer.String()] = names[:idx]
}
}

return nil
}

func (m *AuthClient) VerifyUsers(names []string) error {
func (m *AuthClient) VerifyUsers(ctx context.Context, names []string) error {
m.lkUser.Lock()
defer m.lkUser.Unlock()

Expand All @@ -139,7 +140,7 @@ func (m *AuthClient) VerifyUsers(names []string) error {
return nil
}

func (m *AuthClient) AddMockUser(users ...*auth.OutputUser) {
func (m *AuthClient) AddMockUser(ctx context.Context, users ...*auth.OutputUser) {
m.lkUser.Lock()
defer m.lkUser.Unlock()

Expand All @@ -159,47 +160,51 @@ func (m *AuthClient) GetUserLimit(username, service, api string) (*ratelimit.Lim
return &ratelimit.Limit{Account: username}, nil
}

func (m *AuthClient) Verify(ctx context.Context, token string) ([]rpcAuth.Permission, error) {
func (m *AuthClient) Verify(ctx context.Context, token string) (*auth.VerifyResponse, error) {
panic("Don't call me")
}

func (m *AuthClient) HasUser(req *auth.HasUserRequest) (bool, error) {
func (m *AuthClient) HasUser(ctx context.Context, name string) (bool, error) {
panic("Don't call me")
}

func (m *AuthClient) ListUsers(req *auth.ListUsersRequest) (auth.ListUsersResponse, error) {
func (m *AuthClient) ListUsers(ctx context.Context, skip int64, limit int64, state core.UserState) (auth.ListUsersResponse, error) {
panic("Don't call me")
}

func (m *AuthClient) ListUsersWithMiners(req *auth.ListUsersRequest) (auth.ListUsersResponse, error) {
func (m *AuthClient) ListUsersWithMiners(ctx context.Context, skip int64, limit int64, state core.UserState) (auth.ListUsersResponse, error) {
panic("Don't call me")
}

func (m *AuthClient) GetUserRateLimit(name, id string) (auth.GetUserRateLimitResponse, error) {
func (m *AuthClient) GetUserRateLimit(ctx context.Context, name, id string) (auth.GetUserRateLimitResponse, error) {
panic("Don't call me")
}

func (m *AuthClient) MinerExistInUser(user, miner string) (bool, error) {
func (m *AuthClient) MinerExistInUser(ctx context.Context, user string, miner address.Address) (bool, error) {
panic("Don't call me")
}

func (m *AuthClient) SignerExistInUser(user, signer string) (bool, error) {
func (m *AuthClient) SignerExistInUser(ctx context.Context, user string, signer address.Address) (bool, error) {
panic("Don't call me")
}

func (m *AuthClient) HasMiner(req *auth.HasMinerRequest) (bool, error) {
func (m *AuthClient) HasMiner(ctx context.Context, mienr address.Address) (bool, error) {
panic("Don't call me")
}

func (m *AuthClient) ListMiners(user string) (auth.ListMinerResp, error) {
func (m *AuthClient) ListMiners(ctx context.Context, user string) (auth.ListMinerResp, error) {
panic("Don't call me")
}

func (m *AuthClient) HasSigner(signer string) (bool, error) {
func (m *AuthClient) HasSigner(ctx context.Context, signer address.Address) (bool, error) {
panic("Don't call me")
}

func (m *AuthClient) ListSigners(user string) (auth.ListSignerResp, error) {
func (m *AuthClient) ListSigners(ctx context.Context, user string) (auth.ListSignerResp, error) {
panic("Don't call me")
}

func (m *AuthClient) UpsertMiner(ctx context.Context, user, miner string, openMining bool) (bool, error) {
panic("Don't call me")
}

Expand All @@ -211,7 +216,6 @@ func NewMockAuthClient() *AuthClient {
}

var (
_ jwtclient.IAuthClient = (*AuthClient)(nil)
_ ratelimit.ILimitFinder = (*AuthClient)(nil)
_ jwtclient.IJwtAuthClient = (*AuthClient)(nil)
_ jwtclient.IAuthClient = (*AuthClient)(nil)
_ ratelimit.ILimitFinder = (*AuthClient)(nil)
)
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package version
var CurrentCommit string

// BuildVersion is the local build version, set by build system
const BuildVersion = "1.10.0-rc1"
const BuildVersion = "1.10.0-rc2"

var UserVersion = BuildVersion + CurrentCommit
Loading

0 comments on commit 9dc368b

Please sign in to comment.