Adding Authz checks that support new pathing (#328)
This commit is contained in:
1 parent
3d944a616f
commit
1c2c078e0a
46 files changed
+1433
-1165
No files matched your search
@@ -124,11 +124,6 @@ func TestAccount_Crud(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.True(existed, "Expected existing account when deleted, but it wasn't.")
|
||||
|
||||
existed, apiErr, err = accountClient.Delete(tc.Context(), amId, u.Id)
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.False(existed, "Expected account to not exist when deleted, but it did.")
|
||||
}
|
||||
|
||||
func TestAccount_CustomMethods(t *testing.T) {
|
||||
@@ -198,12 +193,12 @@ func TestAccount_Errors(t *testing.T) {
|
||||
_, apiErr, err = accountClient.Read(tc.Context(), amId, password.AccountPrefix+"_doesntexis")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
|
||||
_, apiErr, err = accountClient.Read(tc.Context(), amId, "invalid id")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Status)
|
||||
|
||||
_, apiErr, err = accountClient.Update(tc.Context(), amId, u.Id, u.Version)
|
||||
require.NoError(err)
|
||||
|
||||
@@ -119,12 +119,7 @@ func TestAuthToken_Crud(t *testing.T) {
|
||||
existed, _, err := tokens.Delete(tc.Context(), at.Id)
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.True(existed, "Expected existing user when deleted, but it wasn't.")
|
||||
|
||||
existed, apiErr, err = tokens.Delete(tc.Context(), at.Id)
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.False(existed, "Expected user to not exist when deleted, but it did.")
|
||||
assert.True(existed, "Expected existing token when deleted, but it wasn't.")
|
||||
}
|
||||
|
||||
func TestAuthToken_Errors(t *testing.T) {
|
||||
@@ -144,10 +139,10 @@ func TestAuthToken_Errors(t *testing.T) {
|
||||
_, apiErr, err := tokens.Read(tc.Context(), authtoken.AuthTokenPrefix+"_doesntexis")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
|
||||
_, apiErr, err = tokens.Read(tc.Context(), "invalid id")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Status)
|
||||
}
|
||||
@@ -170,8 +170,9 @@ func TestGroup_Crud(t *testing.T) {
|
||||
assert.True(existed, "Expected existing user when deleted, but it wasn't.")
|
||||
|
||||
existed, apiErr, err = groupsClient.Delete(tc.Context(), g.Id)
|
||||
assert.NoError(err)
|
||||
assert.False(existed, "Expected user to not exist when deleted, but it did.")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -224,12 +225,12 @@ func TestGroup_Errors(t *testing.T) {
|
||||
_, apiErr, err = groupClient.Read(tc.Context(), iam.GroupPrefix+"_doesntexis")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
|
||||
_, apiErr, err = groupClient.Read(tc.Context(), "invalid id")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Status)
|
||||
|
||||
_, apiErr, err = groupClient.Update(tc.Context(), g.Id, g.Version)
|
||||
require.NoError(err)
|
||||
|
||||
@@ -125,8 +125,9 @@ func TestCatalogs_Crud(t *testing.T) {
|
||||
assert.True(existed, "Expected existing catalog when deleted, but it wasn't.")
|
||||
|
||||
existed, apiErr, err = hcClient.Delete(tc.Context(), hc.Id)
|
||||
assert.NoError(err)
|
||||
assert.False(existed, "Expected catalog to not exist when deleted, but it did.")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
}
|
||||
|
||||
// TODO: Get better coverage for expected errors and error formats.
|
||||
@@ -159,10 +160,10 @@ func TestCatalogs_Errors(t *testing.T) {
|
||||
require.NoError(err)
|
||||
// TODO: Should this be nil instead of just a catalog that has no values set
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(apiErr.Status, http.StatusNotFound)
|
||||
assert.EqualValues(apiErr.Status, http.StatusForbidden)
|
||||
|
||||
_, apiErr, err = pc.Read(tc.Context(), "invalid id")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Status)
|
||||
}
|
||||
@@ -137,8 +137,9 @@ func TestHost_Crud(t *testing.T) {
|
||||
assert.True(existed, "Expected existing catalog when deleted, but it wasn't.")
|
||||
|
||||
existed, apiErr, err = hClient.Delete(tc.Context(), hc.Id, h.Id)
|
||||
assert.NoError(err)
|
||||
assert.False(existed, "Expected catalog to not exist when deleted, but it did.")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
}
|
||||
|
||||
// TODO: Get better coverage for expected errors and error formats.
|
||||
@@ -176,10 +177,10 @@ func TestHost_Errors(t *testing.T) {
|
||||
_, apiErr, err = hClient.Read(tc.Context(), hc.Id, static.HostPrefix+"_doesntexis")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(apiErr.Status, http.StatusNotFound)
|
||||
assert.EqualValues(apiErr.Status, http.StatusForbidden)
|
||||
|
||||
_, apiErr, err = hClient.Read(tc.Context(), hc.Id, "invalid id")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Status)
|
||||
}
|
||||
@@ -237,8 +237,9 @@ func TestSet_Crud(t *testing.T) {
|
||||
} else {
|
||||
existed, apiErr, err = hClient.Delete(tc.Context(), hc.Id, h.Id)
|
||||
}
|
||||
assert.NoError(err)
|
||||
assert.False(existed, "Expected catalog to not exist when deleted, but it did.")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,11 +274,6 @@ func TestRole_Crud(t *testing.T) {
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.True(existed, "Expected existing user when deleted, but it wasn't.")
|
||||
|
||||
existed, apiErr, err = roleClient.Delete(tc.Context(), g.Id)
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.False(existed, "Expected user to not exist when deleted, but it did.")
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -330,12 +325,12 @@ func TestRole_Errors(t *testing.T) {
|
||||
_, apiErr, err = roleClient.Read(tc.Context(), iam.RolePrefix+"_doesntexis")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
|
||||
_, apiErr, err = roleClient.Read(tc.Context(), "invalid id")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Status)
|
||||
|
||||
_, apiErr, err = roleClient.Update(tc.Context(), u.Id, u.Version)
|
||||
require.NoError(err)
|
||||
|
||||
@@ -147,5 +147,5 @@ func TestProject_Errors(t *testing.T) {
|
||||
_, apiErr, err = scps.Read(tc.Context(), "invalid id")
|
||||
assert.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Status)
|
||||
}
|
||||
@@ -123,8 +123,8 @@ func TestUser_Crud(t *testing.T) {
|
||||
|
||||
existed, apiErr, err = userClient.Delete(tc.Context(), u.Id)
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.False(existed, "Expected user to not exist when deleted, but it did.")
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
}
|
||||
|
||||
func TestUser_Errors(t *testing.T) {
|
||||
@@ -156,12 +156,12 @@ func TestUser_Errors(t *testing.T) {
|
||||
_, apiErr, err = userClient.Read(tc.Context(), iam.UserPrefix+"_doesntexis")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
|
||||
_, apiErr, err = userClient.Read(tc.Context(), "invalid id")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Status)
|
||||
|
||||
_, apiErr, err = userClient.Update(tc.Context(), u.Id, u.Version)
|
||||
require.NoError(err)
|
||||
|
||||
Reference in new issue
Block a user