Skip to content

Commit

Permalink
travis
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Mar 29, 2020
1 parent 30d70cb commit ff887d9
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 107 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# 0.90.19
- Fixed private Services from showing in API (/api/services and /api/services/{id})
- Removed unused code

# 0.90.18
- Added service type gRPC, you can now check on gRPC services. (limited)
-

# 0.90.17
- Fixed notification fields for frontend
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/forms/Service.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@
delete s.online_24_hours
s.check_interval = parseInt(s.check_interval)
window.console.log(s)
if (s.id) {
await this.updateService(s)
} else {
Expand Down
27 changes: 22 additions & 5 deletions handlers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import (
"testing"
)

const (
serverDomain = "http://localhost:18888"
)

var (
dir string
)
Expand Down Expand Up @@ -180,13 +176,14 @@ func TestMainApiRoutes(t *testing.T) {
// Name: "Prometheus Export Metrics",
// URL: "/metrics",
// Method: "GET",
// BeforeTest: SetTestENV,
// ExpectedStatus: 200,
// ExpectedContains: []string{
// `Statping Totals`,
// `total_failures`,
// `Golang Metrics`,
// },
//}
//},
}

for _, v := range tests {
Expand All @@ -198,6 +195,26 @@ func TestMainApiRoutes(t *testing.T) {
}
}

//func TestExportSettings(t *testing.T) {
// data, err := ExportSettings()
// require.Nil(t, err)
// assert.Len(t, data, 50)
//
// var exportData ExportData
// err = json.Unmarshal(data, &exportData)
// require.Nil(t, err)
//
// assert.Len(t, exportData.Services, 4)
// assert.Len(t, exportData.Messages, 4)
// assert.Len(t, exportData.Checkins, 2)
// assert.Len(t, exportData.Groups, 1)
//
// assert.Equal(t, "Updated Core", exportData.Core.Name)
// assert.True(t, exportData.Core.Setup)
// assert.NotEmpty(t, exportData.Core.ApiKey)
// assert.NotEmpty(t, exportData.Core.ApiSecret)
//}

type HttpFuncTest func(*testing.T) error

// HTTPTest contains all the parameters for a HTTP Unit Test
Expand Down
2 changes: 1 addition & 1 deletion handlers/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func removeJwtToken(w http.ResponseWriter) {
http.SetCookie(w, &http.Cookie{
Name: cookieKey,
Value: "",
Expires: time.Now().UTC(),
Expires: utils.Now(),
})
}

Expand Down
47 changes: 0 additions & 47 deletions handlers/errors.go

This file was deleted.

46 changes: 0 additions & 46 deletions handlers/function.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handlers

import (
"encoding/json"
"github.com/statping/statping/source"
"github.com/statping/statping/types/core"
"github.com/statping/statping/utils"
Expand All @@ -14,56 +13,11 @@ var (
basePath = "/"
)

type CustomResponseWriter struct {
body []byte
statusCode int
header http.Header
}

func NewCustomResponseWriter() *CustomResponseWriter {
return &CustomResponseWriter{
header: http.Header{},
}
}

func (w *CustomResponseWriter) Header() http.Header {
return w.header
}

func (w *CustomResponseWriter) Write(b []byte) (int, error) {
w.body = b
// implement it as per your requirement
return 0, nil
}

func (w *CustomResponseWriter) WriteHeader(statusCode int) {
w.statusCode = statusCode
}

func parseForm(r *http.Request) url.Values {
r.ParseForm()
return r.PostForm
}

func parseGet(r *http.Request) url.Values {
r.ParseForm()
return r.Form
}

func decodeRequest(r *http.Request, object interface{}) error {
decoder := json.NewDecoder(r.Body)
defer r.Body.Close()
return decoder.Decode(&object)
}

type parsedObject struct {
Error Error
}

func serviceFromID(r *http.Request, object interface{}) error {
return nil
}

var handlerFuncs = func(w http.ResponseWriter, r *http.Request) template.FuncMap {
return template.FuncMap{
"VERSION": func() string {
Expand Down
5 changes: 4 additions & 1 deletion handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,13 @@ func IsUser(r *http.Request) bool {
if os.Getenv("GO_ENV") == "test" {
return true
}
_, err := getJwtToken(r)
tk, err := getJwtToken(r)
if err != nil {
return false
}
if err := tk.Valid(); err != nil {
return false
}
return true
}

Expand Down
5 changes: 5 additions & 0 deletions handlers/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func sendLog(next http.Handler) http.Handler {
func scoped(handler func(r *http.Request) interface{}) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
data := handler(r)
err, ok := data.(error)
if ok {
sendErrorJson(err, w, r)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(scope{data: data, scope: ScopeName(r)})
})
Expand Down
16 changes: 15 additions & 1 deletion handlers/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package handlers

import (
"fmt"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/statping/statping/database"
Expand Down Expand Up @@ -66,6 +67,10 @@ func apiServiceHandler(r *http.Request) interface{} {
if err != nil {
return err
}
user := IsUser(r)
if !srv.Public.Bool && !user {
return errors.New("not authenticated")
}
srv = srv.UpdateStats()
return *srv
}
Expand Down Expand Up @@ -203,7 +208,16 @@ func apiServiceDeleteHandler(w http.ResponseWriter, r *http.Request) {
}

func apiAllServicesHandler(r *http.Request) interface{} {
return services.AllInOrder()
user := IsUser(r)
fmt.Println("user: ", user)
var srvs []services.Service
for _, v := range services.AllInOrder() {
if !v.Public.Bool && !user {
continue
}
srvs = append(srvs, v)
}
return srvs
}

func servicesDeleteFailuresHandler(w http.ResponseWriter, r *http.Request) {
Expand Down
9 changes: 5 additions & 4 deletions handlers/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestApiServiceRoutes(t *testing.T) {
Method: "GET",
ExpectedContains: []string{`"name":"Google"`},
ExpectedStatus: 200,
ResponseLen: 5,
ResponseLen: 4,
BeforeTest: UnsetTestENV,
FuncTest: func(t *testing.T) error {
count := len(services.Services())
Expand All @@ -55,14 +55,15 @@ func TestApiServiceRoutes(t *testing.T) {
Method: "GET",
ExpectedContains: []string{`"name":"Google"`},
ExpectedStatus: 200,
BeforeTest: UnsetTestENV,
},
{
Name: "Statping Private Service 1",
URL: "/api/services/1",
URL: "/api/services/2",
Method: "GET",
ExpectedContains: []string{`"name":"Google"`},
ExpectedContains: []string{`"error":"not authenticated"`},
ExpectedStatus: 200,
BeforeTest: SetTestENV,
BeforeTest: UnsetTestENV,
},
{
Name: "Statping Service 1 with Private responses",
Expand Down
2 changes: 2 additions & 0 deletions types/services/samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func Samples() error {
Timeout: 10,
Order: 1,
GroupId: 1,
Public: null.NewNullBool(true),
Permalink: null.NewNullString("google"),
VerifySSL: null.NewNullBool(true),
NotifyAfter: 3,
Expand All @@ -36,6 +37,7 @@ func Samples() error {
Method: "GET",
Timeout: 20,
Order: 2,
Public: null.NewNullBool(false),
Permalink: null.NewNullString("statping_github"),
VerifySSL: null.NewNullBool(true),
NotifyAfter: 1,
Expand Down
6 changes: 6 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func TestSaveFile(t *testing.T) {
assert.Nil(t, SaveFile(Directory+"/test.txt", []byte("testing saving a file")))
}

func TestOpenFile(t *testing.T) {
f, err := OpenFile(Directory + "/test.txt")
require.Nil(t, err)
assert.Equal(t, "testing saving a file", f)
}

func TestFileExists(t *testing.T) {
assert.True(t, FileExists(Directory+"/test.txt"))
assert.False(t, FileExists(Directory+"fake.txt"))
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.90.18
0.90.19

0 comments on commit ff887d9

Please sign in to comment.