Skip to content

Commit

Permalink
fix(web/acl): get upstream data from JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
nettoclaudio committed Feb 22, 2022
1 parent 68f8a4e commit 390cf14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
10 changes: 2 additions & 8 deletions internal/web/upstreams.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package web

import (
"net/http"
"strconv"

"github.com/labstack/echo/v4"
"github.com/tsuru/rpaas-operator/api/v1alpha1"
Expand Down Expand Up @@ -54,16 +53,11 @@ func deleteUpstream(c echo.Context) error {
return err
}

port, err := strconv.Atoi(c.QueryParam("port"))
if err != nil {
var upstream v1alpha1.AllowedUpstream
if err = c.Bind(&upstream); err != nil {
return err
}

upstream := v1alpha1.AllowedUpstream{
Host: c.QueryParam("host"),
Port: port,
}

if err := manager.DeleteUpstream(ctx, c.Param("instance"), upstream); err != nil {
return err
}
Expand Down
21 changes: 7 additions & 14 deletions internal/web/upstreams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,19 @@ func TestRemoveAccessControlList(t *testing.T) {
tests := []struct {
name string
instance string
args string
body string
expectedCode int
expectedBody string
manager rpaas.RpaasManager
}{
{
name: "remove upstream",
instance: "valid",
args: "host=host1&port=8888",
name: "remove upstream (www.example.com:443)",
instance: "my-instance",
body: `{"host": "www.example.com", "port": 443}`,
expectedCode: http.StatusNoContent,
expectedBody: "",
manager: &fake.RpaasManager{
FakeDeleteUpstream: func(instanceName string, upstream v1alpha1.AllowedUpstream) error {
expectedUpstream := v1alpha1.AllowedUpstream{Host: "host1", Port: 8888}
assert.Equal(t, expectedUpstream, upstream)
assert.Equal(t, v1alpha1.AllowedUpstream{Host: "www.example.com", Port: 443}, upstream)
return nil
},
},
Expand All @@ -131,14 +129,9 @@ func TestRemoveAccessControlList(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
srv := newTestingServer(t, tt.manager)
defer srv.Close()

path := fmt.Sprintf("%s/resources/%s/acl", srv.URL, tt.instance)
if tt.args != "" {
path = fmt.Sprintf("%s?%s", path, tt.args)
}
request, err := http.NewRequest(http.MethodDelete, path, nil)
request, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/resources/%s/acl", srv.URL, tt.instance), strings.NewReader(tt.body))
assert.NoError(t, err)

request.Header.Set("Content-Type", "application/json")
rsp, err := srv.Client().Do(request)
assert.NoError(t, err)
assert.Equal(t, tt.expectedCode, rsp.StatusCode)
Expand Down

0 comments on commit 390cf14

Please sign in to comment.