新注册的用户请输入邮箱并保存,随后登录邮箱激活账号。后续可直接使用邮箱登录!

Commit 5ba3de12 authored by taifu yuan's avatar taifu yuan 🏸

fix: 当前组织管理员多签可更新删除别名信息

parent 4920839a
...@@ -123,17 +123,20 @@ func (r *CertManageRuntime) UpdateAlias(txSimContext protocol.TxSimContext, para ...@@ -123,17 +123,20 @@ func (r *CertManageRuntime) UpdateAlias(txSimContext protocol.TxSimContext, para
return nil, err return nil, err
} }
if txSimContext.GetSender().OrgId != certificate.Subject.Organization[0] { if !containOrgId(txSimContext, certificate.Subject.Organization[0]) {
return nil, fmt.Errorf("update alias fail, "+ err = fmt.Errorf("update alias fail, "+
"you can't change other organization cert. "+ "you can't change to other organization[%s] cert. ",
"your org is %s cert org is %s", certificate.Subject.Organization[0])
txSimContext.GetSender().OrgId, certificate.Subject.Organization[0]) r.log.Warn(err)
return nil, err
} }
if txSimContext.GetSender().OrgId != nowCertificate.Subject.Organization[0] {
return nil, fmt.Errorf("update alias fail, "+ if !containOrgId(txSimContext, nowCertificate.Subject.Organization[0]) {
"you can't change other organization cert. "+ err = fmt.Errorf("update alias fail, "+
"your org is %s cert org is %s", "you can't change other organization[%s] cert. ",
txSimContext.GetSender().OrgId, nowCertificate.Subject.Organization[0]) certificate.Subject.Organization[0])
r.log.Warn(err)
return nil, err
} }
nowCert := &commonPb.AliasCertInfo{ nowCert := &commonPb.AliasCertInfo{
...@@ -177,7 +180,7 @@ func (r *CertManageRuntime) DeleteAlias(txSimContext protocol.TxSimContext, para ...@@ -177,7 +180,7 @@ func (r *CertManageRuntime) DeleteAlias(txSimContext protocol.TxSimContext, para
names := string(params[paramNameAliases]) names := string(params[paramNameAliases])
names = strings.TrimSpace(names) names = strings.TrimSpace(names)
if utils.IsAnyBlank(names) { if utils.IsAnyBlank(names) {
err = fmt.Errorf("update alias failed, alias name is nil") err = fmt.Errorf("delete alias failed, alias name is nil")
r.log.Warn(err) r.log.Warn(err)
return nil, err return nil, err
} }
...@@ -198,16 +201,16 @@ func (r *CertManageRuntime) DeleteAlias(txSimContext protocol.TxSimContext, para ...@@ -198,16 +201,16 @@ func (r *CertManageRuntime) DeleteAlias(txSimContext protocol.TxSimContext, para
// verify org // verify org
certificate, err := utils.ParseCert(certAliasInfo.NowCert.Cert) certificate, err := utils.ParseCert(certAliasInfo.NowCert.Cert)
if err != nil || certificate == nil || certificate.Subject.Organization == nil { if err != nil || certificate == nil || certificate.Subject.Organization == nil {
err = fmt.Errorf("update alias fail, params[%s] format error, err:%s", paramNameCert, err) err = fmt.Errorf("delete alias fail, params[%s] format error, err:%s", paramNameCert, err)
r.log.Warn(err) r.log.Warn(err)
return nil, err return nil, err
} }
if !containOrgId(txSimContext, certificate.Subject.Organization[0]) {
if txSimContext.GetSender().OrgId != certificate.Subject.Organization[0] { err = fmt.Errorf("delete alias fail, "+
return nil, fmt.Errorf("delete alias fail, "+ "you can't delete other organization[%s] cert. ",
"you can't change other organization cert. "+ certificate.Subject.Organization[0])
"your org is %s cert org is %s", r.log.Warn(err)
txSimContext.GetSender().OrgId, certificate.Subject.Organization[0]) return nil, err
} }
blankCert := &commonPb.AliasCertInfo{BlockHeight: txSimContext.GetBlockHeight()} blankCert := &commonPb.AliasCertInfo{BlockHeight: txSimContext.GetBlockHeight()}
...@@ -271,10 +274,10 @@ func (r *CertManageRuntime) addAliasCore(txSimContext protocol.TxSimContext, ali ...@@ -271,10 +274,10 @@ func (r *CertManageRuntime) addAliasCore(txSimContext protocol.TxSimContext, ali
if certAliasInfo == nil { if certAliasInfo == nil {
certAliasInfo = &commonPb.AliasInfo{Alias: aliasName} certAliasInfo = &commonPb.AliasInfo{Alias: aliasName}
} }
//err = r.saveAllAlias(txSimContext, aliasName) err = r.saveAllAlias(txSimContext, aliasName)
//if err != nil { if err != nil {
// return err return err
//} }
certAliasInfo.NowCert = nowCert certAliasInfo.NowCert = nowCert
certAliasInfo.HisCerts = append(certAliasInfo.HisCerts, nowCert) certAliasInfo.HisCerts = append(certAliasInfo.HisCerts, nowCert)
err = r.setAliasToDb(txSimContext, certAliasInfo) err = r.setAliasToDb(txSimContext, certAliasInfo)
...@@ -285,20 +288,20 @@ func (r *CertManageRuntime) addAliasCore(txSimContext protocol.TxSimContext, ali ...@@ -285,20 +288,20 @@ func (r *CertManageRuntime) addAliasCore(txSimContext protocol.TxSimContext, ali
return err return err
} }
//func (r *CertManageRuntime) saveAllAlias(txSimContext protocol.TxSimContext, aliasStr string) error { func (r *CertManageRuntime) saveAllAlias(txSimContext protocol.TxSimContext, aliasStr string) error {
// allAliasBytes, err := txSimContext.Get(certManageContractName, []byte(certAliasKey+"all")) allAliasBytes, err := txSimContext.Get(certManageContractName, []byte(certAliasKey+"all"))
// if err != nil { if err != nil {
// r.log.Warnf("save all alias failed, err: ", err.Error()) r.log.Warnf("save all alias failed, err: ", err.Error())
// return err return err
// } }
// allAlias := string(allAliasBytes) allAlias := string(allAliasBytes)
// if len(allAlias) > 0 { if len(allAlias) > 0 {
// allAlias += "," allAlias += ","
// } }
// allAlias += aliasStr allAlias += aliasStr
// _ = txSimContext.Put(certManageContractName, []byte(certAliasKey+"all"), []byte(allAlias)) _ = txSimContext.Put(certManageContractName, []byte(certAliasKey+"all"), []byte(allAlias))
// return nil return nil
//} }
func (r *CertManageRuntime) setAliasToDb(txSimContext protocol.TxSimContext, certAliasInfo *commonPb.AliasInfo) error { func (r *CertManageRuntime) setAliasToDb(txSimContext protocol.TxSimContext, certAliasInfo *commonPb.AliasInfo) error {
certAliasBytes, err := certAliasInfo.Marshal() certAliasBytes, err := certAliasInfo.Marshal()
...@@ -359,6 +362,17 @@ func (r *CertManageRuntime) setCertHash(txSimContext protocol.TxSimContext, nowC ...@@ -359,6 +362,17 @@ func (r *CertManageRuntime) setCertHash(txSimContext protocol.TxSimContext, nowC
return nil return nil
} }
func containOrgId(ctx protocol.TxSimContext, orgId string) bool {
endorses := ctx.GetTx().Endorsers
if len(endorses) == 0 {
return ctx.GetSender().OrgId == orgId
}
for _, endorse := range endorses {
return endorse.Signer.OrgId == orgId
}
return false
}
// Stay new function // Stay new function
// //
//func (r *CertManageRuntime) FreezeAlias(txSimContext protocol.TxSimContext, params map[string][]byte) ( //func (r *CertManageRuntime) FreezeAlias(txSimContext protocol.TxSimContext, params map[string][]byte) (
......
...@@ -125,7 +125,7 @@ func Test_DeleteAlias(t *testing.T) { ...@@ -125,7 +125,7 @@ func Test_DeleteAlias(t *testing.T) {
// no alias add // no alias add
params := make(map[string][]byte) params := make(map[string][]byte)
params[paramNameAliases] = []byte("alias03") params[paramNameAliases] = []byte("alias03")
result, err = mgrRuntime.DeleteAlias(txSimContext, nil) result, err = mgrRuntime.DeleteAlias(txSimContext, params)
assert.NotNil(t, err) assert.NotNil(t, err)
assert.Nil(t, result) assert.Nil(t, result)
...@@ -152,7 +152,7 @@ func Test_DeleteAlias(t *testing.T) { ...@@ -152,7 +152,7 @@ func Test_DeleteAlias(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, "ok", string(result2)) assert.Equal(t, "ok", string(result2))
// dep delete // repeat
params[paramNameAliases] = []byte("alias03") params[paramNameAliases] = []byte("alias03")
params[paramNameCert] = getOrg1Client1Signer().MemberInfo params[paramNameCert] = getOrg1Client1Signer().MemberInfo
result, err = mgrRuntime.DeleteAlias(txSimContext, params) result, err = mgrRuntime.DeleteAlias(txSimContext, params)
......
...@@ -12,8 +12,9 @@ import ( ...@@ -12,8 +12,9 @@ import (
"sync" "sync"
"testing" "testing"
"chainmaker.org/chainmaker/pb-go/v2/accesscontrol"
commonPb "chainmaker.org/chainmaker/pb-go/v2/common" commonPb "chainmaker.org/chainmaker/pb-go/v2/common"
"chainmaker.org/chainmaker/pb-go/v2/accesscontrol"
"chainmaker.org/chainmaker/protocol/v2/test" "chainmaker.org/chainmaker/protocol/v2/test"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
...@@ -64,6 +65,20 @@ var _ protocol.TxSimContext = (*mock.MockTxSimContext)(nil) ...@@ -64,6 +65,20 @@ var _ protocol.TxSimContext = (*mock.MockTxSimContext)(nil)
func initEnv(t *testing.T) (*CertManageRuntime, *mock.MockTxSimContext, func()) { func initEnv(t *testing.T) (*CertManageRuntime, *mock.MockTxSimContext, func()) {
r, m, f := initEnvCore(t) r, m, f := initEnvCore(t)
m.EXPECT().GetSender().Return(getOrg1Client1Signer()).AnyTimes() m.EXPECT().GetSender().Return(getOrg1Client1Signer()).AnyTimes()
m.EXPECT().GetTx().DoAndReturn(
func() *commonPb.Transaction {
return &commonPb.Transaction{
Sender: &commonPb.EndorsementEntry{
Signer: getOrg1Client1Signer(),
},
Endorsers: []*commonPb.EndorsementEntry{
{
Signer: getOrg1Client1Signer(),
Signature: nil,
},
},
}
}).AnyTimes()
return r, m, f return r, m, f
} }
...@@ -72,6 +87,20 @@ var cache = NewCacheMock() ...@@ -72,6 +87,20 @@ var cache = NewCacheMock()
func initEnvSender2(t *testing.T) (*CertManageRuntime, *mock.MockTxSimContext, func()) { func initEnvSender2(t *testing.T) (*CertManageRuntime, *mock.MockTxSimContext, func()) {
r, m, f := initEnvCore(t) r, m, f := initEnvCore(t)
m.EXPECT().GetSender().Return(getOrg2Client1Signer()).AnyTimes() m.EXPECT().GetSender().Return(getOrg2Client1Signer()).AnyTimes()
m.EXPECT().GetTx().DoAndReturn(
func() *commonPb.Transaction {
return &commonPb.Transaction{
Sender: &commonPb.EndorsementEntry{
Signer: getOrg1Client1Signer(),
},
Endorsers: []*commonPb.EndorsementEntry{
{
Signer: getOrg2Client1Signer(),
Signature: nil,
},
},
}
}).AnyTimes()
return r, m, f return r, m, f
} }
...@@ -97,14 +126,6 @@ func initEnvCore(t *testing.T) (*CertManageRuntime, *mock.MockTxSimContext, func ...@@ -97,14 +126,6 @@ func initEnvCore(t *testing.T) (*CertManageRuntime, *mock.MockTxSimContext, func
func(name string, key []byte) error { func(name string, key []byte) error {
return cache.Del(name, string(key)) return cache.Del(name, string(key))
}).AnyTimes() }).AnyTimes()
txSimContext.EXPECT().GetTx().DoAndReturn(
func() *commonPb.Transaction {
return &commonPb.Transaction{
Sender: &commonPb.EndorsementEntry{
Signer: getOrg1Client1Signer(),
},
}
}).AnyTimes()
txSimContext.EXPECT().GetBlockHeight().Return(uint64(1)).AnyTimes() txSimContext.EXPECT().GetBlockHeight().Return(uint64(1)).AnyTimes()
return certMgrRuntime, txSimContext, func() { ctrl.Finish() } return certMgrRuntime, txSimContext, func() { ctrl.Finish() }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment