pspete / psPAS

PowerShell module for CyberArk Privileged Access Security REST API
https://pspas.pspete.dev
MIT License
291 stars 91 forks source link

ConvertTo-UnixTime helper function does not handle locales well #361

Closed swerveshot closed 3 years ago

swerveshot commented 3 years ago

Describe the issue When using the ConvertTo-UnixTime helper function and you have your locale set to something other than "en-US" you will experience issues making API calls to Password Vault.

To Reproduce Steps to reproduce the behavior:

  1. Run this command to force "en-US" locale and the output has a proper Unix time which will be accepted by the API.
    
    $Date = Get-Date
    [System.Threading.Thread]::CurrentThread.CurrentCulture = "en-US" ; [math]::Round($(Get-Date $Date.ToUniversalTime() -UFormat %s))

1623150741

2. Run this command to force "nl-NL" locale and the output will not have a proper Unix time which will be rejected by the API.
```powershell
$Date = Get-Date
[System.Threading.Thread]::CurrentThread.CurrentCulture = "nl-NL" ; [math]::Round($(Get-Date $Date.ToUniversalTime() -UFormat %s))

162315074106698

The error the API throws when using this value is:

{
    "ErrorCode": "CAWS00001E",
    "ErrorMessage": "Value to add was out of range.\r\nParameter name: value"
}

Expected behavior Have the function create a proper Unix timestamp regardless of locale.

Your Environment CurrentCulture : nl-NL CurrentUICulture : en-US

pspete commented 3 years ago

Thanks for the report @swerveshot. The fix proposed by @liamwh to resolve the issue is now present on the dev branch, so will be part of the next release.

swerveshot commented 3 years ago

Thanks for the update @pspete. I guess we can go ahead and close this issue then.

And kudos to @liamwh for the fix of course.