Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Certificate retrieval when its alias has special characters #589

Merged
merged 4 commits into from
Jul 14, 2023

Conversation

adambarreiro
Copy link
Collaborator

@adambarreiro adambarreiro commented Jul 13, 2023

Bug description

When a Certificate inside the library contained a : in the alias (name), the functions Client.GetCertificateFromLibraryByName and AdminOrg.GetCertificateFromLibraryByName are not able to find it, returning an ENF (Entity Not Found) error.

How to reproduce

Given any VCD version, it is as simple as changing the certificate name in the tests, for example:

	alias := "Test_CertificateInLibrary:1"

Fix

The function shouldDoSlowSearch documentation made the following statements:

shouldDoSlowSearch (...) the encoding is rejected by the API in VCD 10.2 version.
(...) Yet, this not needed anymore in VCD 10.3 version.
(...)

However, if one uses Postman to send the following query in VCD 10.4.x:

https://{{vcdHost}}/cloudapi/1.0.0/ssl/certificateLibrary/?filter=alias==Test%3BCertificate%3BIn%3BLibrary%26filterEncoded=true%26pageSize=128&filterEncoded=true&pageSize=128

It returns the error:

"minorErrorCode": "BAD_REQUEST",
    "message": "Cannot parse the supplied filter: alias==Test;Certificate;In;Library&filterEncoded=true&pageSize=128",
    "stackTrace": "com.vmware.vcloud.api.rest.parser.QueryParseException: Cannot parse the supplied filter: alias==Test;Certificate;In;Library&filterEncoded=true&pageSize=128\n\tat com.vmware.vcloud.api.rest.providers.filters.openapi.QueryValidationFilter.enforceFilteringRestric

So, the statements are false. For this reason, this PR removes the VCD version check in shouldDoSlowSearch, as this issue happens always and independent of the VCD version.

This PR also removes the url.QueryEscape inside shouldDoSlowSearch:

params.Set("filter", fmt.Sprintf(filterKey+"==%s", url.QueryEscape(name)))

This operation is wrong, as the OpenAPI generic calls to retrieve all items also escape the parameters:

func (client *Client) newOpenApiRequest(...) {
...
	// Add the params to our URL
	reqUrlCopy.RawQuery += params.Encode()

So in result, the alias==%s filter was encoded twice, causing the VCD filter processor to fail when the alias has special characters like :, as they're encoded twice.

Tests

Tested in 10.4.2

GOVCD_SKIP_VAPP_CREATION=1 go test -tags functional -check.f 'Test_CertificateInLibrary|Test_GetCertificateFromLibrary.*|Test_NsxtVdcGroup' -check.vv -timeout=0

@adambarreiro adambarreiro changed the title # Fix Certificate retrieval when its alias has special characters Jul 13, 2023
@adambarreiro adambarreiro marked this pull request as ready for review July 13, 2023 15:32
@adambarreiro adambarreiro self-assigned this Jul 13, 2023
Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro force-pushed the fix-certificate-management branch from 356dafb to d4ba120 Compare July 13, 2023 19:58
abarreiro added 3 commits July 13, 2023 22:47
nit
Signed-off-by: abarreiro <[email protected]>
#
Signed-off-by: abarreiro <[email protected]>
#
Signed-off-by: abarreiro <[email protected]>
@adambarreiro adambarreiro merged commit e9a726b into vmware:main Jul 14, 2023
@adambarreiro adambarreiro deleted the fix-certificate-management branch July 14, 2023 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants