Skip to content

Commit

Permalink
fix(be): ignore host 0.0.0.0 in api router
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Oct 2, 2020
1 parent 78b298c commit c12c490
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,38 @@ package api

import (
"log"
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/ansible-semaphore/semaphore/util"
"github.com/go-openapi/loads"
"github.com/go-openapi/spec"
)

func mockParam(w http.ResponseWriter, r *http.Request) {
_, err := util.GetIntParam("test_id", w, r)
if err != nil {
return
}

w.WriteHeader(200)
}

func TestApiPing(t *testing.T) {
req, _ := http.NewRequest("GET", "/api/ping", nil)
rr := httptest.NewRecorder()

r := Route()

r.ServeHTTP(rr, req)

if rr.Code != 200 {
t.Errorf("Response code should be 200 %d", rr.Code)
}
}

// TestApi Validates the api description in the root meets the swagger/openapi spec
func TestApiSchemaValidation(t *testing.T) {
dir, err := os.Getwd()
Expand Down
2 changes: 1 addition & 1 deletion api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Route() *mux.Router {
r.NotFoundHandler = http.HandlerFunc(servePublic)

webPath := "/"
if util.WebHostURL != nil {
if util.WebHostURL != nil && util.WebHostURL.Hostname() != "0.0.0.0" {
r.Host(util.WebHostURL.Hostname())
webPath = util.WebHostURL.Path
}
Expand Down

0 comments on commit c12c490

Please sign in to comment.