make orbit and device ping paths unversioned (#7933)

This commit is contained in:
Roberto Dip 2022-09-26 14:39:56 -03:00 committed by GitHub
parent 84903deffb
commit b9927eade4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 9 deletions

View file

@ -307,7 +307,7 @@ type Service interface {
// ListDevicePolicies lists all policies for the given host, including passing / failing summaries
ListDevicePolicies(ctx context.Context, host *Host) ([]*HostPolicy, error)
// DisableAuthForPing is used by the /orbit_ping and /device_ping endpoints
// DisableAuthForPing is used by the /orbit/ping and /device/ping endpoints
// to bypass authentication, as they are public
DisableAuthForPing(ctx context.Context)

View file

@ -4,6 +4,7 @@ import (
"bytes"
"io"
"net/http"
"strings"
"testing"
"github.com/fleetdm/fleet/v4/server/fleet"
@ -131,7 +132,7 @@ func TestClientCapabilities(t *testing.T) {
var req http.Request
bc.setClientCapabilitiesHeader(&req)
require.Equal(t, c.expected, req.Header.Get(fleet.CapabilitiesHeader))
require.ElementsMatch(t, strings.Split(c.expected, ","), strings.Split(req.Header.Get(fleet.CapabilitiesHeader), ","))
})
}
}

View file

@ -506,11 +506,11 @@ func attachFleetAPIRoutes(r *mux.Router, svc fleet.Service, config config.FleetC
ne.WithCustomMiddleware(
errorLimiter.Limit("ping_device", desktopQuota),
).HEAD("/api/_version_/fleet/device_ping", devicePingEndpoint, devicePingRequest{})
).HEAD("/api/fleet/device/ping", devicePingEndpoint, devicePingRequest{})
ne.WithCustomMiddleware(
errorLimiter.Limit("ping_orbit", desktopQuota),
).HEAD("/api/_version_/fleet/orbit_ping", orbitPingEndpoint, orbitPingRequest{})
).HEAD("/api/fleet/orbit/ping", orbitPingEndpoint, orbitPingRequest{})
}

View file

@ -5569,13 +5569,13 @@ func (s *integrationTestSuite) TestOSVersions() {
}
func (s *integrationTestSuite) TestPingEndpoints() {
s.DoRaw("HEAD", "/api/latest/fleet/orbit_ping", nil, http.StatusOK)
s.DoRaw("HEAD", "/api/fleet/orbit/ping", nil, http.StatusOK)
// unauthenticated works too
s.DoRawNoAuth("HEAD", "/api/latest/fleet/orbit_ping", nil, http.StatusOK)
s.DoRawNoAuth("HEAD", "/api/fleet/orbit/ping", nil, http.StatusOK)
s.DoRaw("HEAD", "/api/latest/fleet/device_ping", nil, http.StatusOK)
s.DoRaw("HEAD", "/api/fleet/device/ping", nil, http.StatusOK)
// unauthenticated works too
s.DoRawNoAuth("HEAD", "/api/latest/fleet/device_ping", nil, http.StatusOK)
s.DoRawNoAuth("HEAD", "/api/fleet/device/ping", nil, http.StatusOK)
}
// this test can be deleted once the "v1" version is removed.

View file

@ -81,7 +81,7 @@ func (oc *OrbitClient) GetConfig(orbitNodeKey string) (json.RawMessage, error) {
}
func (oc *OrbitClient) Ping() error {
verb, path := "HEAD", "/api/latest/fleet/orbit_ping"
verb, path := "HEAD", "/api/fleet/orbit/ping"
err := oc.request(verb, path, nil, nil)
if err == nil || errors.Is(err, notFoundErr{}) {