service: implement Token field setter on RequestVerificationHeader
After recent changes Token field is presented in RequestVerificationHeader. There is a need to provide an interface of field getter/setter. This commit: * defines TokenHeader interface of token value container; * implements Token field setter on RequestVerificationHeader.
This commit is contained in:
parent
09f8ee52d0
commit
942bedb8ed
2 changed files with 25 additions and 0 deletions
|
@ -27,6 +27,12 @@ type (
|
||||||
SetOwner(*ecdsa.PublicKey, []byte)
|
SetOwner(*ecdsa.PublicKey, []byte)
|
||||||
GetLastPeer() (*ecdsa.PublicKey, error)
|
GetLastPeer() (*ecdsa.PublicKey, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TokenHeader is an interface of the container of a Token pointer value
|
||||||
|
TokenHeader interface {
|
||||||
|
GetToken() *Token
|
||||||
|
SetToken(*Token)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -97,6 +103,11 @@ func (m *RequestVerificationHeader) GetLastPeer() (*ecdsa.PublicKey, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetToken is a Token field setter.
|
||||||
|
func (m *RequestVerificationHeader) SetToken(token *Token) {
|
||||||
|
m.Token = token
|
||||||
|
}
|
||||||
|
|
||||||
func newSignature(key *ecdsa.PrivateKey, data []byte) (*RequestVerificationHeader_Signature, error) {
|
func newSignature(key *ecdsa.PrivateKey, data []byte) (*RequestVerificationHeader_Signature, error) {
|
||||||
sign, err := crypto.Sign(key, data)
|
sign, err := crypto.Sign(key, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -188,3 +188,17 @@ func TestVerifyAndSignRequestHeaderWithoutCloning(t *testing.T) {
|
||||||
|
|
||||||
require.Contains(t, buf.String(), "proto: don't know how to copy")
|
require.Contains(t, buf.String(), "proto: don't know how to copy")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRequestVerificationHeader_SetToken(t *testing.T) {
|
||||||
|
id, err := refs.NewUUID()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
token := new(Token)
|
||||||
|
token.ID = id
|
||||||
|
|
||||||
|
h := new(RequestVerificationHeader)
|
||||||
|
|
||||||
|
h.SetToken(token)
|
||||||
|
|
||||||
|
require.Equal(t, token, h.GetToken())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue