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 invalid credential error handling in authentication process #536

Merged
merged 7 commits into from
Jan 18, 2023

Conversation

Didainius
Copy link
Collaborator

@Didainius Didainius commented Dec 15, 2022

At the moment our SDK does not handle HTTP 401 (Unauthorized) error when authenticating to VCD. As a result, the user may get the illusion that he authenticated correctly, but subsequent code would return errors that don't make sense (see example below). This bug also appears for all consumers of this SDK (including Terraform provider VCD). This has already confused quite a few users and we ought to fix it.

Before When specifying invalid credentials, the user may get totally odd errors, such as:

Error: could not find any extended Provider VDC with name ext-net-name: error retrieving query: API Error: 406: The request has invalid accept header: Invalid API version requested. Supported API versions are: [37.0.0-alpha, 36.3, 36.2, 36.1, 36.0, 35.2, 35.0, 34.0, 33.0 [D], 32.0 [D], 31.0 [D]] ([D] indicates deprecated versions)
│
│   with data.vcd_provider_vdc.nsxt-pvdc,
│   on Org-creation-Main.tf line 47, in data "vcd_provider_vdc" "nsxt-pvdc":
│   47: data "vcd_provider_vdc" "nsxt-pvdc" {
│
╵
╷
│ Error: could not find external network V2 by name 'ext-net-name': could not find external network by name: error getting all pages for endpoint https://HOSTNAME/cloudapi/1.0.0/externalNetworks/: error in HTTP GET request: NOT_ACCEPTABLE - The request has invalid accept header: Invalid API version requested. Supported API versions are: [37.0.0-alpha, 36.3, 36.2, 36.1, 36.0, 35.2, 35.0, 34.0, 33.0 [D], 32.0 [D], 31.0 [D]] ([D] indicates deprecated versions)
│
│   with data.vcd_external_network_v2.nsxt-ext-net,
│   on Org-creation-Main.tf line 98, in data "vcd_external_network_v2" "nsxt-ext-net":
│   98: data "vcd_external_network_v2" "nsxt-ext-net" {

After this fix - the user would immediately get such error and break further flow:

error authorizing: received response HTTP 401 (Unauthorized). Please check if your credentials are valid

Two new tests are added to validate this behavior:

  • TestVCDClient_AuthenticateInvalidPassword
  • TestVCDClient_AuthenticateInvalidToken

Signed-off-by: Dainius Serplis <[email protected]>
Signed-off-by: Dainius Serplis <[email protected]>
@Didainius Didainius changed the title Fix invalid credential error in authentication process Fix invalid credential error handling in authentication process Dec 15, 2022
@Didainius Didainius marked this pull request as ready for review January 16, 2023 10:46
Copy link
Collaborator

@adambarreiro adambarreiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!
Approved, with minor corrections.

Signed-off-by: Dainius Serplis <[email protected]>
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion for changelog.

@Didainius Didainius merged commit 6b0cdb4 into vmware:main Jan 18, 2023
@Didainius Didainius deleted the fix-auth-error branch January 18, 2023 12:33
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.

5 participants