Skip to content

Commit

Permalink
Merge pull request #156 from filecoin-project/chore/merge-1.10.0
Browse files Browse the repository at this point in the history
Chore/merge 1.10.0
  • Loading branch information
LinZexiao authored Mar 8, 2023
2 parents d1c9380 + 3407f50 commit 9138153
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 32 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# venus-auth changelog

## v1.10.1

* 查询参数为空时不重置请求url [[#153](https://github.com/filecoin-project/venus-auth/pull/153)]
* 补充对 delegated 地址的支持 [[#154](https://github.com/filecoin-project/venus-auth/pull/154)]

## v1.10.0

* 升级 go-jsonrpc 到 v0.1.7
Expand Down
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ SHELL=/usr/bin/env bash

git=$(subst -,.,$(shell git describe --always --match=NeVeRmAtCh --dirty 2>/dev/null || git rev-parse --short HEAD 2>/dev/null))


ldflags=-X=github.com/filecoin-project/venus-auth/core.CurrentCommit=+git.$(git)
ifneq ($(strip $(LDFLAGS)),)
ldflags+=-extldflags=$(LDFLAGS)
Expand All @@ -11,7 +10,6 @@ GOFLAGS+=-ldflags="$(ldflags)"

all: clean venus-auth


show-env:
@echo '_________________build_environment_______________'
@echo '| git commit=$(git)'
Expand All @@ -20,6 +18,9 @@ show-env:
venus-auth:show-env
go build $(GOFLAGS) -o venus-auth ./cmd/server/*.go

test:
go test -race ./...

lint:
golangci-lint run

Expand All @@ -28,13 +29,8 @@ linux: clean

clean:
rm -rf venus-auth

.PHONY: clean


.PHONY: docker


static: clean
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GOFLAGS) -o venus-auth ./cmd/server/*.go

Expand All @@ -43,7 +39,7 @@ docker:
curl -O https://raw.githubusercontent.com/filecoin-project/venus-docs/master/script/docker/dockerfile
docker build --build-arg https_proxy=$(BUILD_DOCKER_PROXY) --build-arg BUILD_TARGET=venus-auth -t venus-auth .
docker tag venus-auth filvenus/venus-auth:$(TAG)

.PHONY: docker

gen:
go generate ./...
15 changes: 8 additions & 7 deletions auth/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func (o *jwtOAuth) RegisterSigners(ctx context.Context, req *RegisterSignersReq)
}

for _, signer := range req.Signers {
if !isSignerAddress(signer) {
if !IsSignerAddress(signer) {
return fmt.Errorf("invalid protocol type: %v", signer.Protocol())
}

Expand All @@ -532,7 +532,7 @@ func (o *jwtOAuth) SignerExistInUser(ctx context.Context, req *SignerExistInUser
}

addr := req.Signer
if !isSignerAddress(addr) {
if !IsSignerAddress(addr) {
return false, fmt.Errorf("invalid protocol type: %v", addr.Protocol())
}

Expand Down Expand Up @@ -571,7 +571,7 @@ func (o *jwtOAuth) UnregisterSigners(ctx context.Context, req *UnregisterSigners
}

for _, signer := range req.Signers {
if !isSignerAddress(signer) {
if !IsSignerAddress(signer) {
return fmt.Errorf("invalid protocol type: %v", signer.Protocol())
}

Expand All @@ -590,7 +590,7 @@ func (o jwtOAuth) HasSigner(ctx context.Context, req *HasSignerReq) (bool, error
}

addr := req.Signer
if !isSignerAddress(addr) {
if !IsSignerAddress(addr) {
return false, fmt.Errorf("invalid protocol type: %v", addr.Protocol())
}

Expand All @@ -603,7 +603,7 @@ func (o jwtOAuth) DelSigner(ctx context.Context, req *DelSignerReq) (bool, error
return false, ErrorPermissionDenied
}

if !isSignerAddress(addr) {
if !IsSignerAddress(addr) {
return false, fmt.Errorf("invalid protocol type: %v", addr.Protocol())
}

Expand Down Expand Up @@ -634,8 +634,9 @@ func JwtUserFromToken(token string) (string, error) {
return payload.Name, err
}

func isSignerAddress(addr address.Address) bool {
return addr.Protocol() == address.SECP256K1 || addr.Protocol() == address.BLS
func IsSignerAddress(addr address.Address) bool {
protocol := addr.Protocol()
return protocol == address.SECP256K1 || protocol == address.BLS || protocol == address.Delegated
}

func isAdmin(ctx context.Context) bool {
Expand Down
6 changes: 4 additions & 2 deletions auth/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestJwt(t *testing.T) {
"test_user_001": {"t3wylwd6pclppme4qmbgwled5xpsbgwgqbn2alxa7yahg2gnbfkipsdv6m764xm5coizujmwdmkxeugplmorha", "t15rynkupqyfx5ebvaishg7duutwb5ooq2qpaikua"},
"test_user_002": {"t3r47fkdzfmtex5ic3jnwlzc7bkpbj7s4d6limyt4f57t3cuqq5nuvhvwv2cu2a6iga2s64vjqcxjqiezyjooq", "t1uqtvvwkkfkkez52ocnqe6vg74qewiwja4t2tiba"},
"test_user_003": {"t15rynkupqyfx5ebvaishg7duutwb5ooq2qpaikua", "t1sgeoaugenqnzftqp7wvwqebcozkxa5y7i56sy2q"},
"test_user_004": {"f410ffhviosf3a4ymvgm3sxrugj2qkir33qnlhqjrauq"},
}
t.Run("test register signer", func(t *testing.T) { testRegisterSigner(t, userSigners) })
t.Run("test signer exist in user", func(t *testing.T) { testSignerExistInUser(t, userSigners) })
Expand Down Expand Up @@ -770,15 +771,16 @@ func addUsersAndSigners(t *testing.T, userSigners map[string][]string) {

// with adminCtx admin perm
// Create users.
_, _ = jwtOAuthInstance.CreateUser(adminCtx, createUserReq)
_, err := jwtOAuthInstance.CreateUser(adminCtx, createUserReq)
assert.NoError(t, err)
// Add Signer
signerAddrs := make([]address.Address, 0)
for _, signer := range signers {
signerAddr, err := address.NewFromString(signer)
assert.Nil(t, err)
signerAddrs = append(signerAddrs, signerAddr)
}
err := jwtOAuthInstance.RegisterSigners(adminCtx, &RegisterSignersReq{
err = jwtOAuthInstance.RegisterSigners(adminCtx, &RegisterSignersReq{
User: userName,
Signers: signerAddrs,
})
Expand Down
26 changes: 15 additions & 11 deletions auth/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,24 @@ func CorsMiddleWare() gin.HandlerFunc {

func RewriteAddressInUrl() gin.HandlerFunc {
return func(c *gin.Context) {
queryParams := c.Request.URL.Query()
for key, params := range queryParams {
if key == "miner" || key == "signer" {
for index, v := range params {
params[index] = "\"" + v + "\""
if len(c.Request.URL.Query()) > 0 {
queryParams := c.Request.URL.Query()
for key, params := range queryParams {
if key == "miner" || key == "signer" {
for index, v := range params {
params[index] = "\"" + v + "\""
}
}
}
c.Request.RequestURI = c.FullPath() + "?" + queryParams.Encode()
var err error
c.Request.URL, err = url.ParseRequestURI(c.Request.RequestURI)
if err != nil {
log.Errorf("parse request url `%s` failed: %v", c.Request.RequestURI, err)
_ = c.AbortWithError(http.StatusInternalServerError, errors.New("fail when rewrite request url"))
}
}
c.Request.RequestURI = c.FullPath() + "?" + queryParams.Encode()
var err error
c.Request.URL, err = url.ParseRequestURI(c.Request.RequestURI)
if err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, errors.New("fail when rewrite request url"))
}

c.Next()
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var CurrentCommit string

const BuildVersion = "1.10.0"
const BuildVersion = "1.10.1"

var Version = BuildVersion + CurrentCommit

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/dgraph-io/badger/v3 v3.2011.1
github.com/etherlabsio/healthcheck/v2 v2.0.0
github.com/filecoin-project/go-address v1.0.0
github.com/filecoin-project/go-address v1.1.0
github.com/filecoin-project/go-jsonrpc v0.1.5
github.com/fsnotify/fsnotify v1.5.4
github.com/gbrlsnchs/jwt/v3 v3.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/etherlabsio/healthcheck/v2 v2.0.0 h1:oKq8cbpwM/yNGPXf2Sff6MIjVUjx/pGYFydWzeK2MpA=
github.com/etherlabsio/healthcheck/v2 v2.0.0/go.mod h1:huNVOjKzu6FI1eaO1CGD3ZjhrmPWf5Obu/pzpI6/wog=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/filecoin-project/go-address v1.0.0 h1:IrexI0kpADLaPP+CdmU3CVAUqnW/FQC0KTmz4lVKiFU=
github.com/filecoin-project/go-address v1.0.0/go.mod h1:5t3z6qPmIADZBtuE9EIzi0EwzcRy2nVhpo0I/c1r0OA=
github.com/filecoin-project/go-address v1.1.0 h1:ofdtUtEsNxkIxkDw67ecSmvtzaVSdcea4boAmLbnHfE=
github.com/filecoin-project/go-address v1.1.0/go.mod h1:5t3z6qPmIADZBtuE9EIzi0EwzcRy2nVhpo0I/c1r0OA=
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 h1:2pMXdBnCiXjfCYx/hLqFxccPoqsSveQFxVLvNxy9bus=
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
Expand Down

0 comments on commit 9138153

Please sign in to comment.