Skip to content

Commit

Permalink
Merge branch 'main' into pfairban/merge-vh
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed Sep 14, 2024
2 parents 423758a + 33d3cdc commit d9eb1b5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
7 changes: 6 additions & 1 deletion radio/configuration_request_ap.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ func (request ConfigurationRequest) Validate(radio *Radio) error {
return fmt.Errorf("SSID for station %s cannot be blank", stationName)
}
if len(stationConfiguration.Ssid) > maxStationSsidLength {
return fmt.Errorf("invalid SSID length for station %s: %d (expecting 1-%d)", stationName, len(stationConfiguration.Ssid), maxStationSsidLength)
return fmt.Errorf(
"invalid SSID length for station %s: %d (expecting 1-%d)",
stationName,
len(stationConfiguration.Ssid),
maxStationSsidLength,
)
}
if !regexp.MustCompile(stationSsidRegex).MatchString(stationConfiguration.Ssid) {
return fmt.Errorf("invalid SSID for station %s (expecting alphanumeric with hyphens)", stationName)
Expand Down
4 changes: 2 additions & 2 deletions radio/configuration_request_ap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestConfigurationRequest_Validate(t *testing.T) {
err = request.Validate(linksysRadio)
assert.EqualError(t, err, "invalid SSID length for station blue1: 16 (expecting 1-14)")

// Invalid SSID.
// Invalid characters in SSID.
request = ConfigurationRequest{
StationConfigurations: map[string]StationConfiguration{"blue1": {Ssid: "abc_XYZ", WpaKey: "12345678"}},
}
Expand All @@ -96,7 +96,7 @@ func TestConfigurationRequest_Validate(t *testing.T) {
err = request.Validate(linksysRadio)
assert.EqualError(t, err, "invalid WPA key length for station blue1: 17 (expecting 8-16)")

// Invalid WPA key.
// Invalid characters in WPA key.
request = ConfigurationRequest{
StationConfigurations: map[string]StationConfiguration{"blue1": {Ssid: "254", WpaKey: "aAbC2__+#"}},
}
Expand Down
14 changes: 10 additions & 4 deletions radio/configuration_request_robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
const (
// Maximum length for the SSID suffix.
maxSsidSuffixLength = 8

// Regex to validate the SSID suffix.
ssidSuffixRegex = "^[a-zA-Z0-9]*$"
)

// ConfigurationRequest represents a JSON request to configure the radio.
Expand All @@ -26,13 +29,14 @@ type ConfigurationRequest struct {
// Team number to configure the radio for. Must be between 1 and 25499.
TeamNumber int `json:"teamNumber"`

// Suffix to be appended to all WPA SSIDs. Must be alphanumeric and less than eight charaters long.
// Suffix to be appended to all WPA SSIDs. Must be alphanumeric and at most eight characters long.
SsidSuffix string `json:"ssidSuffix"`

// Team-specific WPA key for the 6GHz network used by the FMS. Must be at least eight alphanumeric characters long.
WpaKey6 string `json:"wpaKey6"`

// WPA key for the 2.4GHz network broadcast by the radio for team use. Must be at least eight alphanumeric characters long.
// WPA key for the 2.4GHz network broadcast by the radio for team use. Must be at least eight alphanumeric
// characters long.
WpaKey24 string `json:"wpaKey24"`
}

Expand All @@ -54,9 +58,11 @@ func (request ConfigurationRequest) Validate(radio *Radio) error {
}

if len(request.SsidSuffix) > maxSsidSuffixLength {
return fmt.Errorf("invalid ssidSuffix length: %d (expecting 0-%d)", len(request.SsidSuffix), maxSsidSuffixLength)
return fmt.Errorf(
"invalid ssidSuffix length: %d (expecting 0-%d)", len(request.SsidSuffix), maxSsidSuffixLength,
)
}
if !regexp.MustCompile(alphanumericRegex).MatchString(request.SsidSuffix) {
if !regexp.MustCompile(ssidSuffixRegex).MatchString(request.SsidSuffix) {
return errors.New("invalid ssidSuffix (expecting alphanumeric)")
}

Expand Down
6 changes: 3 additions & 3 deletions radio/radio_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ const (
// Maximum length for WPA keys.
maxWpaKeyLength = 16

// Regex to validate a string as alphanumeric.
alphanumericRegex = "^[a-zA-Z0-9]*$"

// Valid characters in the randomly generated salt used to obscure the WPA key.
saltCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

// Length of the randomly generated salt used to obscure the WPA key.
saltLength = 16

// Regex to validate the a string as alphanumeric.
alphanumericRegex = "^[a-zA-Z0-9]*$"
)

// RadioType represents the hardware type of the radio.
Expand Down
5 changes: 1 addition & 4 deletions web/web_server_ap.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ func getVlan100IpAddress() (string, error) {
}

// addRoutes adds additional route handlers to the router if needed.
func addRoutes(router *mux.Router, web *WebServer) {
router.HandleFunc("/scan/start", web.startScanHandler).Methods("GET")
router.HandleFunc("/scan/result", web.scanResultHandler).Methods("GET")
}
func addRoutes(router *mux.Router, web *WebServer) {}

// rootHandler redirects the root URL to the status page.
func (web *WebServer) rootHandler(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit d9eb1b5

Please sign in to comment.