Skip to content

Commit afa7b6f

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

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
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

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Clear-Host
2-
Import-Module -Name Pester -Force
32
Import-Module .\Crypto.AES\Crypto.AES.psm1 -Force
43

54
Describe 'Crypto.AES.Tests' {
@@ -24,9 +23,11 @@ Describe 'Crypto.AES.Tests' {
2423
}
2524

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

3132
It "has correct size" {
3233
$r_key = Protect-Data -Key $Key -Data $data -Nonce $nonce
@@ -58,14 +59,16 @@ Describe 'Crypto.AES.Tests' {
5859
}
5960

6061
Context "Protect-Data - signature" {
62+
BeforeAll {
6163
$Key = [byte[]]::new(32)
62-
$nonce = [byte[]]::new(12)
64+
$nonce = [byte[]]::new(12)
6365
$nonce[0] = 104 # random value to test with mock
64-
$data = $encoding.GetBytes("Test")
66+
$data = $encoding.GetBytes("Test")
6567

6668
Mock -CommandName Get-RandomNonce -ModuleName Crypto.AES -MockWith {
6769
Write-Output $nonce -NoEnumerate
6870
}
71+
}
6972

7073
It "optional nonce" {
7174
$r_explicit = Protect-Data -Key $Key -Data $data -Nonce $nonce
@@ -89,9 +92,11 @@ Describe 'Crypto.AES.Tests' {
8992
}
9093

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

96101
It "the same nonce" {
97102
$a = Protect-Data -Key $Key -Data $data -Nonce $nonce
@@ -115,10 +120,12 @@ Describe 'Crypto.AES.Tests' {
115120
}
116121

117122
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 )
123+
BeforeAll {
124+
$Key = [byte[]]::new(32)
125+
[byte[]]$nonce = @(228, 132, 78, 5, 31, 60, 78, 70, 192, 119, 50, 184)
126+
[byte[]]$tag = @(188, 136, 244, 158, 253, 2, 183, 117, 127, 2, 193, 66, 39, 37, 94, 188)
127+
$data = @(48, 22, 117, 218 )
128+
}
122129

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

0 commit comments

Comments
 (0)