From ef5e2d7263b6ff1682fd985f66a3ca2b89d22a60 Mon Sep 17 00:00:00 2001 From: ygeva Date: Sun, 15 Oct 2023 21:54:51 +0300 Subject: [PATCH] Return conflict for existing issuer when variables associated with it --- CHANGELOG.md | 1 + app/controllers/issuers_controller.rb | 9 +++++++-- spec/controllers/issuers_controller_spec.rb | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0577f95f57..5b15457121 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/controllers/issuers_controller.rb b/app/controllers/issuers_controller.rb index 95a7141864..e1d0392d94 100644 --- a/app/controllers/issuers_controller.rb +++ b/app/controllers/issuers_controller.rb @@ -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, @@ -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) diff --git a/spec/controllers/issuers_controller_spec.rb b/spec/controllers/issuers_controller_spec.rb index 7a8f8de679..f5e07e7d25 100644 --- a/spec/controllers/issuers_controller_spec.rb +++ b/spec/controllers/issuers_controller_spec.rb @@ -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