Bug 1544800

Summary: Can Add Duplicate Custom Attributes on OpenShift Provider Via the API
Product: Red Hat CloudForms Management Engine Reporter: juwatts
Component: APIAssignee: Gregg Tanzillo <gtanzill>
Status: CLOSED CURRENTRELEASE QA Contact: Parthvi Vala <pvala>
Severity: high Docs Contact:
Priority: high    
Version: 5.9.0CC: cpelland, mkourim, obarenbo, pvala
Target Milestone: GAKeywords: TestOnly, ZStream
Target Release: 5.10.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: 5.10.0.0 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1552824 (view as bug list) Environment:
Last Closed: 2019-02-11 14:00:20 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: CFME Core Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1552824    

Description juwatts 2018-02-13 14:29:58 UTC
Description of problem:
When adding custom attributes via the api on the OpenShift provider, user has the ability to successfully add duplicate entries.


Version-Release number of selected component (if applicable):
5.9.0.20

How reproducible:
100%

Steps to Reproduce:
1. Add a custom attribute via the api
example:
POST /api/providers/1/custom_attributes
{
  "action" : "add",
  "resources" : [
    { "name" : "koko", "value" : "moko" }
  ]
}

2. Verify the custom attribute was added successfully
3. Add the same custom attribute via the api

Actual results:
Duplicate custom attributes appear

Expected results:
Would expect for some 409 returned code and json that explains that this custom attribute is already exists

Additional info:

Comment 3 CFME Bot 2018-02-14 13:45:36 UTC
New commit detected on ManageIQ/manageiq-api/master:
https://github.com/ManageIQ/manageiq-api/commit/5dff1e383aeef4d94befee7b3b17f3e44e6f2cf5

commit 5dff1e383aeef4d94befee7b3b17f3e44e6f2cf5
Author:     Jillian Tullo <jtullo>
AuthorDate: Wed Feb 14 07:37:45 2018 -0500
Commit:     Jillian Tullo <jtullo>
CommitDate: Wed Feb 14 07:37:45 2018 -0500

    Default section to "metadata" across custom attributes add action
    
    When a new custom attribute is added, it defaults the section to "metadata" when the section is not specified. This causes issues if the request is then made again, especially because the default behavior for "add" is to edit. Without defaulting the section to "metadata" across the board, a new custom attribute is created, rather than updated.
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1544800

 .../api/subcollections/custom_attributes.rb          |  2 +-
 spec/requests/custom_attributes_spec.rb              | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

Comment 6 juwatts 2018-10-24 15:47:27 UTC
Verified on 5.10.0.20.20181016163900_fe677b4 that adding a custom attribute with the same name as an existing attribute updates the existing attribute.