Skip to content

Commit 582ab5f

Browse files
committed
Pester upgrade & CI workflow
1 parent 1bccf8a commit 582ab5f

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

.github/workflows/test.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Invoke Pester Tests
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
invoke-pester:
11+
uses: PowerShellLibrary/.github/.github/workflows/invoke-pester.yml@master

Tests/Crypto.AES.Tests.ps1

+23-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Clear-Host
2-
Import-Module -Name Pester -Force
31
Import-Module .\Crypto.AES\Crypto.AES.psm1 -Force
42

53
Describe 'Crypto.AES.Tests' {
6-
$encoding = [System.Text.UTF8Encoding]::new()
4+
BeforeAll {
5+
$encoding = [System.Text.UTF8Encoding]::new()
6+
}
77

88
Context "AES key generation" {
99
It "Should return key as string - default" {
@@ -24,9 +24,11 @@ Describe 'Crypto.AES.Tests' {
2424
}
2525

2626
Context "Protect-Data - Result" {
27-
$Key = [byte[]]::new(32)
28-
$nonce = [byte[]]::new(12)
29-
$data = $encoding.GetBytes("Test")
27+
BeforeAll {
28+
$Key = [byte[]]::new(32)
29+
$nonce = [byte[]]::new(12)
30+
$data = $encoding.GetBytes("Test")
31+
}
3032

3133
It "has correct size" {
3234
$r_key = Protect-Data -Key $Key -Data $data -Nonce $nonce
@@ -58,14 +60,16 @@ Describe 'Crypto.AES.Tests' {
5860
}
5961

6062
Context "Protect-Data - signature" {
63+
BeforeAll {
6164
$Key = [byte[]]::new(32)
62-
$nonce = [byte[]]::new(12)
65+
$nonce = [byte[]]::new(12)
6366
$nonce[0] = 104 # random value to test with mock
64-
$data = $encoding.GetBytes("Test")
67+
$data = $encoding.GetBytes("Test")
6568

6669
Mock -CommandName Get-RandomNonce -ModuleName Crypto.AES -MockWith {
6770
Write-Output $nonce -NoEnumerate
6871
}
72+
}
6973

7074
It "optional nonce" {
7175
$r_explicit = Protect-Data -Key $Key -Data $data -Nonce $nonce
@@ -89,9 +93,11 @@ Describe 'Crypto.AES.Tests' {
8993
}
9094

9195
Context "Protect-Data - nonce" {
92-
$Key = [byte[]]::new(32)
93-
$nonce = [byte[]]::new(12)
94-
$data = $encoding.GetBytes("Test")
96+
BeforeAll {
97+
$Key = [byte[]]::new(32)
98+
$nonce = [byte[]]::new(12)
99+
$data = $encoding.GetBytes("Test")
100+
}
95101

96102
It "the same nonce" {
97103
$a = Protect-Data -Key $Key -Data $data -Nonce $nonce
@@ -115,10 +121,12 @@ Describe 'Crypto.AES.Tests' {
115121
}
116122

117123
Context "Unprotect-Data" {
118-
$Key = [byte[]]::new(32)
119-
[byte[]]$nonce = @(228, 132, 78, 5, 31, 60, 78, 70, 192, 119, 50, 184)
120-
[byte[]]$tag = @(188, 136, 244, 158, 253, 2, 183, 117, 127, 2, 193, 66, 39, 37, 94, 188)
121-
$data = @(48, 22, 117, 218 )
124+
BeforeAll {
125+
$Key = [byte[]]::new(32)
126+
[byte[]]$nonce = @(228, 132, 78, 5, 31, 60, 78, 70, 192, 119, 50, 184)
127+
[byte[]]$tag = @(188, 136, 244, 158, 253, 2, 183, 117, 127, 2, 193, 66, 39, 37, 94, 188)
128+
$data = @(48, 22, 117, 218 )
129+
}
122130

123131
It "has correct size" {
124132
$r_key = Unprotect-Data -Key $Key -Data $data -Nonce $nonce -Tag $tag

0 commit comments

Comments
 (0)