2016-09-26 18:48:55 +00:00
|
|
|
package service
|
2016-09-04 19:43:12 +00:00
|
|
|
|
|
|
|
import (
|
2016-09-16 04:35:52 +00:00
|
|
|
"fmt"
|
2016-09-04 19:43:12 +00:00
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2016-09-26 18:48:55 +00:00
|
|
|
"github.com/kolide/kolide-ose/server/datastore"
|
2016-09-04 19:43:12 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-09-05 19:53:55 +00:00
|
|
|
"golang.org/x/net/context"
|
2016-09-04 19:43:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPIRoutes(t *testing.T) {
|
2016-10-19 14:46:33 +00:00
|
|
|
ds, err := datastore.New("inmem", "")
|
2016-09-04 19:43:12 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2016-09-21 03:08:11 +00:00
|
|
|
svc, err := newTestService(ds)
|
2016-09-04 19:43:12 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
r := mux.NewRouter()
|
2016-09-26 17:14:39 +00:00
|
|
|
ke := MakeKolideServerEndpoints(svc, "CHANGEME")
|
|
|
|
kh := makeKolideKitHandlers(ctx, ke, nil)
|
|
|
|
attachKolideAPIRoutes(r, kh)
|
2016-09-04 19:43:12 +00:00
|
|
|
handler := mux.NewRouter()
|
2016-09-29 04:21:39 +00:00
|
|
|
handler.PathPrefix("/").Handler(r)
|
2016-09-04 19:43:12 +00:00
|
|
|
|
|
|
|
var routes = []struct {
|
|
|
|
verb string
|
|
|
|
uri string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/kolide/users",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "GET",
|
2016-09-15 14:52:17 +00:00
|
|
|
uri: "/api/v1/kolide/users",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/users/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "PATCH",
|
2016-09-04 19:43:12 +00:00
|
|
|
uri: "/api/v1/kolide/users/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
2016-09-15 14:52:17 +00:00
|
|
|
uri: "/api/v1/kolide/login",
|
2016-09-04 19:43:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
2016-09-15 14:52:17 +00:00
|
|
|
uri: "/api/v1/kolide/forgot_password",
|
2016-09-04 19:43:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
2016-09-15 14:52:17 +00:00
|
|
|
uri: "/api/v1/kolide/reset_password",
|
2016-09-04 19:43:12 +00:00
|
|
|
},
|
2016-09-16 04:35:52 +00:00
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/me",
|
|
|
|
},
|
2016-09-22 00:45:57 +00:00
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/config",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "PATCH",
|
|
|
|
uri: "/api/v1/kolide/config",
|
|
|
|
},
|
2016-09-29 02:44:05 +00:00
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/invites",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/kolide/invites",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "DELETE",
|
|
|
|
uri: "/api/v1/kolide/invites/1",
|
|
|
|
},
|
2016-09-04 19:43:12 +00:00
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/queries/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/queries",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/kolide/queries",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "PATCH",
|
|
|
|
uri: "/api/v1/kolide/queries/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "DELETE",
|
|
|
|
uri: "/api/v1/kolide/queries/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/packs/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/packs",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/kolide/packs",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "PATCH",
|
|
|
|
uri: "/api/v1/kolide/packs/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "DELETE",
|
|
|
|
uri: "/api/v1/kolide/packs/1",
|
|
|
|
},
|
|
|
|
{
|
2016-09-26 17:14:39 +00:00
|
|
|
verb: "POST",
|
2016-09-04 19:43:12 +00:00
|
|
|
uri: "/api/v1/kolide/packs/1/queries/2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/packs/1/queries",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "DELETE",
|
|
|
|
uri: "/api/v1/kolide/packs/1/queries/2",
|
|
|
|
},
|
2016-09-29 04:21:39 +00:00
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/osquery/enroll",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/osquery/config",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/osquery/distributed/read",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/osquery/distributed/write",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/osquery/log",
|
|
|
|
},
|
2016-10-03 03:14:35 +00:00
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/labels/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/labels",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/kolide/labels",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "PATCH",
|
|
|
|
uri: "/api/v1/kolide/labels/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "DELETE",
|
|
|
|
uri: "/api/v1/kolide/labels/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/kolide/packs/1/labels/2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/packs/1/labels",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "DELETE",
|
|
|
|
uri: "/api/v1/kolide/packs/1/labels/2",
|
|
|
|
},
|
2016-10-06 00:10:44 +00:00
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/hosts/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/hosts",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "DELETE",
|
|
|
|
uri: "/api/v1/kolide/hosts/1",
|
|
|
|
},
|
2016-09-04 19:43:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, route := range routes {
|
2016-09-16 04:35:52 +00:00
|
|
|
t.Run(fmt.Sprintf(": %v", route.uri), func(st *testing.T) {
|
|
|
|
recorder := httptest.NewRecorder()
|
|
|
|
handler.ServeHTTP(
|
|
|
|
recorder,
|
|
|
|
httptest.NewRequest(route.verb, route.uri, nil),
|
|
|
|
)
|
|
|
|
assert.NotEqual(st, 404, recorder.Code)
|
|
|
|
})
|
2016-09-04 19:43:12 +00:00
|
|
|
}
|
|
|
|
}
|