bpg / terraform-provider-proxmox

Terraform Provider for Proxmox
https://registry.terraform.io/providers/bpg/proxmox
Mozilla Public License 2.0
884 stars 140 forks source link

chore(tests): add script to test/view api-authentication successes/failures #1562

Closed vanillaSprinkles closed 1 month ago

vanillaSprinkles commented 1 month ago

Contributor's Note

Here's the monster shell looper to test api combination paths ( script self-creates a shell-config-file that would need to be updated for success-expected tests )

Proof of Work

example output (of make test-api-creds-auth)

test endpoint: https://w.x.y.z:8006/

Should Pass:

##
pass-test (expect auth-success): set 1/3 part 1/4;  using env raw-creds:  api_token [pve]
    set cred-vars:  PROXMOX_VE_API_TOKEN
    set arg-vars:
  test 1 part 1 passed pass-as-expected
  see TF-output in file: outs_cred-tester__expect_pass__passed.2024-10-02T23_05_17-07_00.log

pass-test (expect auth-success): set 1/3 part 2/4;  using in-line raw-creds:  api_token [pve]
    set cred-vars:
    set arg-vars:  api_token
  test 1 part 2 passed pass-as-expected
  see TF-output in file: outs_cred-tester__expect_pass__passed.2024-10-02T23_05_17-07_00.log

pass-test (expect auth-success): set 1/3 part 3/4;  using env pre-auth:  api_token [pve]
  skip testing api_token with pre-auth ticket+csrf; invalid test (cannot get auth-ticket and csrf with api-token)

pass-test (expect auth-success): set 1/3 part 4/4;  using in-line pre-auth:  api_token [pve]
  skip testing api_token with pre-auth ticket+csrf; invalid test (cannot get auth-ticket and csrf with api-token)

##
pass-test (expect auth-success): set 2/3 part 1/4;  using env raw-creds:  user [pam] + pass
    set cred-vars:  PROXMOX_VE_PASSWORD  PROXMOX_VE_USERNAME
    set arg-vars:
  test 2 part 1 passed pass-as-expected
  see TF-output in file: outs_cred-tester__expect_pass__passed.2024-10-02T23_05_21-07_00.log

pass-test (expect auth-success): set 2/3 part 2/4;  using in-line raw-creds:  user [pam] + pass
    set cred-vars:
    set arg-vars:  password  username
  test 2 part 2 passed pass-as-expected
  see TF-output in file: outs_cred-tester__expect_pass__passed.2024-10-02T23_05_25-07_00.log

pass-test (expect auth-success): set 2/3 part 3/4;  using env pre-auth:  user [pam] + pass
    set cred-vars:  PROXMOX_VE_AUTH_TICKET  PROXMOX_VE_CSRF_PREVENTION_TOKEN
    set arg-vars:
  test 2 part 3 passed pass-as-expected
  see TF-output in file: outs_cred-tester__expect_pass__passed.2024-10-02T23_05_29-07_00.log

pass-test (expect auth-success): set 2/3 part 4/4;  using in-line pre-auth:  user [pam] + pass
  Note: setting test_pre_auth_empty_creds as to not re-test empty pre-auth creds with in-line config
    set cred-vars:
    set arg-vars:  auth_ticket  csrf_prevention_token
  test 2 part 2 passed pass-as-expected
  see TF-output in file: outs_cred-tester__expect_pass__passed.2024-10-02T23_05_32-07_00.log

.....

Should Fail:

##
fail-test (expect auth-failure): set 2/10 part 1/4;  using env raw-creds:  un+pw [real] => ticket [real] + csrf [fake]
    set cred-vars:  PROXMOX_VE_OTP  PROXMOX_VE_PASSWORD  PROXMOX_VE_USERNAME
    set arg-vars:
  test 2 part 1 passed fail-as-expected
  see TF-output in file: outs_cred-tester__expect_fail__passed.2024-10-02T23_11_55-07_00.log
  | Error: failed to get nodes: failed to authenticate HTTP GET request (path: nodes) - Reason: failed to authenticate: failed to authenticate: received an HTTP 401 response - Reason: authentication failure
  |
  |   with data.proxmox_virtual_environment_nodes.available_nodes_01,
  |   on data_object.tf line 5, in data "proxmox_virtual_environment_nodes" "available_nodes_01":
  |    5: data "proxmox_virtual_environment_nodes" "available_nodes_01" {}
  |
  |
  | Error: failed to get nodes: failed to authenticate HTTP GET request (path: nodes) - Reason: failed to authenticate: failed to authenticate: received an HTTP 401 response - Reason: authentication failure
  |
  |   with data.proxmox_virtual_environment_nodes.available_nodes_02,
  |   on data_object.tf line 7, in data "proxmox_virtual_environment_nodes" "available_nodes_02":
  |    7: data "proxmox_virtual_environment_nodes" "available_nodes_02" {}
  |
  |

fail-test (expect auth-failure): set 2/10 part 2/4;  using in-line raw-creds:  un+pw [real] => ticket [real] + csrf [fake]
    set cred-vars:
    set arg-vars:  otp  password  username
  test 2 part 2 passed fail-as-expected
  see TF-output in file: outs_cred-tester__expect_fail__passed.2024-10-02T23_12_04-07_00.log
  | Error: failed to get nodes: failed to authenticate HTTP GET request (path: nodes) - Reason: failed to authenticate: failed to authenticate: received an HTTP 401 response - Reason: authentication failure
  |
  |   with data.proxmox_virtual_environment_nodes.available_nodes_01,
  |   on data_object.tf line 5, in data "proxmox_virtual_environment_nodes" "available_nodes_01":
  |    5: data "proxmox_virtual_environment_nodes" "available_nodes_01" {}
  |
  |
  | Error: failed to get nodes: failed to authenticate HTTP GET request (path: nodes) - Reason: failed to authenticate: failed to authenticate: received an HTTP 401 response - Reason: authentication failure
  |
  |   with data.proxmox_virtual_environment_nodes.available_nodes_02,
  |   on data_object.tf line 7, in data "proxmox_virtual_environment_nodes" "available_nodes_02":
  |    7: data "proxmox_virtual_environment_nodes" "available_nodes_02" {}
  |
  |

fail-test (expect auth-failure): set 2/10 part 3/4;  using env pre-auth:  un+pw [real] => ticket [real] + csrf [fake]
    set cred-vars:  PROXMOX_VE_AUTH_TICKET  PROXMOX_VE_CSRF_PREVENTION_TOKEN
    set arg-vars:
  test 2 part 3 failed fail-as-expected
  see TF-output in file: outs_cred-tester__expect_fail__failed.2024-10-02T23_12_14-07_00.log

fail-test (expect auth-failure): set 2/10 part 4/4;  using in-line pre-auth:  un+pw [real] => ticket [real] + csrf [fake]
  Note: setting test_pre_auth_empty_creds as to not re-test empty pre-auth creds with in-line config
    set cred-vars:
    set arg-vars:  auth_ticket  csrf_prevention_token
  test 2 part 2 failed fail-as-expected
  see TF-output in file: outs_cred-tester__expect_fail__failed.2024-10-02T23_12_18-07_00.log

Community Note

Closes #0000 | Relates #0000

bpg commented 1 month ago

@vanillaSprinkles I won’t even pretend to understand all the intricacies of the megascript 🧠. I’m just going to approve it as-is. My only ask is to move this folder under /example (singular), as all the “manual” test tooling is there. I’ll eventually rename it to something more appropriate.

vanillaSprinkles commented 1 month ago

@bpg agreed on the move (and rename though at the moment im out of ideas on the naming front; often harder than the code itself) - in a sub-dir i presume (of /example) and yes, it is a lot of bash-ism's; i'll try to add in a more inline documentation too (hope to get it this weekend)

vanillaSprinkles commented 1 month ago

@bpg i think this is ready; added a bit of bash-ism documentation in-line

vanillaSprinkles commented 1 month ago

omg im so sad i missed adding a file - made https://github.com/bpg/terraform-provider-proxmox/pull/1596