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

valksor / go-assern / 26285265118

22 May 2026 11:31AM UTC coverage: 51.35% (+5.7%) from 45.617%
26285265118

push

github

k0d3r1s
Ignores local Claude memory files

The local memory server creates files that are not meant for version control. These rules ensure they stay out of the repository.

2909 of 5665 relevant lines covered (51.35%)

75.18 hits per line

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

97.22
/internal/cli/validators.go
1
// Package cli provides interactive CLI components for assern.
2
package cli
3

4
import (
5
        "errors"
6
        "fmt"
7
        "net/url"
8
        "regexp"
9
        "strings"
10
)
11

12
// Transport type identifiers for MCP servers.
13
const (
14
        transportStdio     = "stdio"
15
        transportHTTP      = "http"
16
        transportSSE       = "sse"
17
        transportOAuthHTTP = "oauth-http"
18
        transportOAuthSSE  = "oauth-sse"
19
)
20

21
// reservedNames are server names that cannot be used.
22
var reservedNames = map[string]bool{
23
        "all":     true,
24
        "global":  true,
25
        "project": true,
26
}
27

28
// serverNameRegex validates server names: alphanumeric with hyphens/underscores.
29
var serverNameRegex = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9_-]*$`)
30

31
// ValidateServerName checks if a server name is valid.
32
func ValidateServerName(name string) error {
11✔
33
        if name == "" {
12✔
34
                return errors.New("server name cannot be empty")
1✔
35
        }
1✔
36

37
        if len(name) > 64 {
11✔
38
                return errors.New("server name must be 64 characters or less")
1✔
39
        }
1✔
40

41
        if reservedNames[strings.ToLower(name)] {
12✔
42
                return fmt.Errorf("'%s' is a reserved server name", name)
3✔
43
        }
3✔
44

45
        if !serverNameRegex.MatchString(name) {
8✔
46
                return errors.New("server name must start with a letter and contain only letters, numbers, hyphens, and underscores")
2✔
47
        }
2✔
48

49
        return nil
4✔
50
}
51

52
// ValidateURL checks if a string is a valid URL.
53
func ValidateURL(u string) error {
10✔
54
        if u == "" {
12✔
55
                return errors.New("URL cannot be empty")
2✔
56
        }
2✔
57

58
        parsed, err := url.Parse(u)
8✔
59
        if err != nil {
8✔
60
                return fmt.Errorf("invalid URL: %w", err)
×
61
        }
×
62

63
        if parsed.Scheme == "" {
9✔
64
                return errors.New("URL must include a scheme (http:// or https://)")
1✔
65
        }
1✔
66

67
        if parsed.Scheme != "http" && parsed.Scheme != "https" {
8✔
68
                return errors.New("URL scheme must be http or https")
1✔
69
        }
1✔
70

71
        if parsed.Host == "" {
7✔
72
                return errors.New("URL must include a host")
1✔
73
        }
1✔
74

75
        return nil
5✔
76
}
77

78
// ValidateHTTPSURL checks if a string is a valid HTTPS URL.
79
func ValidateHTTPSURL(u string) error {
3✔
80
        if err := ValidateURL(u); err != nil {
4✔
81
                return err
1✔
82
        }
1✔
83

84
        parsed, _ := url.Parse(u)
2✔
85
        if parsed.Scheme != "https" {
3✔
86
                return errors.New("OAuth requires HTTPS URL")
1✔
87
        }
1✔
88

89
        return nil
1✔
90
}
91

92
// ValidateEnvVarKey checks if an environment variable key is valid.
93
func ValidateEnvVarKey(key string) error {
6✔
94
        if key == "" {
7✔
95
                return errors.New("environment variable key cannot be empty")
1✔
96
        }
1✔
97

98
        // Env var keys should be alphanumeric with underscores, typically uppercase
99
        envVarRegex := regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*$`)
5✔
100
        if !envVarRegex.MatchString(key) {
7✔
101
                return errors.New("environment variable key must contain only letters, numbers, and underscores")
2✔
102
        }
2✔
103

104
        return nil
3✔
105
}
106

107
// ValidateRequired checks if a required field is empty.
108
func ValidateRequired(value, fieldName string) error {
3✔
109
        if strings.TrimSpace(value) == "" {
5✔
110
                return fmt.Errorf("%s is required", fieldName)
2✔
111
        }
2✔
112

113
        return nil
1✔
114
}
115

116
// ValidateTransport checks if a transport type is valid.
117
func ValidateTransport(transport string) error {
7✔
118
        validTransports := map[string]bool{
7✔
119
                transportStdio:     true,
7✔
120
                transportHTTP:      true,
7✔
121
                transportSSE:       true,
7✔
122
                transportOAuthHTTP: true,
7✔
123
                transportOAuthSSE:  true,
7✔
124
                "":                 true, // Auto-detect
7✔
125
        }
7✔
126

7✔
127
        if !validTransports[transport] {
8✔
128
                return fmt.Errorf("invalid transport type: %s (must be stdio, http, sse, oauth-http, or oauth-sse)", transport)
1✔
129
        }
1✔
130

131
        return nil
6✔
132
}
133

134
// IsReservedName checks if a name is reserved.
135
func IsReservedName(name string) bool {
6✔
136
        return reservedNames[strings.ToLower(name)]
6✔
137
}
6✔
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

© 2026 Coveralls, Inc