From 8e522ce263d65188f4b89c9b6ecee28d0a2a15a5 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Wed, 16 Apr 2025 12:50:32 +0200 Subject: [PATCH 1/7] added tests --- Tests/Get-IDNWEnvironment.Tests.ps1 | 17 ++++++ Tests/Get-IDNWFilterString.Tests.ps1 | 89 ++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 Tests/Get-IDNWEnvironment.Tests.ps1 create mode 100644 Tests/Get-IDNWFilterString.Tests.ps1 diff --git a/Tests/Get-IDNWEnvironment.Tests.ps1 b/Tests/Get-IDNWEnvironment.Tests.ps1 new file mode 100644 index 0000000..b5658a1 --- /dev/null +++ b/Tests/Get-IDNWEnvironment.Tests.ps1 @@ -0,0 +1,17 @@ +# Requires -Module Pester +Describe "Get-IDNWEnvironment" { + + BeforeAll { + . "../PSIdentityNow/PSIdentityNow/Private/Get-IDNWEnvironment.ps1" + . "../PSIdentityNow/PSIdentityNow/Private/Get-IDNWSecret.ps1" + . "../PSIdentityNow/PSIdentityNow/Private/Get-IDNWSessionToken.ps1" + . "../PSIdentityNow/PSIdentityNow/Private/Get-IDNWTokenDetail.ps1" + } + + It "Should return a valid token" { + $Environment = Get-IDNWEnvironment -Instance "ACC" -ApiVersion "v3" -UseSecretManagement:$false + $Environment.SessionToken | Should -BeOfType "System.Security.SecureString" + [guid]$Environment.SessionTokenDetails.tenant_id | Should -BeOfType "System.Guid" + } + +} diff --git a/Tests/Get-IDNWFilterString.Tests.ps1 b/Tests/Get-IDNWFilterString.Tests.ps1 new file mode 100644 index 0000000..c0bcf2e --- /dev/null +++ b/Tests/Get-IDNWFilterString.Tests.ps1 @@ -0,0 +1,89 @@ +# Requires -Module Pester +Describe "Get-IDNWFilterString" { + + BeforeAll { + . "../PSIdentityNow/PSIdentityNow/Private/Get-IDNWFilterString.ps1" + . "../PSIdentityNow/PSIdentityNow/Private/Test-IDNWFilter.ps1" + } + + It "should handle string values correctly" { + $filters = @(@{ field = "name"; operator = "eq"; value = "test" }) + $result = Get-IDNWFilterString -Filters $filters + $result | Should -Be 'name eq "test"' + } + + It "should handle integer values correctly" { + $filters = @(@{ field = "count"; operator = "eq"; value = 5 }) + $result = Get-IDNWFilterString -Filters $filters + $result | Should -Be 'count eq 5' + } + + It "should handle boolean values correctly" { + $filters = @(@{ field = "enabled"; operator = "eq"; value = $true }) + $result = Get-IDNWFilterString -Filters $filters + $result | Should -Be 'enabled eq true' + } + + It "should handle 'present' operator correctly" { + $filters = @(@{ field = "email"; operator = "present"; value = $null }) + $result = Get-IDNWFilterString -Filters $filters + $result | Should -Be 'pr email' + } + + It "should handle 'isnull' operator correctly" { + $filters = @(@{ field = "lastLogin"; operator = "isnull"; value = $null }) + $result = Get-IDNWFilterString -Filters $filters + $result | Should -Be 'lastLogin isnull' + } + + It "should handle array values with 'in' operator correctly" { + $filters = @(@{ field = "id"; operator = "in"; value = @("one", "two") }) + $result = Get-IDNWFilterString -Filters $filters + $result | Should -Be 'id in ("one","two")' + } + + It "should handle 'containsall' operator and arrays correctly" { + $filters = @(@{ field = "tags"; operator = "containsall"; value = @("foo", "bar") }) + $result = Get-IDNWFilterString -Filters $filters + $result | Should -Be 'tags ca ("foo","bar")' + } + + It "should handle 'contains' operator and string values correctly" { + $filters = @(@{ field = "description"; operator = "contains"; value = "admin" }) + $result = Get-IDNWFilterString -Filters $filters + $result | Should -Be 'description co "admin"' + } + + It "should handle 'startswith' operator correctly" { + $filters = @(@{ field = "username"; operator = "startswith"; value = "dev" }) + $result = Get-IDNWFilterString -Filters $filters + $result | Should -Be 'username sw "dev"' + } + + It "should handle DateTime values correctly" { + $dt = Get-Date -Date "2024-01-01T12:00:00" + $filters = @(@{ field = "created"; operator = "ge"; value = $dt }) + $result = Get-IDNWFilterString -Filters $filters + $result | Should -Be 'created ge 2024-01-01T12:00:00Z' + } + + It "should handle multiple filters combined with 'and'" { + $filters = @( + @{ field = "name"; operator = "eq"; value = "admin" }, + @{ field = "enabled"; operator = "eq"; value = $true } + ) + $result = Get-IDNWFilterString -Filters $filters + $result | Should -Be 'name eq "admin" and enabled eq true' + } + + It "should escape double quotes in string values" { + $filters = @(@{ field = "comment"; operator = "eq"; value = 'He said "hello"' }) + $result = Get-IDNWFilterString -Filters $filters + $result | Should -Be 'comment eq "He said \"hello\""' + } + + It "should throw on unsupported value types" { + $filters = @(@{ field = "bad"; operator = "eq"; value = @{ unexpected = "type" } }) + { Get-IDNWFilterString -Filters $filters } | Should -Throw + } +} From 62ac927e2c027915c210223fbfb8caab6da10ee2 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Wed, 16 Apr 2025 12:51:06 +0200 Subject: [PATCH 2/7] on demand for now --- .github/workflows/run-pester.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-pester.yml b/.github/workflows/run-pester.yml index 6c2378e..4dbad05 100644 --- a/.github/workflows/run-pester.yml +++ b/.github/workflows/run-pester.yml @@ -1,7 +1,9 @@ name: Run Pester Tests -on: - pull_request: +on: [workflow_dispatch] + +# on: +# pull_request: jobs: pester: From a7684158996834df74bc458be5cf6939e5bf9c23 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Wed, 16 Apr 2025 13:03:04 +0200 Subject: [PATCH 3/7] revert --- .github/workflows/run-pester.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run-pester.yml b/.github/workflows/run-pester.yml index 4dbad05..6c2378e 100644 --- a/.github/workflows/run-pester.yml +++ b/.github/workflows/run-pester.yml @@ -1,9 +1,7 @@ name: Run Pester Tests -on: [workflow_dispatch] - -# on: -# pull_request: +on: + pull_request: jobs: pester: From 9af113c8ea2c35cb3cf7878f063b08d3f6e802a1 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Wed, 16 Apr 2025 13:03:22 +0200 Subject: [PATCH 4/7] no env --- Tests/Get-IDNWEnvironment.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Get-IDNWEnvironment.Tests.ps1 b/Tests/Get-IDNWEnvironment.Tests.ps1 index b5658a1..2e35f0b 100644 --- a/Tests/Get-IDNWEnvironment.Tests.ps1 +++ b/Tests/Get-IDNWEnvironment.Tests.ps1 @@ -9,7 +9,7 @@ Describe "Get-IDNWEnvironment" { } It "Should return a valid token" { - $Environment = Get-IDNWEnvironment -Instance "ACC" -ApiVersion "v3" -UseSecretManagement:$false + $Environment = Get-IDNWEnvironment -ApiVersion "v3" -UseSecretManagement:$false $Environment.SessionToken | Should -BeOfType "System.Security.SecureString" [guid]$Environment.SessionTokenDetails.tenant_id | Should -BeOfType "System.Guid" } From 86c4e6e380fc49821b1f075a8713b4625799cbb3 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Wed, 16 Apr 2025 13:03:42 +0200 Subject: [PATCH 5/7] revert revert --- .github/workflows/run-pester.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-pester.yml b/.github/workflows/run-pester.yml index 6c2378e..4dbad05 100644 --- a/.github/workflows/run-pester.yml +++ b/.github/workflows/run-pester.yml @@ -1,7 +1,9 @@ name: Run Pester Tests -on: - pull_request: +on: [workflow_dispatch] + +# on: +# pull_request: jobs: pester: From b0ea5ef8ed90b6d73a2b9857f6121abc5519437b Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Wed, 16 Apr 2025 13:07:57 +0200 Subject: [PATCH 6/7] doh --- Tests/Get-IDNWEnvironment.Tests.ps1 | 8 ++++---- Tests/Get-IDNWFilterString.Tests.ps1 | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/Get-IDNWEnvironment.Tests.ps1 b/Tests/Get-IDNWEnvironment.Tests.ps1 index 2e35f0b..03fd7ce 100644 --- a/Tests/Get-IDNWEnvironment.Tests.ps1 +++ b/Tests/Get-IDNWEnvironment.Tests.ps1 @@ -2,10 +2,10 @@ Describe "Get-IDNWEnvironment" { BeforeAll { - . "../PSIdentityNow/PSIdentityNow/Private/Get-IDNWEnvironment.ps1" - . "../PSIdentityNow/PSIdentityNow/Private/Get-IDNWSecret.ps1" - . "../PSIdentityNow/PSIdentityNow/Private/Get-IDNWSessionToken.ps1" - . "../PSIdentityNow/PSIdentityNow/Private/Get-IDNWTokenDetail.ps1" + . "../PSIdentityNow/Private/Get-IDNWEnvironment.ps1" + . "../PSIdentityNow/Private/Get-IDNWSecret.ps1" + . "../PSIdentityNow/Private/Get-IDNWSessionToken.ps1" + . "../PSIdentityNow/Private/Get-IDNWTokenDetail.ps1" } It "Should return a valid token" { diff --git a/Tests/Get-IDNWFilterString.Tests.ps1 b/Tests/Get-IDNWFilterString.Tests.ps1 index c0bcf2e..fbfccd3 100644 --- a/Tests/Get-IDNWFilterString.Tests.ps1 +++ b/Tests/Get-IDNWFilterString.Tests.ps1 @@ -2,8 +2,8 @@ Describe "Get-IDNWFilterString" { BeforeAll { - . "../PSIdentityNow/PSIdentityNow/Private/Get-IDNWFilterString.ps1" - . "../PSIdentityNow/PSIdentityNow/Private/Test-IDNWFilter.ps1" + . "../PSIdentityNow/Private/Get-IDNWFilterString.ps1" + . "../PSIdentityNow/Private/Test-IDNWFilter.ps1" } It "should handle string values correctly" { From af9e39f23e34806d322402640396a0d890e97352 Mon Sep 17 00:00:00 2001 From: Mathijs de Ruiter <33999622+EUCTechTopics@users.noreply.github.com> Date: Wed, 16 Apr 2025 13:14:05 +0200 Subject: [PATCH 7/7] revert --- .github/workflows/run-pester.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run-pester.yml b/.github/workflows/run-pester.yml index 4dbad05..6c2378e 100644 --- a/.github/workflows/run-pester.yml +++ b/.github/workflows/run-pester.yml @@ -1,9 +1,7 @@ name: Run Pester Tests -on: [workflow_dispatch] - -# on: -# pull_request: +on: + pull_request: jobs: pester: