Merge pull request #94 from nspcc-dev/implement-bearer-interface-on-message

service: implement BearerToken interface on BearerTokenMsg message
This commit is contained in:
Leonard Lyubich 2020-06-18 16:12:15 +03:00 committed by GitHub
commit 6cbf6562c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 44 deletions

View file

@ -119,6 +119,16 @@ func (m *BearerTokenMsg_Info) SetOwnerID(v OwnerID) {
m.OwnerID = v
}
// ExpirationEpoch returns the result of ValidUntil field getter.
func (m BearerTokenMsg_Info) ExpirationEpoch() uint64 {
return m.GetValidUntil()
}
// SetExpirationEpoch passes argument to ValidUntil field setter.
func (m *BearerTokenMsg_Info) SetExpirationEpoch(v uint64) {
m.SetValidUntil(v)
}
// SetOwnerKey is an OwnerKey field setter.
func (m *BearerTokenMsg) SetOwnerKey(v []byte) {
m.OwnerKey = v
@ -128,29 +138,3 @@ func (m *BearerTokenMsg) SetOwnerKey(v []byte) {
func (m *BearerTokenMsg) SetSignature(v []byte) {
m.Signature = v
}
func wrapBearerTokenMsg(msg *BearerTokenMsg) bearerMsgWrapper {
return bearerMsgWrapper{
BearerTokenMsg: msg,
}
}
// ExpirationEpoch returns the result of ValidUntil field getter.
//
// If message is nil, 0 returns.
func (s bearerMsgWrapper) ExpirationEpoch() uint64 {
if s.BearerTokenMsg != nil {
return s.GetValidUntil()
}
return 0
}
// SetExpirationEpoch passes argument to ValidUntil field setter.
//
// If message is nil, nothing changes.
func (s bearerMsgWrapper) SetExpirationEpoch(v uint64) {
if s.BearerTokenMsg != nil {
s.SetValidUntil(v)
}
}

View file

@ -182,6 +182,9 @@ func TestBearerTokenMsg_Setters(t *testing.T) {
s.SetValidUntil(validUntil)
require.Equal(t, validUntil, s.GetValidUntil())
s.SetExpirationEpoch(validUntil + 1)
require.Equal(t, validUntil+1, s.ExpirationEpoch())
ownerID := OwnerID{1, 2, 3}
s.SetOwnerID(ownerID)
require.Equal(t, ownerID, s.GetOwnerID())
@ -194,18 +197,3 @@ func TestBearerTokenMsg_Setters(t *testing.T) {
s.SetSignature(sig)
require.Equal(t, sig, s.GetSignature())
}
func TestBearerMsgWrapper_ExpirationEpoch(t *testing.T) {
s := wrapBearerTokenMsg(nil)
require.Zero(t, s.ExpirationEpoch())
require.NotPanics(t, func() {
s.SetExpirationEpoch(1)
})
msg := new(BearerTokenMsg)
s = wrapBearerTokenMsg(msg)
epoch := uint64(7)
s.SetExpirationEpoch(epoch)
require.Equal(t, epoch, s.ExpirationEpoch())
}

View file

@ -286,7 +286,7 @@ func TestSignVerifyRequestData(t *testing.T) {
token = new(Token)
initVerb = Token_Info_Verb(1)
bearer = wrapBearerTokenMsg(new(BearerTokenMsg))
bearer = new(BearerTokenMsg)
bearerEpoch = uint64(8)
extHdrKey = "key"

View file

@ -109,7 +109,7 @@ func (t testCustomField) Marshal() ([]byte, error) { return nil, nil }
// If Bearer field value is nil, nil returns.
func (m RequestVerificationHeader) GetBearerToken() BearerToken {
if t := m.GetBearer(); t != nil {
return wrapBearerTokenMsg(t)
return t
}
return nil

View file

@ -136,5 +136,5 @@ func TestRequestVerificationHeader_GetBearerToken(t *testing.T) {
bearer := new(BearerTokenMsg)
s.SetBearer(bearer)
require.Equal(t, wrapBearerTokenMsg(bearer), s.GetBearerToken())
require.Equal(t, bearer, s.GetBearerToken())
}