Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Add path arg validation to Signer & Verifier #73

Merged
merged 4 commits into from
Jul 11, 2022
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/csharp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ name: C#
on:
push:
branches: [ main ]
paths:
- 'csharp/**'
- 'test-resources/**'
pull_request:
branches: [ main ]
paths:
- 'csharp/**'
- 'test-resources/**'

jobs:
test:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ name: Go
on:
push:
branches: [ main ]
paths:
- 'go/**'
- 'test-resources/**'
pull_request:
branches: [ main ]
paths:
- 'go/**'
- 'test-resources/**'

jobs:
lint:
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ name: Java

on:
push:
branches:
- '**'
branches: [ main ]
paths:
- 'java/**'
- 'test-resources/**'
tags-ignore:
- '**'
pull_request:
branches: [ main ]
paths:
- 'java/**'
- 'test-resources/**'

jobs:
build-and-test:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ name: Node
on:
push:
branches: [ main ]
paths:
- 'nodejs/**'
- 'test-resources/**'
pull_request:
branches: [ main ]
paths:
- 'nodejs/**'
- 'test-resources/**'

jobs:
test:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ on:
branches: [ main ]
tags:
- "php/v**"
paths:
- 'php/**'
- 'test-resources/**'
pull_request:
branches: [ main ]
paths:
- 'php/**'
- 'test-resources/**'

jobs:
test:
Expand Down Expand Up @@ -72,4 +78,4 @@ jobs:
path: "php"
deploy_key: ${{ secrets.DOWNSTREAM_GITHUB_DEPLOY_KEY }}
branch: ${{ steps.tag-replacer.outputs.NEW_TAG }}
force: true
force: true
6 changes: 6 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ name: Rust
on:
push:
branches: [ main ]
paths:
- 'rust/**'
- 'test-resources/**'
pull_request:
branches: [ main ]
paths:
- 'rust/**'
- 'test-resources/**'

jobs:
test:
Expand Down
3 changes: 3 additions & 0 deletions csharp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.1.10
* Add `path` arg validation to `Signer` & `Verifier` for more informative errors.

## 0.1.9
* Fix key-dependant parameter length error for .NET Standard 2.0.

Expand Down
4 changes: 4 additions & 0 deletions csharp/src/Signer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public Signer Method(string method)
/// </summary>
public Signer Path(string path)
{
if (!path.StartsWith("/"))
{
throw new ArgumentException($"Invalid path \"{path}\" must start with '/'");
}
this.path = path;
return this;
}
Expand Down
4 changes: 4 additions & 0 deletions csharp/src/Verifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public Verifier Method(string method)
/// </summary>
public Verifier Path(string path)
{
if (!path.StartsWith("/"))
{
throw new ArgumentException($"Invalid path \"{path}\" must start with '/'");
}
this.path = path;
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion csharp/src/truelayer-signing.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageVersion>0.1.9</PackageVersion>
<PackageVersion>0.1.10</PackageVersion>
<TargetFrameworks>net5.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<Nullable>enable</Nullable>
Expand Down
20 changes: 20 additions & 0 deletions csharp/test/ErrorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,25 @@ string CreateSignature(Dictionary<string, string> jwsHeaderMap)

verify.Should().Throw<SignatureException>();
}

[Fact]
public void InvalidSignerPath()
{
Action sign = () => Signer.SignWithPem(Kid, PrivateKey)
.Path("https://example.com/the-path");

sign.Should().Throw<ArgumentException>()
.WithMessage("Invalid path \"https://example.com/the-path\" must start with '/'");
}

[Fact]
public void InvalidVerifierPath()
{
Action verify = () => Verifier.VerifyWithPem(PublicKey)
.Path("https://example.com/the-path");

verify.Should().Throw<ArgumentException>()
.WithMessage("Invalid path \"https://example.com/the-path\" must start with '/'");
}
}
}