Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
46 changes: 46 additions & 0 deletions .github/workflows/PSScriptAnalyzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
#
# https://github.com/microsoft/action-psscriptanalyzer
# For more information on PSScriptAnalyzer in general, see
# https://github.com/PowerShell/PSScriptAnalyzer

name: PSScriptAnalyzer

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
name: PSScriptAnalyzer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Run PSScriptAnalyzer
uses: microsoft/psscriptanalyzer-action@6b2948b1944407914a58661c49941824d149734f
with:
# Check https://github.com/microsoft/action-psscriptanalyzer for more info about the options.
# The below set up runs PSScriptAnalyzer to your entire repository and runs some basic security rules.
path: .\
recurse: true
# Include your own basic security rules. Removing this option will run all the rules
#includeRule: '"PSAvoidGlobalAliases", "PSAvoidUsingConvertToSecureStringWithPlainText"'
output: results.sarif

# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
33 changes: 33 additions & 0 deletions .github/workflows/pester.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Run Pester Tests

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
pester:
runs-on: windows-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Pester
shell: pwsh
run: Install-Module -Name Pester -Force -Scope CurrentUser

- name: Run Pester Tests
run: |
# Run Pester tests with Code Coverage
Import-Module -Name Pester -Force
[PesterConfiguration] $config = Import-PowerShellDataFile -Path ".\config.pester.psd1" -ErrorAction Stop
Invoke-Pester -Configuration $config

- name: Upload code coverage report
if: ${{ success() }}
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: coverage.xml
8 changes: 4 additions & 4 deletions Functions/New-PSOneQRCode.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
BeforeAll {
Import-Module "$PSScriptRoot\..\loader.psm1" -Force
$Global:defaultQrCodePath | Remove-Item -Force -ErrorAction SilentlyContinue
Get-DefaultQrCodePath | Remove-Item -Force -ErrorAction SilentlyContinue
}

Describe 'New-PsOneQRCode' {
AfterEach {
$Global:defaultQrCodePath | Remove-Item -Force -ErrorAction SilentlyContinue
Get-DefaultQrCodePath | Remove-Item -Force -ErrorAction SilentlyContinue
}

It 'defaults to file based output' {
New-PSOneQRCode -payload 'Test' -Show $False

Get-Item $Global:defaultQrCodePath | Should -Exist
Get-Item (Get-DefaultQrCodePath) | Should -Exist
}

It 'returns the byte array when `-AsByteArray` switch is on' {
$byteArray = New-PSOneQRCode -payload 'Test' -Show $False -AsByteArray

$byteArray.Count | Should -Not -BeNullOrEmpty
Test-Path $Global:defaultQrCodePath | Should -BeFalse
Test-Path (Get-DefaultQrCodePath) | Should -BeFalse
}
}

Expand Down
18 changes: 8 additions & 10 deletions Functions/New-PSOneQRCode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function New-PSOneQRCode {

.PARAMETER AsByteArray
Returns the byte array data for in memory processing.

.EXAMPLE
New-PSOneQRCode -payload $payload -Width $width -Show -OutPath $OutPath
Creates a QR code png graphics on your desktop, and opens it with the associated program
Expand Down Expand Up @@ -50,29 +50,27 @@ function New-PSOneQRCode {

[Parameter(ParameterSetName = 'File')]
[string]
$OutPath = $Global:defaultQrCodePath,
$OutPath = (Get-DefaultQrCodePath),

[Parameter(ParameterSetName = 'ByteArray')]
[switch]
$AsByteArray,

[byte[]]
[byte[]]
$DarkColorRgba = @(0, 0, 0),

[byte[]]
$LightColorRgba = @(255, 255, 255)

)


$generator = New-Object -TypeName QRCoder.QRCodeGenerator
$data = $generator.CreateQrCode($payload, 'Q')
$code = new-object -TypeName QRCoder.PngByteQRCode -ArgumentList ($data)
$code = New-Object -TypeName QRCoder.PngByteQRCode -ArgumentList ($data)
$byteArray = $code.GetGraphic($Width, $darkColorRgba, $lightColorRgba)

if ($AsByteArray) { return $byteArray }

[System.IO.File]::WriteAllBytes($outPath, $byteArray)

if ($Show) { Invoke-Item -Path $outPath }
}
8 changes: 4 additions & 4 deletions Functions/New-PSOneQRCodeGeolocation.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
BeforeAll {
Import-Module "$PSScriptRoot\..\loader.psm1" -Force
$Global:defaultQrCodePath | Remove-Item -Force -ErrorAction SilentlyContinue
(Get-DefaultQrCodePath) | Remove-Item -Force -ErrorAction SilentlyContinue
}

Describe 'New-PSOneQRCodeGeolocation' {
AfterEach {
$Global:defaultQrCodePath | Remove-Item -Force -ErrorAction SilentlyContinue
(Get-DefaultQrCodePath) | Remove-Item -Force -ErrorAction SilentlyContinue
}

It 'defaults to file based output' {
New-PSOneQRCodeGeolocation -Address 'Test'

Get-Item $Global:defaultQrCodePath | Should -Exist
Get-Item (Get-DefaultQrCodePath) | Should -Exist
}

It 'throws when address is not found' {
Expand All @@ -22,7 +22,7 @@ Describe 'New-PSOneQRCodeGeolocation' {
$byteArray = New-PSOneQRCodeGeolocation -Address 'Test' -AsByteArray

$byteArray.Count | Should -Not -BeNullOrEmpty
Test-Path $Global:defaultQrCodePath | Should -BeFalse
Test-Path (Get-DefaultQrCodePath) | Should -BeFalse
}
}

Expand Down
18 changes: 9 additions & 9 deletions Functions/New-PSOneQRCodeGeolocation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
https://github.com/TobiasPSP/Modules.QRCodeGenerator
#>

[CmdletBinding(DefaultParameterSetName = "Address")]
[CmdletBinding(DefaultParameterSetName = 'Address')]
param
(
[Parameter(Mandatory, ParameterSetName = 'Location')]
Expand Down Expand Up @@ -64,7 +64,7 @@
[Parameter(ParameterSetName = 'Location')]
[Parameter(ParameterSetName = 'Address')]
[string]
$OutPath = $Global:defaultQrCodePath,
$OutPath = (Get-DefaultQrCodePath),

[Parameter(ParameterSetName = 'ByteArrayLocation')]
[Parameter(ParameterSetName = 'ByteArrayAddress')]
Expand All @@ -79,15 +79,15 @@

)

if ($PSCmdlet.ParameterSetName -eq "Address") {
if ($PSCmdlet.ParameterSetName -eq 'Address') {
$AddressEncoded = [System.Net.WebUtility]::UrlEncode($Address)
$ApiUri = "http://nominatim.openstreetmap.org/search?q=$AddressEncoded&format=xml&addressdetails=1&limit=1"
$Response = Invoke-RestMethod -Uri $ApiUri -UseBasicParsing

$place = $Response.searchresults.place

if ($null -eq $place) {
throw "Address not found."
throw 'Address not found.'
}
$Latitude = $place.lat
$Longitude = $place.lon
Expand All @@ -98,11 +98,11 @@ geo:$Latitude,$Longitude
"@

$splat = @{
payload = $payload
Show = $Show
Width = $Width
OutPath = $OutPath
darkColorRgba = $darkColorRgba
payload = $payload
Show = $Show
Width = $Width
OutPath = $OutPath
darkColorRgba = $darkColorRgba
lightColorRgba = $lightColorRgba
}

Expand Down
8 changes: 4 additions & 4 deletions Functions/New-PSOneQRCodeText.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
BeforeAll {
Import-Module "$PSScriptRoot\..\loader.psm1" -Force
$Global:defaultQrCodePath | Remove-Item -Force -ErrorAction SilentlyContinue
(Get-DefaultQrCodePath) | Remove-Item -Force -ErrorAction SilentlyContinue
}

Describe 'New-PSOneQRCodeText' {
AfterEach {
$Global:defaultQrCodePath | Remove-Item -Force -ErrorAction SilentlyContinue
(Get-DefaultQrCodePath) | Remove-Item -Force -ErrorAction SilentlyContinue
}

It 'defaults to file based output' {
New-PSOneQRCodeText -Text 'Test'

Get-Item $Global:defaultQrCodePath | Should -Exist
Get-Item (Get-DefaultQrCodePath) | Should -Exist
}

It 'returns the byte array when `-AsByteArray` switch is on' {
$byteArray = New-PSOneQRCodeText -Text 'Test' -AsByteArray

$byteArray.Count | Should -Not -BeNullOrEmpty
Test-Path $Global:defaultQrCodePath | Should -BeFalse
Test-Path (Get-DefaultQrCodePath) | Should -BeFalse
}
}

Expand Down
12 changes: 6 additions & 6 deletions Functions/New-PSOneQRCodeText.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

[Parameter(ParameterSetName = 'File')]
[string]
$OutPath = $Global:defaultQrCodePath,
$OutPath = (Get-DefaultQrCodePath),

[Parameter(ParameterSetName = 'ByteArray')]
[switch]
Expand All @@ -59,11 +59,11 @@
)

$splat = @{
payload = $Text
Show = $Show
Width = $Width
OutPath = $OutPath
darkColorRgba = $darkColorRgba
payload = $Text
Show = $Show
Width = $Width
OutPath = $OutPath
darkColorRgba = $darkColorRgba
lightColorRgba = $lightColorRgba
}

Expand Down
8 changes: 4 additions & 4 deletions Functions/New-PSOneQRCodeTwitter.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
BeforeAll {
Import-Module "$PSScriptRoot\..\loader.psm1" -Force
$Global:defaultQrCodePath | Remove-Item -Force -ErrorAction SilentlyContinue
(Get-DefaultQrCodePath) | Remove-Item -Force -ErrorAction SilentlyContinue
}

Describe 'New-PSOneQRCodeTwitter' {
AfterEach {
$Global:defaultQrCodePath | Remove-Item -Force -ErrorAction SilentlyContinue
(Get-DefaultQrCodePath) | Remove-Item -Force -ErrorAction SilentlyContinue
}

It 'defaults to file based output' {
New-PSOneQRCodeTwitter -ProfileName 'Test'

Get-Item $Global:defaultQrCodePath | Should -Exist
Get-Item (Get-DefaultQrCodePath) | Should -Exist
}

It 'returns the byte array when `-AsByteArray` switch is on' {
$byteArray = New-PSOneQRCodeTwitter -ProfileName 'Test' -AsByteArray

$byteArray.Count | Should -Not -BeNullOrEmpty
Test-Path $Global:defaultQrCodePath | Should -BeFalse
Test-Path (Get-DefaultQrCodePath) | Should -BeFalse
}
}

Expand Down
13 changes: 6 additions & 7 deletions Functions/New-PSOneQRCodeTwitter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

[Parameter(ParameterSetName = 'File')]
[string]
$OutPath = $Global:defaultQrCodePath,
$OutPath = (Get-DefaultQrCodePath),

[Parameter(ParameterSetName = 'ByteArray')]
[switch]
Expand All @@ -59,11 +59,11 @@
)

$splat = @{
payload = "http://www.twitter.com/$ProfileName"
Show = $Show
Width = $Width
OutPath = $OutPath
darkColorRgba = $darkColorRgba
payload = "http://www.twitter.com/$ProfileName"
Show = $Show
Width = $Width
OutPath = $OutPath
darkColorRgba = $darkColorRgba
lightColorRgba = $lightColorRgba
}

Expand All @@ -74,5 +74,4 @@
}

New-PSOneQRCode @splat

}
8 changes: 4 additions & 4 deletions Functions/New-PSOneQRCodeURI.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
BeforeAll {
Import-Module "$PSScriptRoot\..\loader.psm1" -Force
$Global:defaultQrCodePath | Remove-Item -Force -ErrorAction SilentlyContinue
(Get-DefaultQrCodePath) | Remove-Item -Force -ErrorAction SilentlyContinue
}

Describe 'New-PSOneQRCodeURI' {
AfterEach {
$Global:defaultQrCodePath | Remove-Item -Force -ErrorAction SilentlyContinue
(Get-DefaultQrCodePath) | Remove-Item -Force -ErrorAction SilentlyContinue
}

It 'defaults to file based output' {
New-PSOneQRCodeURI -URI 'http://127.0.0.1'

Get-Item $Global:defaultQrCodePath | Should -Exist
Get-Item (Get-DefaultQrCodePath) | Should -Exist
}

It 'returns the byte array when `-AsByteArray` switch is on' {
$byteArray = New-PSOneQRCodeURI -URI 'http://127.0.0.1' -AsByteArray

$byteArray.Count | Should -Not -BeNullOrEmpty
Test-Path $Global:defaultQrCodePath | Should -BeFalse
Test-Path (Get-DefaultQrCodePath) | Should -BeFalse
}
}

Expand Down
Loading