Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
新注册的用户请输入邮箱并保存,随后登录邮箱激活账号。后续可直接使用邮箱登录!
Open sidebar
bao xinyu
vm-native
Commits
5ba3de12
Commit
5ba3de12
authored
Mar 09, 2022
by
taifu yuan
🏸
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 当前组织管理员多签可更新删除别名信息
parent
4920839a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
47 deletions
+82
-47
certmgr/cert_alias_manage_contract.go
certmgr/cert_alias_manage_contract.go
+50
-36
certmgr/cert_alias_manage_contract_test.go
certmgr/cert_alias_manage_contract_test.go
+2
-2
certmgr/cert_manage_contract_test.go
certmgr/cert_manage_contract_test.go
+30
-9
No files found.
certmgr/cert_alias_manage_contract.go
View file @
5ba3de12
...
...
@@ -123,17 +123,20 @@ func (r *CertManageRuntime) UpdateAlias(txSimContext protocol.TxSimContext, para
return
nil
,
err
}
if
txSimContext
.
GetSender
()
.
OrgId
!=
certificate
.
Subject
.
Organization
[
0
]
{
return
nil
,
fmt
.
Errorf
(
"update alias fail, "
+
"you can't change other organization cert. "
+
"your org is %s cert org is %s"
,
txSimContext
.
GetSender
()
.
OrgId
,
certificate
.
Subject
.
Organization
[
0
])
if
!
containOrgId
(
txSimContext
,
certificate
.
Subject
.
Organization
[
0
])
{
err
=
fmt
.
Errorf
(
"update alias fail, "
+
"you can't change to other organization[%s] cert. "
,
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, "
+
"you can't change other organization cert. "
+
"your org is %s cert org is %s"
,
txSimContext
.
GetSender
()
.
OrgId
,
nowCertificate
.
Subject
.
Organization
[
0
])
if
!
containOrgId
(
txSimContext
,
nowCertificate
.
Subject
.
Organization
[
0
])
{
err
=
fmt
.
Errorf
(
"update alias fail, "
+
"you can't change other organization[%s] cert. "
,
certificate
.
Subject
.
Organization
[
0
])
r
.
log
.
Warn
(
err
)
return
nil
,
err
}
nowCert
:=
&
commonPb
.
AliasCertInfo
{
...
...
@@ -177,7 +180,7 @@ func (r *CertManageRuntime) DeleteAlias(txSimContext protocol.TxSimContext, para
names
:=
string
(
params
[
paramNameAliases
])
names
=
strings
.
TrimSpace
(
names
)
if
utils
.
IsAnyBlank
(
names
)
{
err
=
fmt
.
Errorf
(
"
upda
te alias failed, alias name is nil"
)
err
=
fmt
.
Errorf
(
"
dele
te alias failed, alias name is nil"
)
r
.
log
.
Warn
(
err
)
return
nil
,
err
}
...
...
@@ -198,16 +201,16 @@ func (r *CertManageRuntime) DeleteAlias(txSimContext protocol.TxSimContext, para
// verify org
certificate
,
err
:=
utils
.
ParseCert
(
certAliasInfo
.
NowCert
.
Cert
)
if
err
!=
nil
||
certificate
==
nil
||
certificate
.
Subject
.
Organization
==
nil
{
err
=
fmt
.
Errorf
(
"
upda
te alias fail, params[%s] format error, err:%s"
,
paramNameCert
,
err
)
err
=
fmt
.
Errorf
(
"
dele
te alias fail, params[%s] format error, err:%s"
,
paramNameCert
,
err
)
r
.
log
.
Warn
(
err
)
return
nil
,
err
}
if
txSimContext
.
GetSender
()
.
OrgId
!=
certificate
.
Subject
.
Organization
[
0
]
{
return
nil
,
fmt
.
Errorf
(
"delete alias fail,
"
+
"you can't change other o
rganization
cert. "
+
"your org is %s cert org is %s"
,
txSimContext
.
GetSender
()
.
OrgId
,
c
er
tificate
.
Subject
.
Organization
[
0
])
if
!
containOrgId
(
txSimContext
,
certificate
.
Subject
.
Organization
[
0
])
{
err
=
fmt
.
Errorf
(
"delete alias fail, "
+
"you can't delete other organization[%s] cert.
"
,
certificate
.
Subject
.
O
rganization
[
0
])
r
.
log
.
Warn
(
err
)
return
nil
,
er
r
}
blankCert
:=
&
commonPb
.
AliasCertInfo
{
BlockHeight
:
txSimContext
.
GetBlockHeight
()}
...
...
@@ -271,10 +274,10 @@ func (r *CertManageRuntime) addAliasCore(txSimContext protocol.TxSimContext, ali
if
certAliasInfo
==
nil
{
certAliasInfo
=
&
commonPb
.
AliasInfo
{
Alias
:
aliasName
}
}
//
err = r.saveAllAlias(txSimContext, aliasName)
//
if err != nil {
//
return err
//
}
err
=
r
.
saveAllAlias
(
txSimContext
,
aliasName
)
if
err
!=
nil
{
return
err
}
certAliasInfo
.
NowCert
=
nowCert
certAliasInfo
.
HisCerts
=
append
(
certAliasInfo
.
HisCerts
,
nowCert
)
err
=
r
.
setAliasToDb
(
txSimContext
,
certAliasInfo
)
...
...
@@ -285,20 +288,20 @@ func (r *CertManageRuntime) addAliasCore(txSimContext protocol.TxSimContext, ali
return
err
}
//
func (r *CertManageRuntime) saveAllAlias(txSimContext protocol.TxSimContext, aliasStr string) error {
//
allAliasBytes, err := txSimContext.Get(certManageContractName, []byte(certAliasKey+"all"))
//
if err != nil {
//
r.log.Warnf("save all alias failed, err: ", err.Error())
//
return err
//
}
//
allAlias := string(allAliasBytes)
//
if len(allAlias) > 0 {
//
allAlias += ","
//
}
//
allAlias += aliasStr
//
_ = txSimContext.Put(certManageContractName, []byte(certAliasKey+"all"), []byte(allAlias))
//
return nil
//
}
func
(
r
*
CertManageRuntime
)
saveAllAlias
(
txSimContext
protocol
.
TxSimContext
,
aliasStr
string
)
error
{
allAliasBytes
,
err
:=
txSimContext
.
Get
(
certManageContractName
,
[]
byte
(
certAliasKey
+
"all"
))
if
err
!=
nil
{
r
.
log
.
Warnf
(
"save all alias failed, err: "
,
err
.
Error
())
return
err
}
allAlias
:=
string
(
allAliasBytes
)
if
len
(
allAlias
)
>
0
{
allAlias
+=
","
}
allAlias
+=
aliasStr
_
=
txSimContext
.
Put
(
certManageContractName
,
[]
byte
(
certAliasKey
+
"all"
),
[]
byte
(
allAlias
))
return
nil
}
func
(
r
*
CertManageRuntime
)
setAliasToDb
(
txSimContext
protocol
.
TxSimContext
,
certAliasInfo
*
commonPb
.
AliasInfo
)
error
{
certAliasBytes
,
err
:=
certAliasInfo
.
Marshal
()
...
...
@@ -359,6 +362,17 @@ func (r *CertManageRuntime) setCertHash(txSimContext protocol.TxSimContext, nowC
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
//
//func (r *CertManageRuntime) FreezeAlias(txSimContext protocol.TxSimContext, params map[string][]byte) (
...
...
certmgr/cert_alias_manage_contract_test.go
View file @
5ba3de12
...
...
@@ -125,7 +125,7 @@ func Test_DeleteAlias(t *testing.T) {
// no alias add
params
:=
make
(
map
[
string
][]
byte
)
params
[
paramNameAliases
]
=
[]
byte
(
"alias03"
)
result
,
err
=
mgrRuntime
.
DeleteAlias
(
txSimContext
,
nil
)
result
,
err
=
mgrRuntime
.
DeleteAlias
(
txSimContext
,
params
)
assert
.
NotNil
(
t
,
err
)
assert
.
Nil
(
t
,
result
)
...
...
@@ -152,7 +152,7 @@ func Test_DeleteAlias(t *testing.T) {
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
"ok"
,
string
(
result2
))
//
d
ep
delete
//
r
ep
eat
params
[
paramNameAliases
]
=
[]
byte
(
"alias03"
)
params
[
paramNameCert
]
=
getOrg1Client1Signer
()
.
MemberInfo
result
,
err
=
mgrRuntime
.
DeleteAlias
(
txSimContext
,
params
)
...
...
certmgr/cert_manage_contract_test.go
View file @
5ba3de12
...
...
@@ -12,8 +12,9 @@ import (
"sync"
"testing"
"chainmaker.org/chainmaker/pb-go/v2/accesscontrol"
commonPb
"chainmaker.org/chainmaker/pb-go/v2/common"
"chainmaker.org/chainmaker/pb-go/v2/accesscontrol"
"chainmaker.org/chainmaker/protocol/v2/test"
"github.com/stretchr/testify/assert"
...
...
@@ -64,6 +65,20 @@ var _ protocol.TxSimContext = (*mock.MockTxSimContext)(nil)
func
initEnv
(
t
*
testing
.
T
)
(
*
CertManageRuntime
,
*
mock
.
MockTxSimContext
,
func
())
{
r
,
m
,
f
:=
initEnvCore
(
t
)
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
}
...
...
@@ -72,6 +87,20 @@ var cache = NewCacheMock()
func
initEnvSender2
(
t
*
testing
.
T
)
(
*
CertManageRuntime
,
*
mock
.
MockTxSimContext
,
func
())
{
r
,
m
,
f
:=
initEnvCore
(
t
)
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
}
...
...
@@ -97,14 +126,6 @@ func initEnvCore(t *testing.T) (*CertManageRuntime, *mock.MockTxSimContext, func
func
(
name
string
,
key
[]
byte
)
error
{
return
cache
.
Del
(
name
,
string
(
key
))
})
.
AnyTimes
()
txSimContext
.
EXPECT
()
.
GetTx
()
.
DoAndReturn
(
func
()
*
commonPb
.
Transaction
{
return
&
commonPb
.
Transaction
{
Sender
:
&
commonPb
.
EndorsementEntry
{
Signer
:
getOrg1Client1Signer
(),
},
}
})
.
AnyTimes
()
txSimContext
.
EXPECT
()
.
GetBlockHeight
()
.
Return
(
uint64
(
1
))
.
AnyTimes
()
return
certMgrRuntime
,
txSimContext
,
func
()
{
ctrl
.
Finish
()
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment