Skip to content

Commit

Permalink
Refactor (#8)
Browse files Browse the repository at this point in the history
- Switch to [Import-ConfigData](https://github.com/cdhunt/Import-ConfigData) for Toml parsing
  - Which also brings PSD1 and YAML support
- Better handle of SSL failures
- Adds basic functional tests
- Updates CI
- Updates Docs
  • Loading branch information
cdhunt authored Dec 14, 2023
1 parent 724953c commit 9202275
Show file tree
Hide file tree
Showing 17 changed files with 814 additions and 1,867 deletions.
134 changes: 134 additions & 0 deletions .github/workflows/powershell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: PowerShell

on:
push:
branches: [ "main" ]
paths-ignore:
- 'docs/**'
- 'Changelog.md'
- 'README.md'
- src/internal/Export-HelpToMd.ps1
pull_request:
branches: [ "main" ]

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
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.

- 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: .\src
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@v2
with:
sarif_file: results.sarif

- uses: dotnet/nbgv@1801854259a50d987aaa03b99b28cebf49faa779
id: nbgv

- name: Build
shell: pwsh
run: ./build.ps1 build ${{ steps.nbgv.outputs.VersionMajor }} ${{ steps.nbgv.outputs.VersionMinor }} ${{ steps.nbgv.outputs.BuildNumber }} ${{ steps.nbgv.outputs.VersionRevision }} ${{ steps.nbgv.outputs.PrereleaseVersionNoLeadingHyphen }}

- name: Store build output
uses: actions/upload-artifact@v3
with:
name: build
path: |
publish
retention-days: 1

test7:
permissions:
contents: read # for actions/checkout to fetch code
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
name: Test PowerShell 7
needs: Build
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/powershell:${{ matrix.pwshv }}-ubuntu-22.04
strategy:
matrix:
pwshv: ['7.3','7.4']

steps:
- uses: actions/checkout@v4

- name: Download build output
uses: actions/download-artifact@v3
with:
name: build
path: publish

- name: Test
shell: pwsh
run: ./build.ps1 test

test5:
permissions:
contents: read # for actions/checkout to fetch code
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
name: Test PowerShell 5
needs: Build
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download build output
uses: actions/download-artifact@v3
with:
name: build
path: publish

- name: Test
shell: powershell
run: ./build.ps1 test

publish:
permissions:
contents: read # for actions/checkout to fetch code
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
name: Publish
needs: [test7, test5]
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/dotnet/sdk:8.0
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4

- name: Download build output
uses: actions/download-artifact@v3
with:
name: build
path: publish

- name: Publish
shell: pwsh
run: ./build.ps1 publish
env:
PSPublishApiKey: ${{ secrets.NUGETAPIKEY }}
106 changes: 6 additions & 100 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ This is not a 100% accurate port of [httpunit](https://github.com/StackExchange/
The goal of this module is to utilize `Net.Http.HttpClient` to more closely simulate a .Net client application.
It also provides easy access to the Windows Certificate store for client certificate authentication.

## TOML
## Docs

[Full Docs](docs)

### TOML

This configuration file is targeting compatibility with the original [httpunit file format](https://github.com/StackExchange/httpunit/tree/master#toml) but is partially implemented.

Expand All @@ -31,7 +35,7 @@ Each `[[plan]]` lists:
- `insecureSkipVerify = true` Will allow testing of untrusted or self-signed certificates.
- `[plan.headers]` For http/https, a list of keys and values to validate the response headers.

## A sample config file
#### A sample config file

```toml
[[plan]]
Expand All @@ -42,101 +46,3 @@ Each `[[plan]]` lists:
[plan.headers]
Server = "gws"
```

## Help

### Invoke-HttpUnit

Aliases: httpunit, ihu, Test-Http

```text
SYNOPSIS
A PowerShell port of httpunit.
SYNTAX
Invoke-HttpUnit [-Url] <String> [[-Code] <String>] [[-String] <String>] [[-Headers] <Hashtable>] [[-Timeout] <TimeSpan>] [[-Certificate] <X509Certificate>]
[<CommonParameters>]
Invoke-HttpUnit [-Path] <String> [[-Tag] <String[]>] [<CommonParameters>]
DESCRIPTION
This is not a 100% accurate port of httpunit. The goal of this module is to utilize Net.Http.HttpClient to more closely simulate a .Net client application.
It also provides easy access to the Windows Certificate store for client certificate authentication.
PARAMETERS
-Path <String>
Specifies a path to a TOML file with a list of tests.
Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false
-Tag <String[]>
If specified, only runs plans that are tagged with one of the
tags specified.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Url <String>
The URL to retrieve.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Code <String>
For http/https, the expected status code, default 200.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-String <String>
For http/https, a string we expect to find in the result.
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Headers <Hashtable>
For http/https, a hashtable to validate the response headers.
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Timeout <TimeSpan>
A timeout for the test. Default is 3 seconds.
Required? false
Position? 5
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Certificate <X509Certificate>
For http/https, specifies the client certificate that is used for a secure web request. Enter a variable that contains a certificate.
Required? false
Position? 6
Default value
Accept pipeline input? false
Accept wildcard characters? false
```
Loading

0 comments on commit 9202275

Please sign in to comment.