• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pusher / pusher-http-go / 12285846667

11 Dec 2024 10:17PM UTC coverage: 87.082%. Remained the same
12285846667

Pull #93

github

web-flow
Bump golang.org/x/crypto

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.0.0-20200709230013-948cd5f35899 to 0.31.0.
- [Commits](https://github.com/golang/crypto/commits/v0.31.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #93: Bump golang.org/x/crypto from 0.0.0-20200709230013-948cd5f35899 to 0.31.0

573 of 658 relevant lines covered (87.08%)

1.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.01
/encoder.go
1
package pusher
2

3
import (
4
        "encoding/json"
5
        "errors"
6
        "fmt"
7
)
8

9
// defaultMaxEventPayloadSizeKB indicates the max size allowed for the data content
10
// (payload) of each event, unless an override is present in the client
11
const defaultMaxEventPayloadSizeKB = 10
12

13
type batchEvent struct {
14
        Channel  string  `json:"channel"`
15
        Name     string  `json:"name"`
16
        Data     string  `json:"data"`
17
        SocketID *string `json:"socket_id,omitempty"`
18
        Info     *string `json:"info,omitempty"`
19
}
20
type batchPayload struct {
21
        Batch []batchEvent `json:"batch"`
22
}
23

24
func encodeTriggerBody(
25
        channels []string,
26
        event string,
27
        data interface{},
28
        params map[string]string,
29
        encryptionKey []byte,
30
        overrideMaxMessagePayloadKB int,
31
) ([]byte, error) {
2✔
32
        dataBytes, err := encodeEventData(data)
2✔
33
        if err != nil {
2✔
34
                return nil, err
×
35
        }
×
36
        var payloadData string
2✔
37
        if isEncryptedChannel(channels[0]) {
4✔
38
                payloadData = encrypt(channels[0], dataBytes, encryptionKey)
2✔
39
        } else {
4✔
40
                payloadData = string(dataBytes)
2✔
41
        }
2✔
42

43
        eventExceedsMaximumSize := false
2✔
44
        if overrideMaxMessagePayloadKB == 0 {
4✔
45
                eventExceedsMaximumSize = len(payloadData) > defaultMaxEventPayloadSizeKB*1024
2✔
46
        } else {
4✔
47
                eventExceedsMaximumSize = len(payloadData) > overrideMaxMessagePayloadKB*1024
2✔
48
        }
2✔
49
        if eventExceedsMaximumSize {
4✔
50
                return nil, errors.New(fmt.Sprintf("Event payload exceeded maximum size (%d bytes is too much)", len(payloadData)))
2✔
51
        }
2✔
52
        eventPayload := map[string]interface{}{
2✔
53
                "name":     event,
2✔
54
                "channels": channels,
2✔
55
                "data":     payloadData,
2✔
56
        }
2✔
57
        for k, v := range params {
4✔
58
                if _, ok := eventPayload[k]; ok {
2✔
59
                        return nil, errors.New(fmt.Sprintf("Paramater %s specified multiple times", k))
×
60
                }
×
61
                eventPayload[k] = v
2✔
62
        }
63
        return json.Marshal(eventPayload)
2✔
64
}
65

66
func encodeTriggerBatchBody(
67
        batch []Event,
68
        encryptionKey []byte,
69
        overrideMaxMessagePayloadKB int,
70
) ([]byte, error) {
2✔
71
        batchEvents := make([]batchEvent, len(batch))
2✔
72
        for idx, e := range batch {
4✔
73
                var stringifyedDataBytes string
2✔
74
                dataBytes, err := encodeEventData(e.Data)
2✔
75
                if err != nil {
2✔
76
                        return nil, err
×
77
                }
×
78
                if isEncryptedChannel(e.Channel) {
4✔
79
                        stringifyedDataBytes = encrypt(e.Channel, dataBytes, encryptionKey)
2✔
80
                } else {
4✔
81
                        stringifyedDataBytes = string(dataBytes)
2✔
82
                }
2✔
83
                eventExceedsMaximumSize := false
2✔
84
                if overrideMaxMessagePayloadKB == 0 {
4✔
85
                        eventExceedsMaximumSize = len(stringifyedDataBytes) > defaultMaxEventPayloadSizeKB*1024
2✔
86
                } else {
4✔
87
                        eventExceedsMaximumSize = len(stringifyedDataBytes) > overrideMaxMessagePayloadKB*1024
2✔
88
                }
2✔
89
                if eventExceedsMaximumSize {
4✔
90
                        return nil, fmt.Errorf("Data of the event #%d in batch, exceeded maximum size (%d bytes is too much)", idx, len(stringifyedDataBytes))
2✔
91
                }
2✔
92
                newBatchEvent := batchEvent{
2✔
93
                        Channel:  e.Channel,
2✔
94
                        Name:     e.Name,
2✔
95
                        Data:     stringifyedDataBytes,
2✔
96
                        SocketID: e.SocketID,
2✔
97
                        Info:     e.Info,
2✔
98
                }
2✔
99
                batchEvents[idx] = newBatchEvent
2✔
100
        }
101
        return json.Marshal(&batchPayload{batchEvents})
2✔
102
}
103

104
func encodeEventData(data interface{}) ([]byte, error) {
2✔
105
        var dataBytes []byte
2✔
106
        var err error
2✔
107

2✔
108
        switch d := data.(type) {
2✔
109
        case []byte:
×
110
                dataBytes = d
×
111
        case string:
2✔
112
                dataBytes = []byte(d)
2✔
113
        default:
2✔
114
                dataBytes, err = json.Marshal(data)
2✔
115
                if err != nil {
2✔
116
                        return nil, err
×
117
                }
×
118
        }
119
        return dataBytes, nil
2✔
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc