func TestAuthenticateFailure(t *testing.T) {
	method := "GET"
	path := root + "/authenticate/failure"
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{method: method, path: path}
	want := &wanted{code: http.StatusUnauthorized, success: false}
	makeRequest(t, app, params, want)
}
func TestSessionGetSuccessCreateEmpty(t *testing.T) {
	method := "GET"
	path := root + "/session-get"
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{method: method, path: path}
	want := &wanted{code: http.StatusOK, success: true}
	makeRequest(t, app, params, want)
}
func TestMethodNotAllowed(t *testing.T) {
	method := "OPTIONS"
	path := root
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{method: method, path: path}
	want := &wanted{code: http.StatusMethodNotAllowed, success: false}
	makeRequest(t, app, params, want)
}
func TestServerError(t *testing.T) {
	method := "GET"
	path := root + "/server-error"
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{method: method, path: path}
	want := &wanted{code: http.StatusInternalServerError, success: false}
	makeRequest(t, app, params, want)
}
func TestNotFound(t *testing.T) {
	method := "GET"
	path := root + "/not-found"
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{method: method, path: path}
	want := &wanted{code: http.StatusNotFound, success: false}
	makeRequest(t, app, params, want)
}
func TestCSRFFailureBodyNil(t *testing.T) {
	method := "GET"
	path := root + "/csrf"
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{method: method, path: path}
	want := &wanted{code: http.StatusBadRequest, success: false}
	makeRequest(t, app, params, want)
}
func TestAuthenticateSuccess(t *testing.T) {
	method := "GET"
	path := root + "/authenticate/success"
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{method: method, path: path}
	want := &wanted{code: http.StatusOK, success: true}
	makeRequest(t, app, params, want)
}
func TestSessionSetUpdateError(t *testing.T) {
	method := "GET"
	path := root + "/session-set"
	auth := sessionIDWithUpdateError
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{auth: auth, method: method, path: path}
	want := &wanted{code: http.StatusInternalServerError, success: false}
	makeRequest(t, app, params, want)
}
func TestSessionSetSuccess(t *testing.T) {
	method := "GET"
	path := root + "/session-set"
	auth := sessionIDExistent
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{auth: auth, method: method, path: path}
	want := &wanted{code: http.StatusOK, success: true}
	makeRequest(t, app, params, want)
}
func TestSessionGetSuccessCreateErrorWithDeleteError(t *testing.T) {
	method := "GET"
	path := root + "/session-get/create-error"
	auth := sessionIDWithDeleteError
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{auth: auth, method: method, path: path}
	want := &wanted{code: http.StatusOK, success: true}
	makeRequest(t, app, params, want)
}
func TestCSRFSuccess(t *testing.T) {
	method := "GET"
	path := root + "/csrf"
	body := []byte(fmt.Sprintf("{\"sessionid\": \"%s\"}", sessionIDExistent))
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{body: body, method: method, path: path}
	want := &wanted{code: http.StatusOK, success: true}
	makeRequest(t, app, params, want)
}
func TestCSRFFailureWrongSessionID(t *testing.T) {
	method := "GET"
	path := root + "/csrf"
	body := []byte(fmt.Sprintf("{\"sessionid\": \"WRONG-SESSION-ID\"}"))
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{body: body, method: method, path: path}
	want := &wanted{code: http.StatusBadRequest, success: false}
	makeRequest(t, app, params, want)
}
func TestBodyParserSuccess(t *testing.T) {
	method := "POST"
	path := root + "/body-parser/success"
	body := []byte(arbitraryJSON)
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{body: body, method: method, path: path}
	want := &wanted{code: http.StatusOK, success: true}
	makeRequest(t, app, params, want)
}
func TestBodyParserFailureNoInit(t *testing.T) {
	method := "POST"
	path := root + "/body-parser/failure/no-init"
	body := []byte(arbitraryJSON)
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{body: body, method: method, path: path}
	want := &wanted{code: http.StatusInternalServerError, success: false}
	makeRequest(t, app, params, want)
}
func TestBodyParserFailureBadInput(t *testing.T) {
	method := "POST"
	path := root + "/body-parser/success"
	body := []byte("{BAD JSON}")
	app := forest.New("")
	app.RegisterRoute(root, newRouter(app))
	params := &requested{body: body, method: method, path: path}
	want := &wanted{code: http.StatusBadRequest, success: false}
	makeRequest(t, app, params, want)
}
func TestSafeErrorFilter(t *testing.T) {
	method := "GET"
	app := forest.New("")
	app.SafeErrorFilter = func(err error) error {
		if err.Error() == customSafeErrorMessage {
			return err
		} else {
			return nil
		}
	}
	app.RegisterRoute(root, newRouter(app))
	// test safe errors via custom filter
	path := root + "/safe-error/success"
	params := &requested{method: method, path: path}
	want := &wanted{code: http.StatusInternalServerError, success: false}
	_, forestResponse := makeRequest(t, app, params, want)
	if forestResponse.Message != customSafeErrorMessage {
		t.Errorf("%s %s should return message: %s",
			method, path, customSafeErrorMessage)
	}
	// test unsafe errors not passing through custom filter
	path = root + "/safe-error/failure"
	params = &requested{method: method, path: path}
	want = &wanted{code: http.StatusInternalServerError, success: false}
	_, forestResponse = makeRequest(t, app, params, want)
	if forestResponse.Message == customUnsafeErrorMessage {
		t.Errorf("%s %s should NOT return unsafe message: %s",
			method, path, customUnsafeErrorMessage)
	}
	// test unsafe errors passing through if app.Config.Debug is true
	app.Config.Debug = true
	path = root + "/safe-error/failure"
	params = &requested{method: method, path: path}
	want = &wanted{code: http.StatusInternalServerError, success: false}
	_, forestResponse = makeRequest(t, app, params, want)
	if forestResponse.Message != customUnsafeErrorMessage {
		t.Errorf("%s %s should return unsafe message if %s is true: %s",
			method, path, "app.Config.Debug", customUnsafeErrorMessage)
	}
}