iam: refuse DeleteUser while access keys remain

Deleting a user with live credentials orphaned its access keys; AWS
answers DeleteConflict until they are removed first.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Chris LuandDevin committed 2026-10-06 09:25:32 -07:00
1 parent 3dcc74e93d
commit 85c706e015
4 files changed
+73 -3

No files matched your search

+28 -1
View File
@@ -1692,7 +1692,34 @@ func TestEmbeddedIamFullWorkflow(t *testing.T) {
assert.Equal(t, http.StatusOK, response.Code)
})
// 5. Delete user
var accessKeyId string
for _, ident := range api.mockConfig.Identities {
if ident.Name == "WorkflowUser" && len(ident.Credentials) > 0 {
accessKeyId = ident.Credentials[0].AccessKey
}
}
assert.NotEmpty(t, accessKeyId)
// 5. Deleting a user that still has an access key is refused
t.Run("DeleteUserConflict", func(t *testing.T) {
params := &iam.DeleteUserInput{UserName: aws.String("WorkflowUser")}
req, _ := iam.New(session.New()).DeleteUserRequest(params)
_ = req.Build()
response, err := executeEmbeddedIamRequest(api, req.HTTPRequest, nil)
assert.NoError(t, err)
assert.Equal(t, http.StatusConflict, response.Code)
})
// 6. Delete the access key, then the user
t.Run("DeleteAccessKey", func(t *testing.T) {
params := &iam.DeleteAccessKeyInput{UserName: aws.String("WorkflowUser"), AccessKeyId: aws.String(accessKeyId)}
req, _ := iam.New(session.New()).DeleteAccessKeyRequest(params)
_ = req.Build()
response, err := executeEmbeddedIamRequest(api, req.HTTPRequest, nil)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, response.Code)
})
t.Run("DeleteUser", func(t *testing.T) {
params := &iam.DeleteUserInput{UserName: aws.String("WorkflowUser")}
req, _ := iam.New(session.New()).DeleteUserRequest(params)