Skip to content

Commit

Permalink
NET-509-515
Browse files Browse the repository at this point in the history
* Updated unit test for network name max length check.

* Updated extclient endpoint ip string manipulation to use sprintf

* Added proper error message for network name length more than max allowed.
  • Loading branch information
uGiFarukh committed Aug 7, 2023
1 parent fc37b32 commit aec639e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions controllers/ext_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ func getExtClientConf(w http.ResponseWriter, r *http.Request) {
}
gwendpoint := ""
if host.EndpointIP.To4() == nil {
gwendpoint = "[" + host.EndpointIP.String() + "]" + ":" + strconv.Itoa(host.ListenPort)
gwendpoint = fmt.Sprintf("[%s]:%d", host.EndpointIP.String(), host.ListenPort)
} else {
gwendpoint = host.EndpointIP.String() + ":" + strconv.Itoa(host.ListenPort)
gwendpoint = fmt.Sprintf("%s:%d", host.EndpointIP.String(), host.ListenPort)
}
newAllowedIPs := network.AddressRange
if newAllowedIPs != "" && network.AddressRange6 != "" {
Expand Down
8 changes: 8 additions & 0 deletions controllers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ func createNetwork(w http.ResponseWriter, r *http.Request) {
return
}

if len(network.NetID) > 32 {
err := errors.New("Network name shouldn't exceed 32 characters")

Check failure on line 249 in controllers/network.go

View workflow job for this annotation

GitHub Actions / staticcheck

error strings should not be capitalized (ST1005)
logger.Log(0, r.Header.Get("user"), "failed to create network: ",
err.Error())
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}

if network.AddressRange == "" && network.AddressRange6 == "" {
err := errors.New("IPv4 or IPv6 CIDR required")
logger.Log(0, r.Header.Get("user"), "failed to create network: ",
Expand Down
4 changes: 2 additions & 2 deletions controllers/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestDeleteNetwork(t *testing.T) {
err := logic.DeleteNetwork("skynet")
assert.Nil(t, err)
})
t.Run("NonExistantNetwork", func(t *testing.T) {
t.Run("NonExistentNetwork", func(t *testing.T) {
err := logic.DeleteNetwork("skynet")
assert.Nil(t, err)
})
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestValidateNetwork(t *testing.T) {
{
testname: "NetIDTooLong",
network: models.Network{
NetID: "LongNetIDName",
NetID: "LongNetIDNameForMaxCharactersTest",
},
errMessage: "Field validation for 'NetID' failed on the 'max' tag",
},
Expand Down

0 comments on commit aec639e

Please sign in to comment.