Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #138 from lpabon/bug_137
Browse files Browse the repository at this point in the history
Check that hostname is not an empty string
  • Loading branch information
Luis Pabón committed Aug 14, 2015
2 parents 735455c + 956f35c commit 4fe2463
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apps/glusterfs/app_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ func (a *App) NodeAdd(w http.ResponseWriter, r *http.Request) {
return
}

// Check for correct values
for _, name := range append(msg.Hostnames.Manage, msg.Hostnames.Storage...) {
if name == "" {
http.Error(w, "Hostname cannot be an empty string", http.StatusBadRequest)
return
}
}

// Get cluster and peer node
var cluster *ClusterEntry
var peer_node *NodeEntry
Expand Down Expand Up @@ -78,7 +86,7 @@ func (a *App) NodeAdd(w http.ResponseWriter, r *http.Request) {
a.asyncManager.AsyncHttpRedirectFunc(w, r, func() (string, error) {

// Peer probe if there is at least one other node
// TODO: What happens if the peer_node is not responding.. we need to chose another.
// TODO: What happens if the peer_node is not responding.. we need to choose another.
if peer_node != nil {
err := a.executor.PeerProbe(peer_node.ManageHostName(), node.ManageHostName())
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions apps/glusterfs/app_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ func TestNodeAddBadRequests(t *testing.T) {
tests.Assert(t, err == nil)
tests.Assert(t, r.StatusCode == http.StatusBadRequest)

// Make a request where the hostnames are empty strings
request = []byte(`{
"cluster" : "123",
"hostnames" : {
"storage" : [ "" ],
"manage" : [ "" ]
},
"zone" : 10
}`)

// Check that it returns that the cluster id is not found
r, err = http.Post(ts.URL+"/nodes", "application/json", bytes.NewBuffer(request))
tests.Assert(t, err == nil)
tests.Assert(t, r.StatusCode == http.StatusBadRequest)
s, err := utils.GetStringFromResponse(r)
tests.Assert(t, err == nil)
tests.Assert(t, strings.Contains(s, "empty string"))

// Make a request where the cluster id does not exist
request = []byte(`{
"cluster" : "123",
Expand Down

0 comments on commit 4fe2463

Please sign in to comment.