From a922d18de8fc921115c9199d5fde92fc8a363389 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Nov 2024 13:44:41 +0100 Subject: [PATCH 1/6] Remove example scripts and add Base64 conversion functions --- examples/General.ps1 | 19 ----------- src/classes/public/Base64.ps1 | 28 +++++++++++++++++ src/formats/PSBase64.Format.ps1xml | 20 ++++++++++++ src/functions/public/ConvertFrom-Base64.ps1 | 35 +++++++++++++++++++++ src/functions/public/ConvertTo-Base64.ps1 | 35 +++++++++++++++++++++ src/functions/public/Get-PSModuleTest.ps1 | 20 ------------ src/functions/public/New-Base64.ps1 | 11 +++++++ src/functions/public/Test-Base64.ps1 | 22 +++++++++++++ tests/Module.Tests.ps1 | 23 +++++++------- 9 files changed, 163 insertions(+), 50 deletions(-) delete mode 100644 examples/General.ps1 create mode 100644 src/classes/public/Base64.ps1 create mode 100644 src/formats/PSBase64.Format.ps1xml create mode 100644 src/functions/public/ConvertFrom-Base64.ps1 create mode 100644 src/functions/public/ConvertTo-Base64.ps1 delete mode 100644 src/functions/public/Get-PSModuleTest.ps1 create mode 100644 src/functions/public/New-Base64.ps1 create mode 100644 src/functions/public/Test-Base64.ps1 diff --git a/examples/General.ps1 b/examples/General.ps1 deleted file mode 100644 index e193423..0000000 --- a/examples/General.ps1 +++ /dev/null @@ -1,19 +0,0 @@ -<# - .SYNOPSIS - This is a general example of how to use the module. -#> - -# Import the module -Import-Module -Name 'PSModule' - -# Define the path to the font file -$FontFilePath = 'C:\Fonts\CodeNewRoman\CodeNewRomanNerdFontPropo-Regular.tff' - -# Install the font -Install-Font -Path $FontFilePath -Verbose - -# List installed fonts -Get-Font -Name 'CodeNewRomanNerdFontPropo-Regular' - -# Uninstall the font -Get-Font -Name 'CodeNewRomanNerdFontPropo-Regular' | Uninstall-Font -Verbose diff --git a/src/classes/public/Base64.ps1 b/src/classes/public/Base64.ps1 new file mode 100644 index 0000000..e9d6199 --- /dev/null +++ b/src/classes/public/Base64.ps1 @@ -0,0 +1,28 @@ +class PSBase64 { + [string] $Base64 + + PSBase64([string] $Value) { + $this.Base64 = [PSBase64]::ConvertToBase64($Value) + } + + [string] ToString() { + return [PSBase64]::ConvertFromBase64($this.Base64) + } + + static [string] ConvertFromBase64([string] $Base64String) { + return [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($Base64String)) + } + + static [string] ConvertToBase64([string] $String) { + return [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($String)) + } + + static [bool] IsValid([string] $Base64String) { + try { + $null = [Convert]::FromBase64String($Base64String) + return $true + } catch { + return $false + } + } +} diff --git a/src/formats/PSBase64.Format.ps1xml b/src/formats/PSBase64.Format.ps1xml new file mode 100644 index 0000000..8b0f644 --- /dev/null +++ b/src/formats/PSBase64.Format.ps1xml @@ -0,0 +1,20 @@ + + + + + PSBase64CustomControl + + PSBase64 + + + + + + Base64 + + + + + + + diff --git a/src/functions/public/ConvertFrom-Base64.ps1 b/src/functions/public/ConvertFrom-Base64.ps1 new file mode 100644 index 0000000..d5d892a --- /dev/null +++ b/src/functions/public/ConvertFrom-Base64.ps1 @@ -0,0 +1,35 @@ +function ConvertFrom-Base64 { + <# + .SYNOPSIS + Convert to string from base64 + + .DESCRIPTION + Converts a Base64 encoded string to a string. + + .EXAMPLE + 'VGhpc0lzQU5pY2VTdHJpbmc=' | ConvertFrom-Base64 + ThisIsANiceString + + Converts the Base64 encoded string 'VGhpc0lzQU5pY2VTdHJpbmc=' to a string. + + .EXAMPLE + ConvertFrom-Base64String -String 'SABlAGwAbABvACAAVwBvAHIAbABkAA==' + Hello World + + Converts the string from base64 to a regular string. + #> + [Alias('ConvertFrom-Base64String')] + [OutputType([string])] + [CmdletBinding()] + param( + # The Base64 encoded string to convert. + [Parameter(Mandatory)] + [string] $Base64String + ) + + if ([PSBase64]::IsValid($Base64String)) { + return [PSBase64]::ConvertFromBase64($Base64String) + } else { + throw "Invalid Base64 string" + } +} diff --git a/src/functions/public/ConvertTo-Base64.ps1 b/src/functions/public/ConvertTo-Base64.ps1 new file mode 100644 index 0000000..1fefb69 --- /dev/null +++ b/src/functions/public/ConvertTo-Base64.ps1 @@ -0,0 +1,35 @@ +filter ConvertTo-Base64 { + <# + .SYNOPSIS + Convert a string to base64 + + .DESCRIPTION + Converts a string to a Base64 encoded string. + + .EXAMPLE + ConvertTo-Base64 -String 'ThisIsANiceString' + VGhpc0lzQU5pY2VTdHJpbmc= + + Converts the string 'ThisIsANiceString' to a Base64 encoded string. + + .EXAMPLE + 'Hello World' | ConvertTo-Base64 + + SABlAGwAbABvACAAVwBvAHIAbABkAA== + + Converts the string 'Hello World' to base64. + #> + [Alias('ConvertTo-Base64String')] + [OutputType([string])] + [CmdletBinding()] + param( + # The string to convert to base64 + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [string] $String + ) + return [PSBase64]::ConvertToBase64($String) +} diff --git a/src/functions/public/Get-PSModuleTest.ps1 b/src/functions/public/Get-PSModuleTest.ps1 deleted file mode 100644 index 0e9aacf..0000000 --- a/src/functions/public/Get-PSModuleTest.ps1 +++ /dev/null @@ -1,20 +0,0 @@ -#Requires -Modules Utilities - -function Get-PSModuleTest { - <# - .SYNOPSIS - Performs tests on a module. - - .EXAMPLE - Test-PSModule -Name 'World' - - "Hello, World!" - #> - [CmdletBinding()] - param ( - # Name of the person to greet. - [Parameter(Mandatory)] - [string] $Name - ) - Write-Output "Hello, $Name!" -} diff --git a/src/functions/public/New-Base64.ps1 b/src/functions/public/New-Base64.ps1 new file mode 100644 index 0000000..cb5dbc1 --- /dev/null +++ b/src/functions/public/New-Base64.ps1 @@ -0,0 +1,11 @@ +function New-Base64 { + [CmdletBinding()] + param ( + [Parameter(Mandatory)] + [string] $InputString + ) + + return [PSBase64]::new($InputString) +} + +New-Base64 -InputString 'ThisIsANiceString' diff --git a/src/functions/public/Test-Base64.ps1 b/src/functions/public/Test-Base64.ps1 new file mode 100644 index 0000000..365e13c --- /dev/null +++ b/src/functions/public/Test-Base64.ps1 @@ -0,0 +1,22 @@ +function Test-Base64 { + <# + .SYNOPSIS + Test if a string is a valid Base64 string. + + .DESCRIPTION + Test if a string is a valid Base64 string. + + .EXAMPLE + Test-Base64 -Base64String 'U29tZSBkYXRh' + True + + Returns $true as the string is a valid Base64 string. + #> + [OutputType([bool])] + [CmdletBinding()] + param ( + [string] $Base64String + ) + + return [PSBase64]::IsValid($Base64String) +} diff --git a/tests/Module.Tests.ps1 b/tests/Module.Tests.ps1 index d329e70..75bbd34 100644 --- a/tests/Module.Tests.ps1 +++ b/tests/Module.Tests.ps1 @@ -1,14 +1,15 @@ Describe 'Module' { - It 'Function: Get-PSModuleTest' { - Get-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' - } - It 'Function: New-PSModuleTest' { - New-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' - } - It 'Function: Set-PSModuleTest' { - Set-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' - } - It 'Function: Test-PSModuleTest' { - Test-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + Context 'Base64' { + It 'Creates a base64 object' { + $base64 = New-Base64 -InputString 'ThisIsANiceString' + $base64.Base64 | Should -Be 'VGhpc0lzQU5pY2VTdHJpbmc=' + } + + It 'Encodes and decodes a string' { + $string = 'Hello, World!' + $encoded = $string | ConvertTo-Base64 + $decoded = $encoded | ConvertFrom-Base64 + $decoded | Should -Be $string + } } } From 6685c284af5765713afa6133475b08a7b27303ec Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Nov 2024 13:49:57 +0100 Subject: [PATCH 2/6] Add tests for Base64 encoding and decoding functionality --- tests/Module.Tests.ps1 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/Module.Tests.ps1 b/tests/Module.Tests.ps1 index 75bbd34..0295458 100644 --- a/tests/Module.Tests.ps1 +++ b/tests/Module.Tests.ps1 @@ -4,12 +4,21 @@ $base64 = New-Base64 -InputString 'ThisIsANiceString' $base64.Base64 | Should -Be 'VGhpc0lzQU5pY2VTdHJpbmc=' } - + It 'Encodes and decodes a string' { $string = 'Hello, World!' $encoded = $string | ConvertTo-Base64 $decoded = $encoded | ConvertFrom-Base64 $decoded | Should -Be $string } + + It 'Can test if a string is base64 encoded' { + $string = 'Hello, World!' + $encoded = $string | ConvertTo-Base64 + $decoded = $encoded | ConvertFrom-Base64 + $string | Test-Base64 | Should -Be $false + $encoded | Test-Base64 | Should -Be $true + $decoded | Test-Base64 | Should -Be $false + } } } From f164cb92095aa506c5fc00a3b5fc9350ca275d5d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Nov 2024 13:52:24 +0100 Subject: [PATCH 3/6] Fix issues --- src/functions/public/New-Base64.ps1 | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/functions/public/New-Base64.ps1 b/src/functions/public/New-Base64.ps1 index cb5dbc1..a668b4b 100644 --- a/src/functions/public/New-Base64.ps1 +++ b/src/functions/public/New-Base64.ps1 @@ -1,11 +1,24 @@ function New-Base64 { - [CmdletBinding()] + <# + .SYNOPSIS + Create a new Base64 object + + .DESCRIPTION + Create a new Base64 object + + .EXAMPLE + New-Base64 -InputString 'ThisIsANiceString' + VGhpc0lzQU5pY2VTdHJpbmc= + + Create a new Base64 object from the string 'ThisIsANiceString' + #> + [CmdletBinding(SupportsShouldProcess)] param ( [Parameter(Mandatory)] [string] $InputString ) - return [PSBase64]::new($InputString) + if ($PSCmdlet.ShouldProcess("PSBase64 class", "Create")) { + return [PSBase64]::new($InputString) + } } - -New-Base64 -InputString 'ThisIsANiceString' From 1431effb0c3a62b7c9596b9a234d722f569d3386 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Nov 2024 13:59:44 +0100 Subject: [PATCH 4/6] Refactor Base64 functions to use filters and remove unused files --- src/formats/PSBase64.Format.ps1xml | 20 ----------------- src/functions/public/ConvertFrom-Base64.ps1 | 7 ++++-- src/functions/public/New-Base64.ps1 | 24 --------------------- src/functions/public/Test-Base64.ps1 | 6 +++++- 4 files changed, 10 insertions(+), 47 deletions(-) delete mode 100644 src/formats/PSBase64.Format.ps1xml delete mode 100644 src/functions/public/New-Base64.ps1 diff --git a/src/formats/PSBase64.Format.ps1xml b/src/formats/PSBase64.Format.ps1xml deleted file mode 100644 index 8b0f644..0000000 --- a/src/formats/PSBase64.Format.ps1xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - PSBase64CustomControl - - PSBase64 - - - - - - Base64 - - - - - - - diff --git a/src/functions/public/ConvertFrom-Base64.ps1 b/src/functions/public/ConvertFrom-Base64.ps1 index d5d892a..3677566 100644 --- a/src/functions/public/ConvertFrom-Base64.ps1 +++ b/src/functions/public/ConvertFrom-Base64.ps1 @@ -1,4 +1,4 @@ -function ConvertFrom-Base64 { +filter ConvertFrom-Base64 { <# .SYNOPSIS Convert to string from base64 @@ -23,7 +23,10 @@ [CmdletBinding()] param( # The Base64 encoded string to convert. - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipeline + )] [string] $Base64String ) diff --git a/src/functions/public/New-Base64.ps1 b/src/functions/public/New-Base64.ps1 deleted file mode 100644 index a668b4b..0000000 --- a/src/functions/public/New-Base64.ps1 +++ /dev/null @@ -1,24 +0,0 @@ -function New-Base64 { - <# - .SYNOPSIS - Create a new Base64 object - - .DESCRIPTION - Create a new Base64 object - - .EXAMPLE - New-Base64 -InputString 'ThisIsANiceString' - VGhpc0lzQU5pY2VTdHJpbmc= - - Create a new Base64 object from the string 'ThisIsANiceString' - #> - [CmdletBinding(SupportsShouldProcess)] - param ( - [Parameter(Mandatory)] - [string] $InputString - ) - - if ($PSCmdlet.ShouldProcess("PSBase64 class", "Create")) { - return [PSBase64]::new($InputString) - } -} diff --git a/src/functions/public/Test-Base64.ps1 b/src/functions/public/Test-Base64.ps1 index 365e13c..aedf91f 100644 --- a/src/functions/public/Test-Base64.ps1 +++ b/src/functions/public/Test-Base64.ps1 @@ -1,4 +1,4 @@ -function Test-Base64 { +filter Test-Base64 { <# .SYNOPSIS Test if a string is a valid Base64 string. @@ -15,6 +15,10 @@ [OutputType([bool])] [CmdletBinding()] param ( + [Parameter( + Mandatory, + ValueFromPipeline + )] [string] $Base64String ) From 58b1a676c65931e63390e0119c61c7a180656cc6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Nov 2024 14:14:38 +0100 Subject: [PATCH 5/6] Refactor Base64 implementation by removing the PSBase64 class and updating conversion functions to use direct .NET methods; enhance validation in ConvertFrom-Base64 and add tests for encoding and decoding functions. --- src/classes/public/Base64.ps1 | 28 --------------- src/functions/public/ConvertFrom-Base64.ps1 | 7 ++-- src/functions/public/ConvertTo-Base64.ps1 | 2 +- src/functions/public/Test-Base64.ps1 | 13 ++++++- tests/Module.Tests.ps1 | 38 ++++++++++++--------- 5 files changed, 36 insertions(+), 52 deletions(-) delete mode 100644 src/classes/public/Base64.ps1 diff --git a/src/classes/public/Base64.ps1 b/src/classes/public/Base64.ps1 deleted file mode 100644 index e9d6199..0000000 --- a/src/classes/public/Base64.ps1 +++ /dev/null @@ -1,28 +0,0 @@ -class PSBase64 { - [string] $Base64 - - PSBase64([string] $Value) { - $this.Base64 = [PSBase64]::ConvertToBase64($Value) - } - - [string] ToString() { - return [PSBase64]::ConvertFromBase64($this.Base64) - } - - static [string] ConvertFromBase64([string] $Base64String) { - return [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($Base64String)) - } - - static [string] ConvertToBase64([string] $String) { - return [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($String)) - } - - static [bool] IsValid([string] $Base64String) { - try { - $null = [Convert]::FromBase64String($Base64String) - return $true - } catch { - return $false - } - } -} diff --git a/src/functions/public/ConvertFrom-Base64.ps1 b/src/functions/public/ConvertFrom-Base64.ps1 index 3677566..e6ff1df 100644 --- a/src/functions/public/ConvertFrom-Base64.ps1 +++ b/src/functions/public/ConvertFrom-Base64.ps1 @@ -27,12 +27,9 @@ Mandatory, ValueFromPipeline )] + [ValidateScript({ Test-Base64 -Base64String $_ }, ErrorMessage = 'Invalid Base64 string')] [string] $Base64String ) - if ([PSBase64]::IsValid($Base64String)) { - return [PSBase64]::ConvertFromBase64($Base64String) - } else { - throw "Invalid Base64 string" - } + return [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($Base64String)) } diff --git a/src/functions/public/ConvertTo-Base64.ps1 b/src/functions/public/ConvertTo-Base64.ps1 index 1fefb69..3baf5e7 100644 --- a/src/functions/public/ConvertTo-Base64.ps1 +++ b/src/functions/public/ConvertTo-Base64.ps1 @@ -31,5 +31,5 @@ )] [string] $String ) - return [PSBase64]::ConvertToBase64($String) + return [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($String)) } diff --git a/src/functions/public/Test-Base64.ps1 b/src/functions/public/Test-Base64.ps1 index aedf91f..7f59f65 100644 --- a/src/functions/public/Test-Base64.ps1 +++ b/src/functions/public/Test-Base64.ps1 @@ -11,6 +11,12 @@ True Returns $true as the string is a valid Base64 string. + + .EXAMPLE + 'U29tZSBkYXRh' | Test-Base64 + True + + Returns $true as the string is a valid Base64 string. #> [OutputType([bool])] [CmdletBinding()] @@ -22,5 +28,10 @@ [string] $Base64String ) - return [PSBase64]::IsValid($Base64String) + try { + $null = [Convert]::FromBase64String($Base64String) + return $true + } catch { + return $false + } } diff --git a/tests/Module.Tests.ps1 b/tests/Module.Tests.ps1 index 0295458..d2d1748 100644 --- a/tests/Module.Tests.ps1 +++ b/tests/Module.Tests.ps1 @@ -1,24 +1,28 @@ -Describe 'Module' { - Context 'Base64' { - It 'Creates a base64 object' { - $base64 = New-Base64 -InputString 'ThisIsANiceString' - $base64.Base64 | Should -Be 'VGhpc0lzQU5pY2VTdHJpbmc=' +Describe 'Base64' { + Context 'Function: Test-Base64' { + It "Test-Base64 -Base64String 'U29tZSBkYXRh' -> true" { + Test-Base64 -Base64String 'U29tZSBkYXRh' | Should -Be $true + } + It "'U29tZSBkYXRh' | Test-Base64 -> true" { + 'U29tZSBkYXRh' | Test-Base64 | Should -Be $true + } + } + Context 'Function: ConvertTo-Base64' { + It "ConvertTo-Base64 -String 'ThisIsANiceString' -> VGhpc0lzQU5pY2VTdHJpbmc=" { + ConvertTo-Base64 -String 'ThisIsANiceString' | Should -Be 'VGhpc0lzQU5pY2VTdHJpbmc=' } - It 'Encodes and decodes a string' { - $string = 'Hello, World!' - $encoded = $string | ConvertTo-Base64 - $decoded = $encoded | ConvertFrom-Base64 - $decoded | Should -Be $string + It "'Hello World' | ConvertTo-Base64 -> SABlAGwAbABvACAAVwBvAHIAbABkAA==" { + 'Hello World' | ConvertTo-Base64 | Should -Be 'SABlAGwAbABvACAAVwBvAHIAbABkAA==' + } + } + Context 'Function: ConvertFrom-Base64' { + It "'VGhpc0lzQU5pY2VTdHJpbmc=' | ConvertFrom-Base64 -> ThisIsANiceString" { + 'VGhpc0lzQU5pY2VTdHJpbmc=' | ConvertFrom-Base64 | Should -Be 'ThisIsANiceString' } - It 'Can test if a string is base64 encoded' { - $string = 'Hello, World!' - $encoded = $string | ConvertTo-Base64 - $decoded = $encoded | ConvertFrom-Base64 - $string | Test-Base64 | Should -Be $false - $encoded | Test-Base64 | Should -Be $true - $decoded | Test-Base64 | Should -Be $false + It "ConvertFrom-Base64 -Base64String 'SABlAGwAbABvACAAVwBvAHIAbABkAA==' -> Hello World" { + ConvertFrom-Base64 -Base64String 'SABlAGwAbABvACAAVwBvAHIAbABkAA==' | Should -Be 'Hello World' } } } From 6b08587a7f5de19170c93692f5a25290b3f537d0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 30 Nov 2024 14:28:34 +0100 Subject: [PATCH 6/6] Fix --- src/functions/public/ConvertFrom-Base64.ps1 | 10 +++++----- src/functions/public/ConvertTo-Base64.ps1 | 7 +++---- src/functions/public/Test-Base64.ps1 | 8 ++++---- tests/Module.Tests.ps1 | 20 ++++++++++---------- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/functions/public/ConvertFrom-Base64.ps1 b/src/functions/public/ConvertFrom-Base64.ps1 index e6ff1df..fa00cfc 100644 --- a/src/functions/public/ConvertFrom-Base64.ps1 +++ b/src/functions/public/ConvertFrom-Base64.ps1 @@ -4,16 +4,16 @@ Convert to string from base64 .DESCRIPTION - Converts a Base64 encoded string to a string. + Converts a base64 encoded string to a string. .EXAMPLE - 'VGhpc0lzQU5pY2VTdHJpbmc=' | ConvertFrom-Base64 + ConvertFrom-Base64 -Base64String 'VGhpc0lzQU5pY2VTdHJpbmc=' ThisIsANiceString - Converts the Base64 encoded string 'VGhpc0lzQU5pY2VTdHJpbmc=' to a string. + Converts the base64 encoded string 'VGhpc0lzQU5pY2VTdHJpbmc=' to a string. .EXAMPLE - ConvertFrom-Base64String -String 'SABlAGwAbABvACAAVwBvAHIAbABkAA==' + 'SGVsbG8gV29ybGQ=' | ConvertFrom-Base64String Hello World Converts the string from base64 to a regular string. @@ -22,7 +22,7 @@ [OutputType([string])] [CmdletBinding()] param( - # The Base64 encoded string to convert. + # The base64 encoded string to convert. [Parameter( Mandatory, ValueFromPipeline diff --git a/src/functions/public/ConvertTo-Base64.ps1 b/src/functions/public/ConvertTo-Base64.ps1 index 3baf5e7..05a1fd6 100644 --- a/src/functions/public/ConvertTo-Base64.ps1 +++ b/src/functions/public/ConvertTo-Base64.ps1 @@ -4,18 +4,17 @@ Convert a string to base64 .DESCRIPTION - Converts a string to a Base64 encoded string. + Converts a string to a base64 encoded string. .EXAMPLE ConvertTo-Base64 -String 'ThisIsANiceString' VGhpc0lzQU5pY2VTdHJpbmc= - Converts the string 'ThisIsANiceString' to a Base64 encoded string. + Converts the string 'ThisIsANiceString' to a base64 encoded string. .EXAMPLE 'Hello World' | ConvertTo-Base64 - - SABlAGwAbABvACAAVwBvAHIAbABkAA== + SGVsbG8gV29ybGQ= Converts the string 'Hello World' to base64. #> diff --git a/src/functions/public/Test-Base64.ps1 b/src/functions/public/Test-Base64.ps1 index 7f59f65..ade81cd 100644 --- a/src/functions/public/Test-Base64.ps1 +++ b/src/functions/public/Test-Base64.ps1 @@ -1,22 +1,22 @@ filter Test-Base64 { <# .SYNOPSIS - Test if a string is a valid Base64 string. + Test if a string is a valid base64 string. .DESCRIPTION - Test if a string is a valid Base64 string. + Test if a string is a valid base64 string. .EXAMPLE Test-Base64 -Base64String 'U29tZSBkYXRh' True - Returns $true as the string is a valid Base64 string. + Returns $true as the string is a valid base64 string. .EXAMPLE 'U29tZSBkYXRh' | Test-Base64 True - Returns $true as the string is a valid Base64 string. + Returns $true as the string is a valid base64 string. #> [OutputType([bool])] [CmdletBinding()] diff --git a/tests/Module.Tests.ps1 b/tests/Module.Tests.ps1 index d2d1748..457967d 100644 --- a/tests/Module.Tests.ps1 +++ b/tests/Module.Tests.ps1 @@ -1,10 +1,10 @@ Describe 'Base64' { Context 'Function: Test-Base64' { - It "Test-Base64 -Base64String 'U29tZSBkYXRh' -> true" { - Test-Base64 -Base64String 'U29tZSBkYXRh' | Should -Be $true + It "Test-Base64 -Base64String 'VGhpc0lzQU5pY2VTdHJpbmc=' -> true" { + Test-Base64 -Base64String 'VGhpc0lzQU5pY2VTdHJpbmc=' | Should -Be $true } - It "'U29tZSBkYXRh' | Test-Base64 -> true" { - 'U29tZSBkYXRh' | Test-Base64 | Should -Be $true + It "'SGVsbG8gV29ybGQ=' | Test-Base64 -> true" { + 'SGVsbG8gV29ybGQ=' | Test-Base64 | Should -Be $true } } Context 'Function: ConvertTo-Base64' { @@ -12,17 +12,17 @@ ConvertTo-Base64 -String 'ThisIsANiceString' | Should -Be 'VGhpc0lzQU5pY2VTdHJpbmc=' } - It "'Hello World' | ConvertTo-Base64 -> SABlAGwAbABvACAAVwBvAHIAbABkAA==" { - 'Hello World' | ConvertTo-Base64 | Should -Be 'SABlAGwAbABvACAAVwBvAHIAbABkAA==' + It "'Hello World' | ConvertTo-Base64 -> SGVsbG8gV29ybGQ=" { + 'Hello World' | ConvertTo-Base64 | Should -Be 'SGVsbG8gV29ybGQ=' } } Context 'Function: ConvertFrom-Base64' { - It "'VGhpc0lzQU5pY2VTdHJpbmc=' | ConvertFrom-Base64 -> ThisIsANiceString" { - 'VGhpc0lzQU5pY2VTdHJpbmc=' | ConvertFrom-Base64 | Should -Be 'ThisIsANiceString' + It "ConvertFrom-Base64 -Base64String 'VGhpc0lzQU5pY2VTdHJpbmc=' -> ThisIsANiceString" { + ConvertFrom-Base64 -Base64String 'VGhpc0lzQU5pY2VTdHJpbmc=' | Should -Be 'ThisIsANiceString' } - It "ConvertFrom-Base64 -Base64String 'SABlAGwAbABvACAAVwBvAHIAbABkAA==' -> Hello World" { - ConvertFrom-Base64 -Base64String 'SABlAGwAbABvACAAVwBvAHIAbABkAA==' | Should -Be 'Hello World' + It "'SGVsbG8gV29ybGQ=' | ConvertFrom-Base64 -> Hello World" { + 'SGVsbG8gV29ybGQ=' | ConvertFrom-Base64 | Should -Be 'Hello World' } } }