• 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

97.14
/util.go
1
package pusher
2

3
import (
4
        "errors"
5
        "encoding/json"
6
        "fmt"
7
        "net/url"
8
        "regexp"
9
        "strconv"
10
        "strings"
11
        "time"
12
)
13

14
var channelValidationRegex = regexp.MustCompile("^[-a-zA-Z0-9_=@,.;]+$")
15
var socketIDValidationRegex = regexp.MustCompile(`\A\d+\.\d+\z`)
16
var maxChannelNameSize = 200
17

18
func jsonMarshalToString(data interface{}) (result string, err error) {
2✔
19
        var _result []byte
2✔
20
        _result, err = json.Marshal(data)
2✔
21
        if err != nil {
2✔
22
                return
×
23
        }
×
24
        return string(_result), err
2✔
25
}
26

27
func authTimestamp() string {
2✔
28
        return strconv.FormatInt(time.Now().Unix(), 10)
2✔
29
}
2✔
30

31
func parseUserAuthenticationRequestParams(_params []byte) (socketID string, err error) {
2✔
32
        params, err := url.ParseQuery(string(_params))
2✔
33
        if err != nil {
4✔
34
                return
2✔
35
        }
2✔
36
        if _, ok := params["socket_id"]; !ok {
4✔
37
                return "", errors.New("socket_id not found")
2✔
38
        }
2✔
39
        return params["socket_id"][0], nil
2✔
40
}
41

42
func parseChannelAuthorizationRequestParams(_params []byte) (channelName string, socketID string, err error) {
2✔
43
        params, err := url.ParseQuery(string(_params))
2✔
44
        if err != nil {
4✔
45
                return
2✔
46
        }
2✔
47
        if _, ok := params["channel_name"]; !ok {
4✔
48
                return "", "", errors.New("channel_name not found")
2✔
49
        }
2✔
50
        if _, ok := params["socket_id"]; !ok {
4✔
51
                return "", "", errors.New("socket_id not found")
2✔
52
        }
2✔
53
        return params["channel_name"][0], params["socket_id"][0], nil
2✔
54
}
55

56
func validUserId(userId string) bool {
2✔
57
        length := len(userId)
2✔
58
        return length > 0 && length < maxChannelNameSize
2✔
59
}
2✔
60

61
func validChannel(channel string) bool {
2✔
62
        if len(channel) > maxChannelNameSize || !channelValidationRegex.MatchString(channel) {
4✔
63
                return false
2✔
64
        }
2✔
65
        return true
2✔
66
}
67

68
func channelsAreValid(channels []string) bool {
2✔
69
        for _, channel := range channels {
4✔
70
                if !validChannel(channel) {
4✔
71
                        return false
2✔
72
                }
2✔
73
        }
74
        return true
2✔
75
}
76

77
func isEncryptedChannel(channel string) bool {
2✔
78
        if strings.HasPrefix(channel, "private-encrypted-") {
4✔
79
                return true
2✔
80
        }
2✔
81
        return false
2✔
82
}
83

84
func validateUserData(userData map[string]interface{}) (err error) {
2✔
85
        _id, ok := userData["id"]
2✔
86
        if !ok || _id == nil {
4✔
87
                return errors.New("Missing id in user data")
2✔
88
        }
2✔
89
        var id string
2✔
90
        id, ok = _id.(string)
2✔
91
        if !ok {
4✔
92
                return errors.New("id field in user data is not a string")
2✔
93
        }
2✔
94
        if !validUserId(id) {
4✔
95
                return fmt.Errorf("Invalid id in user data: '%s'", id)
2✔
96
        }
2✔
97
        return
2✔
98
}
99

100
func validateSocketID(socketID *string) (err error) {
2✔
101
        if (socketID == nil) || socketIDValidationRegex.MatchString(*socketID) {
4✔
102
                return
2✔
103
        }
2✔
104
        return errors.New("socket_id invalid")
2✔
105
}
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