Skip to content

Commit

Permalink
Merge pull request #2995 from cyberark/ONYX-46339-error-issuers-exists
Browse files Browse the repository at this point in the history
Return conflict for existing issuer when variables associated with it
  • Loading branch information
yoavgeva authored Oct 16, 2023
2 parents 3cfdef2 + ef5e2d7 commit b196913
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [1.0.10-cloud] - 2023-10-22
### Added
- Telemetry logs for ephemeral secrets
- Return conflict for existing issuer when variables associated with it

## [1.0.9-cloud] - 2023-10-15
### Added
Expand Down
9 changes: 7 additions & 2 deletions app/controllers/issuers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def create
issuer_type = IssuerTypeFactory.new.create_issuer_type(params[:type])
issuer_type.validate(body_params)

issuerResource = Issuer.find(issuer_id: params[:id])
if not issuerResource.nil?
raise Exceptions::RecordExists.new("issuer", params[:id])
end

issuer = Issuer.new(issuer_id: params[:id], account: params[:account],
issuer_type: params[:type],
max_ttl: params[:max_ttl], data: params[:data].to_json,
Expand Down Expand Up @@ -58,11 +63,11 @@ def create
message: e.message
}
}, status: :bad_request)
rescue Sequel::UniqueConstraintViolation => e
rescue Exceptions::RecordExists => e
logger.error("The issuer [#{params[:id]}] already exists")
audit_failure(e, action)
issuer_audit_failure(params[:account], params[:id], "add", e.message)
raise Exceptions::RecordExists.new("issuer", params[:id])
raise e
rescue => e
audit_failure(e, action)
issuer_audit_failure(params[:account], params[:id], "add", e.message)
Expand Down
7 changes: 6 additions & 1 deletion spec/controllers/issuers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@
)
assert_response :success
expect(Resource.find(resource_id: "rspec:variable:data/ephemerals/related-ephemeral-variable")).to_not eq(nil)

post("/issuers/rspec",
env: token_auth_header(role: admin_user).merge(
'RAW_POST_DATA' => payload_create_issuer_input,
'CONTENT_TYPE' => "application/json"
))
assert_response :conflict
end
end

Expand Down

0 comments on commit b196913

Please sign in to comment.