url.PathEscape resource ids in the sdk before sending building a request. (#2035)
This commit is contained in:
29 files changed
+199
-87
No files matched your search
@@ -285,10 +285,19 @@ func TestErrors(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.NotNil(u)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = accountClient.Read(tc.Context(), fmt.Sprintf("%s/../", u.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = accountClient.Update(tc.Context(), u.Item.Id, 73, accounts.WithName("anything"))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package authmethods_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
@@ -319,10 +320,19 @@ func TestErrors(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.NotNil(u)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = amClient.Read(tc.Context(), fmt.Sprintf("%s/../", u.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = amClient.Update(tc.Context(), u.Item.Id, 73, authmethods.WithName("anything"))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
|
||||
|
||||
@@ -137,7 +137,6 @@ func TestCrud(t *testing.T) {
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
}
|
||||
|
||||
// TODO: Get better coverage for expected errors and error formats.
|
||||
func TestErrors(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
tc := controller.NewTestController(t, nil)
|
||||
@@ -163,10 +162,19 @@ func TestErrors(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.NotNil(l)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = lClient.Read(tc.Context(), fmt.Sprintf("%s/../", l.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = lClient.Update(tc.Context(), l.Item.Id, 73, credentiallibraries.WithName("anything"))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
|
||||
|
||||
@@ -149,9 +149,16 @@ func TestErrors(t *testing.T) {
|
||||
vs, err := c.Create(tc.Context(), "vault", proj.GetPublicId(), credentialstores.WithName("foo"),
|
||||
credentialstores.WithVaultCredentialStoreAddress(vaultServ.Addr), credentialstores.WithVaultCredentialStoreToken(vaultTok))
|
||||
require.NoError(err)
|
||||
require.NotNil(vs)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = c.Read(tc.Context(), fmt.Sprintf("%s/../", vs.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.NotNil(vs)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = c.Update(tc.Context(), vs.Item.Id, 73, credentialstores.WithName("anything"))
|
||||
|
||||
@@ -195,10 +195,19 @@ func TestErrors(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.NotNil(g)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = groupClient.Read(tc.Context(), fmt.Sprintf("%s/../", g.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = groupClient.Update(tc.Context(), g.Item.Id, 73, groups.WithName("anything"))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
|
||||
|
||||
@@ -216,10 +216,17 @@ func TestErrors(t *testing.T) {
|
||||
|
||||
hc, err := pc.Create(tc.Context(), "static", proj.GetPublicId(), hostcatalogs.WithName("foo"))
|
||||
require.NoError(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.NotNil(hc)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = pc.Read(tc.Context(), fmt.Sprintf("%s/../", hc.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = pc.Update(tc.Context(), hc.Item.Id, 73, hostcatalogs.WithName("anything"))
|
||||
require.Error(err)
|
||||
|
||||
@@ -199,10 +199,19 @@ func TestErrors(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.NotNil(h)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = hClient.Read(tc.Context(), fmt.Sprintf("%s/../", h.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = hClient.Update(tc.Context(), h.Item.Id, 73, hosts.WithName("anything"))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
|
||||
|
||||
@@ -287,7 +287,6 @@ func TestCrud(t *testing.T) {
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
}
|
||||
|
||||
// TODO: Get better coverage for expected errors and error formats.
|
||||
func TestErrors(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
tc := controller.NewTestController(t, nil)
|
||||
@@ -308,10 +307,19 @@ func TestErrors(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.NotNil(h)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = hClient.Read(tc.Context(), fmt.Sprintf("%s/../", h.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = hClient.Update(tc.Context(), h.Item.Id, 73, hostsets.WithName("anything"))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
|
||||
|
||||
@@ -187,10 +187,19 @@ func TestErrorsOidc(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.NotNil(u)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = managedgroupClient.Read(tc.Context(), fmt.Sprintf("%s/../", u.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = managedgroupClient.Update(tc.Context(), u.Item.Id, 73, managedgroups.WithName("anything"))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
|
||||
|
||||
@@ -285,10 +285,19 @@ func TestErrors(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.NotNil(u)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = roleClient.Read(tc.Context(), fmt.Sprintf("%s/../", u.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = roleClient.Update(tc.Context(), u.Item.Id, 73, roles.WithName("anything"))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
|
||||
|
||||
@@ -124,10 +124,19 @@ func TestErrors(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.NotNil(createdProj)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = scps.Read(tc.Context(), fmt.Sprintf("%s/../", createdProj.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = scps.Update(tc.Context(), createdProj.Item.Id, 73, scopes.WithName("anything"))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
|
||||
|
||||
@@ -272,10 +272,19 @@ func TestSet_Errors(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.NotNil(tar)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = tarClient.Read(tc.Context(), fmt.Sprintf("%s/../", tar.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = tarClient.Update(tc.Context(), tar.Item.Id, 73, targets.WithName("anything"))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
|
||||
|
||||
@@ -181,10 +181,19 @@ func TestErrors(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.NotNil(u)
|
||||
|
||||
// A malformed id is processed as the id and not a different path to the api.
|
||||
_, err = userClient.Read(tc.Context(), fmt.Sprintf("%s/../", u.Item.Id))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
require.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode())
|
||||
require.Len(apiErr.Details.RequestFields, 1)
|
||||
assert.Equal(apiErr.Details.RequestFields[0].Name, "id")
|
||||
|
||||
// Updating the wrong version should fail.
|
||||
_, err = userClient.Update(tc.Context(), u.Item.Id, 73, users.WithName("anything"))
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
|
||||
|
||||
|
||||
Reference in new issue
Block a user