Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
chore: Update golangci to 1.19
Browse files Browse the repository at this point in the history
closes hyperledger-archives#334

Signed-off-by: Firas Qutishat <[email protected]>
  • Loading branch information
fqutishat authored and Filip Burlacu committed Sep 25, 2019
1 parent 7cd296a commit d6946d7
Show file tree
Hide file tree
Showing 49 changed files with 197 additions and 264 deletions.
5 changes: 3 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ issues:
exclude:
# Allow package logger variables (for now)
- \`logger\` is a global variable
# Temporary until golangci update to go 1.13
- Is not declared by package errors
- Line contains TODO/BUG/FIXME
# Add comments for package
- at least one file in a package should have a package comment
1 change: 0 additions & 1 deletion cmd/aries-agentd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ var logger = log.New("aries-framework/agentd")

// This is an application which starts Aries agent controller API on given port
func main() {

// Default port and command lines arguments will be addressed as part of #94
host := os.Getenv(agentHostEnvKey)
if host == "" {
Expand Down
8 changes: 0 additions & 8 deletions cmd/aries-agentd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ func validateRequests(t *testing.T, testURL, testInboundURL string) {
expectResponseData: false,
},
}

for _, tt := range tests {

resp, err := http.DefaultClient.Do(tt.r)
if err != nil {
t.Fatal(err)
Expand All @@ -190,18 +188,15 @@ func validateRequests(t *testing.T, testURL, testInboundURL string) {
require.True(t, isJSON(response))
}
}

}

// isJSON checks if response is json
func isJSON(res []byte) bool {
var js map[string]interface{}
return json.Unmarshal(res, &js) == nil

}

func TestStartAriesDWithoutHost(t *testing.T) {

prev := os.Getenv(agentHostEnvKey)
defer func() {
err := os.Setenv(agentHostEnvKey, prev)
Expand All @@ -228,11 +223,9 @@ func TestStartAriesDWithoutHost(t *testing.T) {
case <-time.After(5 * time.Second):
t.Fatal("agent should fail to start when host address not provided")
}

}

func TestStartAriesWithoutInboundHost(t *testing.T) {

prev := os.Getenv(agentHostEnvKey)
defer func() {
err := os.Setenv(agentHostEnvKey, prev)
Expand Down Expand Up @@ -272,7 +265,6 @@ func TestStartAriesWithoutInboundHost(t *testing.T) {
case <-time.After(5 * time.Second):
t.Fatal("agent should fail to start when inbound host address not provided")
}

}

func generateTempDir(t testing.TB) (string, func()) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/didexchange/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func New(ctx provider) (*Client, error) {
if !ok {
return nil, errors.New("cast service to DIDExchange Service failed")
}
return &Client{didexchangeSvc: didexchangeSvc, wallet: ctx.CryptoWallet(), inboundTransportEndpoint: ctx.InboundTransportEndpoint()}, nil
return &Client{didexchangeSvc: didexchangeSvc, wallet: ctx.CryptoWallet(),
inboundTransportEndpoint: ctx.InboundTransportEndpoint()}, nil
}

// CreateInvitation create invitation
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/didexchange/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func TestClient_CreateInvitation(t *testing.T) {
require.Error(t, err)
require.Contains(t, err.Error(), "createSigningKeyErr")
})

}

func TestClient_QueryConnectionByID(t *testing.T) {
Expand Down Expand Up @@ -93,8 +92,9 @@ func TestClient_HandleInvitation(t *testing.T) {
})

t.Run("test error from handle msg", func(t *testing.T) {
c, err := New(&mockprovider.Provider{ServiceValue: &mockprotocol.MockDIDExchangeSvc{HandleErr: fmt.Errorf("handle error")},
WalletValue: &mockwallet.CloseableWallet{}, InboundEndpointValue: "endpoint"})
c, err := New(&mockprovider.Provider{
ServiceValue: &mockprotocol.MockDIDExchangeSvc{HandleErr: fmt.Errorf("handle error")},
WalletValue: &mockwallet.CloseableWallet{}, InboundEndpointValue: "endpoint"})
require.NoError(t, err)
inviteReq, err := c.CreateInvitation()
require.NoError(t, err)
Expand Down
8 changes: 0 additions & 8 deletions pkg/common/log/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

// TestDefaultLogger tests default logging feature when no custom logging provider is supplied via 'Initialize()' call
func TestDefaultLogger(t *testing.T) {

defer func() { loggerProviderOnce = sync.Once{} }()
const module = "sample-module"

Expand All @@ -31,13 +30,11 @@ func TestDefaultLogger(t *testing.T) {

// verify default logger
modlog.VerifyDefaultLogging(t, logger, module, metadata.SetLevel)

}

// TestAllLevels tests logging level behaviour
// logging levels can be set per modules, if not set then it will default to 'INFO'
func TestAllLevels(t *testing.T) {

module := "sample-module-critical"
SetLevel(module, CRITICAL)
require.Equal(t, CRITICAL, GetLevel(module))
Expand All @@ -62,7 +59,6 @@ func TestAllLevels(t *testing.T) {
SetLevel(module, DEBUG)
require.Equal(t, DEBUG, GetLevel(module))
verifyLevels(t, module, []Level{CRITICAL, ERROR, WARNING, INFO, DEBUG}, []Level{})

}

// TestCallerInfos callerinfo behavior which displays caller function details in log lines
Expand All @@ -82,12 +78,10 @@ func TestCallerInfos(t *testing.T) {
require.False(t, IsCallerInfoEnabled(module, INFO))
require.False(t, IsCallerInfoEnabled(module, ERROR))
require.False(t, IsCallerInfoEnabled(module, WARNING))

}

// TestLogLevel testing 'LogLevel()' used for parsing log levels from strings
func TestLogLevel(t *testing.T) {

verifyLevelsNoError := func(expected Level, levels ...string) {
for _, level := range levels {
actual, err := ParseLevel(level)
Expand All @@ -105,7 +99,6 @@ func TestLogLevel(t *testing.T) {

// TestParseLevelError testing 'LogLevel()' used for parsing log levels from strings
func TestParseLevelError(t *testing.T) {

verifyLevelError := func(levels ...string) {
for _, level := range levels {
_, err := ParseLevel(level)
Expand All @@ -114,7 +107,6 @@ func TestParseLevelError(t *testing.T) {
}

verifyLevelError("", "D", "DE BUG", ".")

}

func verifyLevels(t *testing.T, module string, enabled, disabled []Level) {
Expand Down
1 change: 0 additions & 1 deletion pkg/common/log/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

// TestDefaultLogger tests custom logging feature when custom logging provider is supplied through 'Initialize()' call
func TestCustomLogger(t *testing.T) {

defer func() { loggerProviderOnce = sync.Once{} }()
const module = "sample-module"

Expand Down
1 change: 0 additions & 1 deletion pkg/didcomm/crypto/legacy/authcrypt/authcrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type Crypter struct {
// New will create a Crypter that encrypts messages using the legacy Aries format
// Note: legacy crypter does not support XChacha20Poly1035 (XC20P), only Chacha20Poly1035 (C20P)
func New(sender keyPairEd25519, recipients []*publicEd25519) (*Crypter, error) { // nolint: lll

if len(recipients) == 0 {
return nil, errors.New("empty recipients keys, must have at least one recipient")
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/didcomm/crypto/legacy/authcrypt/authcrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func TestBadConfig(t *testing.T) {

func TestEncrypt(t *testing.T) {
t.Run("Success test case: given keys, generate envelope", func(t *testing.T) {

senderKey := getB58EdKey(
"Bxp2KpXeh6RgXXRVGRQUskT9qT35aSSz1JvdbMUcB2Yc",
"2QqgiHtrUtDPpfoZG2C3Qi8a1MbLQuTZaaScu5LzQbUCkw5YnXngKLMJ8VuPgoN3Piqt1PBUACVd6uQRmtayZp2x")
Expand Down Expand Up @@ -279,7 +278,6 @@ func TestSodiumBoxSeal(t *testing.T) {
require.NoError(t, err)

t.Run("Generate a box_seal message to compare to ACA-Py:", func(t *testing.T) {

msg := []byte("lorem ipsum dolor sit amet consectetur adipiscing elit ")

enc, err := sodiumBoxSeal(msg, recipient1Key.pub, rand.Reader)
Expand All @@ -292,7 +290,6 @@ func TestSodiumBoxSeal(t *testing.T) {
})

t.Run("Seal a message with sodiumBoxSeal and unseal it with sodiumBoxSealOpen", func(t *testing.T) {

msg := []byte("lorem ipsum dolor sit amet consectetur adipiscing elit ")

enc, err := sodiumBoxSeal(msg, recipient1Key.pub, rand.Reader)
Expand All @@ -304,7 +301,6 @@ func TestSodiumBoxSeal(t *testing.T) {
})

t.Run("Seal message, present signing key", func(t *testing.T) {

rec := getB58CurveKey(
"DJuB84EKcHjMcwRKV2CP6pDSWG8xL8V2yntcLpvuHTj4",
"9foNvM6BPbcAohay8cEkDG6BZj26Tave6k1mGcPx63yW")
Expand Down Expand Up @@ -420,7 +416,6 @@ func TestKeyConversion(t *testing.T) {
}

for i, edKeyString := range edPubs {

edKeyBytes := base58.Decode(edKeyString)
edKey := publicEd25519{}
copy(edKey[:], edKeyBytes)
Expand Down Expand Up @@ -484,7 +479,6 @@ func TestKeyConversion(t *testing.T) {
}

for i, edKeyString := range edPrivs {

edKeyBytes := base58.Decode(edKeyString)
edKey := privateEd25519{}
copy(edKey[:], edKeyBytes)
Expand Down Expand Up @@ -561,7 +555,6 @@ func getB58EdKey(pub, priv string) *keyPairEd25519 {
}

func getB58CurveKey(pub, priv string) *keyPairCurve25519 {

key := keyPairCurve25519{new(privateCurve25519), new(publicCurve25519)}
pubk := base58.Decode(pub)
privk := base58.Decode(priv)
Expand Down
1 change: 0 additions & 1 deletion pkg/didcomm/crypto/legacy/authcrypt/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func (c *Crypter) buildRecipients(cek *[chacha.KeySize]byte) ([]recipient, error
// buildRecipient encodes the necessary data for the recipient to decrypt the message
// encrypting the CEK and sender pub key
func (c *Crypter) buildRecipient(cek *[chacha.KeySize]byte, recKey *publicEd25519) (*recipient, error) {

var nonce [24]byte

_, err := c.randSource.Read(nonce[:])
Expand Down
2 changes: 1 addition & 1 deletion pkg/didcomm/dispatcher/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type DIDCommMsg struct {
Outbound bool
Type string
Payload []byte
//TODO : might need refactor as per the issue-226
// TODO : might need refactor as per the issue-226
OutboundDestination *Destination
}

Expand Down
32 changes: 17 additions & 15 deletions pkg/didcomm/dispatcher/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,24 @@ func NewOutbound(prov Provider) *OutboundDispatcher {
// Send msg
func (o *OutboundDispatcher) Send(msg interface{}, senderVerKey string, des *Destination) error {
for _, v := range o.outboundTransports {
if v.Accept(des.ServiceEndpoint) {
bytes, err := json.Marshal(msg)
if err != nil {
return fmt.Errorf("failed marshal to bytes: %w", err)
}
packedMsg, err := o.wallet.PackMessage(&wallet.Envelope{Message: bytes, FromVerKey: senderVerKey, ToVerKeys: des.RecipientKeys})
if err != nil {
return fmt.Errorf("failed to pack msg: %w", err)
}
// TODO should we return respData from send
_, err = v.Send(packedMsg, des.ServiceEndpoint)
if err != nil {
return fmt.Errorf("failed to send msg using http outbound transport: %w", err)
}
return nil
if !v.Accept(des.ServiceEndpoint) {
continue
}
bytes, err := json.Marshal(msg)
if err != nil {
return fmt.Errorf("failed marshal to bytes: %w", err)
}
packedMsg, err := o.wallet.PackMessage(
&wallet.Envelope{Message: bytes, FromVerKey: senderVerKey, ToVerKeys: des.RecipientKeys})
if err != nil {
return fmt.Errorf("failed to pack msg: %w", err)
}
// TODO should we return respData from send
_, err = v.Send(packedMsg, des.ServiceEndpoint)
if err != nil {
return fmt.Errorf("failed to send msg using http outbound transport: %w", err)
}
return nil
}
return fmt.Errorf("no outbound transport found for serviceEndpoint: %s", des.ServiceEndpoint)
}
3 changes: 2 additions & 1 deletion pkg/didcomm/dispatcher/outbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func TestOutboundDispatcher_Send(t *testing.T) {

t.Run("test outbound send failure", func(t *testing.T) {
o := NewOutbound(&provider{walletValue: &mockwallet.CloseableWallet{},
outboundTransportsValue: []transport.OutboundTransport{&mockdidcomm.MockOutboundTransport{AcceptValue: true, SendErr: fmt.Errorf("send error")}}})
outboundTransportsValue: []transport.OutboundTransport{
&mockdidcomm.MockOutboundTransport{AcceptValue: true, SendErr: fmt.Errorf("send error")}}})
err := o.Send("data", "", &Destination{ServiceEndpoint: "url"})
require.Error(t, err)
require.Contains(t, err.Error(), "send error")
Expand Down
12 changes: 6 additions & 6 deletions pkg/didcomm/protocol/didexchange/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ import (

"github.com/google/uuid"

"github.com/hyperledger/aries-framework-go/pkg/common/log"
"github.com/hyperledger/aries-framework-go/pkg/common/metadata"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/dispatcher"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/decorator"
"github.com/hyperledger/aries-framework-go/pkg/storage"
"github.com/hyperledger/aries-framework-go/pkg/wallet"
)

// TODO https://github.com/hyperledger/aries-framework-go/issues/104
var logger = log.New("aries-framework/didexchange")

// didCommChMessage type to correlate actionEvent message(go channel) with callback message(internal go channel).
type didCommChMessage struct {
ID string
Expand Down Expand Up @@ -224,7 +220,8 @@ func (s *Service) handle(msg *message) error {

// sendEvent triggers the action event. This function stores the state of current processing and passes a callback
// function in the event message.
func (s *Service) sendActionEvent(msg dispatcher.DIDCommMsg, aEvent chan<- dispatcher.DIDCommAction, threadID string, nextState state) error {
func (s *Service) sendActionEvent(msg dispatcher.DIDCommMsg, aEvent chan<- dispatcher.DIDCommAction,
threadID string, nextState state) error {
jsonDoc, err := json.Marshal(&message{
Msg: msg,
ThreadID: threadID,
Expand Down Expand Up @@ -273,7 +270,10 @@ func (s *Service) startInternalListener() {
go func() {
for msg := range s.callbackChannel {
// TODO handle error in callback - https://github.com/hyperledger/aries-framework-go/issues/242
s.process(msg.ID, msg.DIDCommCallback)
if err := s.process(msg.ID, msg.DIDCommCallback); err != nil {
// TODO handle error
fmt.Println(err.Error())
}
}
}()
}
Expand Down
Loading

0 comments on commit d6946d7

Please sign in to comment.