diff --git a/observatory_test.go b/observatory_test.go index fa897141d04..16c2a70231e 100644 --- a/observatory_test.go +++ b/observatory_test.go @@ -224,7 +224,7 @@ func TestObservatoryPageTrend(t *testing.T) { } `) } - mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+testURL+"/trend", handler) + mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+escapedTestURL+"/trend", handler) want := ObservatoryPageTrend{ PerformanceScore: []*int{nil, IntPtr(100)}, TTFB: []*int{nil, IntPtr(10)}, @@ -268,7 +268,7 @@ func TestListObservatoryPageTests(t *testing.T) { } `, pageTestJSON) } - mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+testURL+"/tests", handler) + mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+escapedTestURL+"/tests", handler) want := []ObservatoryPageTest{ pageTest, } @@ -304,7 +304,7 @@ func TestCreateObservatoryPageTest(t *testing.T) { } `, pageTestJSON) } - mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+testURL+"/tests", handler) + mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+escapedTestURL+"/tests", handler) want := pageTest test, err := client.CreateObservatoryPageTest(context.Background(), ZoneIdentifier(testZoneID), CreateObservatoryPageTestParams{ URL: testURL, @@ -336,7 +336,7 @@ func TestDeleteObservatoryPageTests(t *testing.T) { } `) } - mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+testURL+"/tests", handler) + mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+escapedTestURL+"/tests", handler) want := 2 count, err := client.DeleteObservatoryPageTests(context.Background(), ZoneIdentifier(testZoneID), DeleteObservatoryPageTestsParams{ URL: testURL, @@ -364,7 +364,7 @@ func TestGetObservatoryPageTest(t *testing.T) { } `, pageTestJSON) } - mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+testURL+"/tests/"+observatoryTestID, handler) + mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+escapedTestURL+"/tests/"+observatoryTestID, handler) want := pageTest test, err := client.GetObservatoryPageTest(context.Background(), ZoneIdentifier(testZoneID), GetObservatoryPageTestParams{ TestID: observatoryTestID, @@ -393,7 +393,7 @@ func TestCreateObservatoryScheduledPageTest(t *testing.T) { } `, scheduledPageTestJSON) } - mux.HandleFunc("/zones/"+testZoneID+"/speed_api/schedule/"+testURL, handler) + mux.HandleFunc("/zones/"+testZoneID+"/speed_api/schedule/"+escapedTestURL, handler) want := scheduledPageTest pages, err := client.CreateObservatoryScheduledPageTest(context.Background(), ZoneIdentifier(testZoneID), CreateObservatoryScheduledPageTestParams{ Frequency: frequency, @@ -422,7 +422,7 @@ func TestObservatoryScheduledPageTest(t *testing.T) { } `, scheduleJSON) } - mux.HandleFunc("/zones/"+testZoneID+"/speed_api/schedule/"+testURL, handler) + mux.HandleFunc("/zones/"+testZoneID+"/speed_api/schedule/"+escapedTestURL, handler) want := schedule schedule, err := client.GetObservatoryScheduledPageTest(context.Background(), ZoneIdentifier(testZoneID), GetObservatoryScheduledPageTestParams{ URL: testURL, @@ -446,13 +446,13 @@ func TestDeleteObservatoryScheduledPageTest(t *testing.T) { "success": true, "errors": [], "messages": [], - "result": { + "result": { "count": 2 } } `) } - mux.HandleFunc("/zones/"+testZoneID+"/speed_api/schedule/"+testURL, handler) + mux.HandleFunc("/zones/"+testZoneID+"/speed_api/schedule/"+escapedTestURL, handler) want := 2 count, err := client.DeleteObservatoryScheduledPageTest(context.Background(), ZoneIdentifier(testZoneID), DeleteObservatoryScheduledPageTestParams{ URL: testURL, diff --git a/pages_project.go b/pages_project.go index 202846158a6..34efdc73c24 100644 --- a/pages_project.go +++ b/pages_project.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "net/url" "time" "github.com/goccy/go-json" @@ -254,7 +255,7 @@ func (api *API) GetPagesProject(ctx context.Context, rc *ResourceContainer, proj return PagesProject{}, ErrMissingAccountID } - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", rc.Identifier, projectName) + uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", rc.Identifier, url.PathEscape(projectName)) res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) if err != nil { return PagesProject{}, err @@ -299,7 +300,7 @@ func (api *API) UpdatePagesProject(ctx context.Context, rc *ResourceContainer, p return PagesProject{}, ErrMissingIdentifier } - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", rc.Identifier, params.ID) + uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", rc.Identifier, url.PathEscape(params.ID)) res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params) if err != nil { return PagesProject{}, err @@ -319,7 +320,7 @@ func (api *API) DeletePagesProject(ctx context.Context, rc *ResourceContainer, p if rc.Identifier == "" { return ErrMissingAccountID } - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", rc.Identifier, projectName) + uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", rc.Identifier, url.PathEscape(projectName)) res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) if err != nil { return err diff --git a/pages_project_test.go b/pages_project_test.go index 49861c06944..88cb7c6709e 100644 --- a/pages_project_test.go +++ b/pages_project_test.go @@ -554,7 +554,7 @@ func TestPagesProject(t *testing.T) { }`, testPagesProjectResponse) } - mux.HandleFunc("/accounts/"+testAccountID+"/pages/projects/Test Pages Project", handler) + mux.HandleFunc("/accounts/"+testAccountID+"/pages/projects/Test%20Pages%20Project", handler) _, err := client.GetPagesProject(context.Background(), AccountIdentifier(""), "Test Pages Project") if assert.Error(t, err) { @@ -631,7 +631,7 @@ func TestUpdatePagesProject(t *testing.T) { }`, testPagesProjectResponse) } - mux.HandleFunc("/accounts/"+testAccountID+"/pages/projects/Test Pages Project", handler) + mux.HandleFunc("/accounts/"+testAccountID+"/pages/projects/Test%20Pages%20Project", handler) _, err := client.UpdatePagesProject(context.Background(), AccountIdentifier(""), *updateAttributes) if assert.Error(t, err) { @@ -659,7 +659,7 @@ func TestDeletePagesProject(t *testing.T) { }`) } - mux.HandleFunc("/accounts/"+testAccountID+"/pages/projects/Test Pages Project", handler) + mux.HandleFunc("/accounts/"+testAccountID+"/pages/projects/Test%20Pages%20Project", handler) err := client.DeletePagesProject(context.Background(), AccountIdentifier(""), "Test Pages Project") if assert.Error(t, err) { diff --git a/tunnel_routes_test.go b/tunnel_routes_test.go index b9583bd115d..17a91f4f806 100644 --- a/tunnel_routes_test.go +++ b/tunnel_routes_test.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "net/http" + "net/url" "testing" "time" @@ -82,7 +83,7 @@ func TestTunnelRouteForIP(t *testing.T) { }`) } - mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/ip/10.1.0.137", handler) + mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/ip/"+url.PathEscape("10.1.0.137"), handler) ts, _ := time.Parse(time.RFC3339Nano, "2021-01-25T18:22:34.317854Z") want := TunnelRoute{ @@ -125,7 +126,7 @@ func TestCreateTunnelRoute(t *testing.T) { }`) } - mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/network/10.0.0.0/16", handler) + mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/network/"+url.PathEscape("10.0.0.0/16"), handler) ts, _ := time.Parse(time.RFC3339Nano, "2021-01-25T18:22:34.317854Z") want := TunnelRoute{ @@ -184,7 +185,7 @@ func TestUpdateTunnelRoute(t *testing.T) { VirtualNetworkID: "9f322de4-5988-4945-b770-f1d6ac200f86", } - mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/network/10.0.0.0/16", handler) + mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/network/"+url.PathEscape("10.0.0.0/16"), handler) tunnel, err := client.UpdateTunnelRoute(context.Background(), AccountIdentifier(testAccountID), TunnelRoutesUpdateParams{TunnelID: testTunnelID, Network: "10.0.0.0/16", Comment: "foo", VirtualNetworkID: "9f322de4-5988-4945-b770-f1d6ac200f86"}) if assert.NoError(t, err) { @@ -216,7 +217,7 @@ func TestDeleteTunnelRoute(t *testing.T) { }`) } - mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/network/10.0.0.0/16", handler) + mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/network/"+url.PathEscape("10.0.0.0/16"), handler) err := client.DeleteTunnelRoute(context.Background(), AccountIdentifier(testAccountID), TunnelRoutesDeleteParams{Network: "10.0.0.0/16", VirtualNetworkID: "9f322de4-5988-4945-b770-f1d6ac200f86"}) assert.NoError(t, err) }