2016-09-05 20:03:58 +00:00
|
|
|
package server
|
2016-09-04 19:43:12 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
2016-09-14 16:11:06 +00:00
|
|
|
kitlog "github.com/go-kit/kit/log"
|
2016-09-04 19:43:12 +00:00
|
|
|
"github.com/gorilla/mux"
|
2016-09-14 16:11:06 +00:00
|
|
|
"github.com/kolide/kolide-ose/config"
|
2016-09-04 19:43:12 +00:00
|
|
|
"github.com/kolide/kolide-ose/datastore"
|
|
|
|
"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) {
|
|
|
|
ds, err := datastore.New("gorm-sqlite3", ":memory:")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2016-09-14 16:11:06 +00:00
|
|
|
svc, err := NewService(ds, kitlog.NewNopLogger(), config.TestConfig())
|
2016-09-04 19:43:12 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
|
attachAPIRoutes(r, ctx, svc, nil)
|
|
|
|
handler := mux.NewRouter()
|
|
|
|
handler.PathPrefix("/api/v1/kolide").Handler(r)
|
|
|
|
|
|
|
|
var routes = []struct {
|
|
|
|
verb string
|
|
|
|
uri string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/kolide/users",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
uri: "/api/v1/kolide/users/1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/kolide/users/1/password",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/kolide/users/1/role",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "POST",
|
|
|
|
uri: "/api/v1/kolide/users/1/status",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
verb: "GET",
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, route := range routes {
|
|
|
|
recorder := httptest.NewRecorder()
|
|
|
|
handler.ServeHTTP(
|
|
|
|
recorder,
|
|
|
|
httptest.NewRequest(route.verb, route.uri, nil),
|
|
|
|
)
|
|
|
|
assert.NotEqual(t, 404, recorder.Code)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|