Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Fix an issue with environment names not being encoded #1869

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion protected_environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (s *ProtectedEnvironmentsService) UpdateProtectedEnvironments(pid interface
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/protected_environments/%s", PathEscape(project), environment)
u := fmt.Sprintf("projects/%s/protected_environments/%s", PathEscape(project), PathEscape(environment))

req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions protected_environments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,30 @@ func TestUpdateProtectedEnvironments(t *testing.T) {
assert.Equal(t, expected, environment)
}

func TestUpdateRepositoryEnvironmentsEscapesURL(t *testing.T) {
mux, client := setup(t)

rawRequest := ""

// Use a "/" in the environment name, so it needs encoding
// Note: Mux requires the path to be unencoded for some reason. Using %2F will never intercept the request.
mux.HandleFunc("/api/v4/projects/1/protected_environments/test/environment", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)

// Store the raw request so we're sure it's encoded properly
rawRequest = r.URL.RawPath

fmt.Fprintf(w, `{
"name": "test/environment"
}`)
})

_, resp, err := client.ProtectedEnvironments.UpdateProtectedEnvironments(1, "test/environment", &UpdateProtectedEnvironmentsOptions{})
assert.NoError(t, err, "failed to get response")
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, rawRequest, "/api/v4/projects/1/protected_environments/test%2Fenvironment")
}

func TestUnprotectRepositoryEnvironments(t *testing.T) {
mux, client := setup(t)

Expand Down
Loading