Skip to content

Commit fbb1555

Browse files
Sõmermaamrts
authored andcommitted
feat(token): change the authentication token format from JWT to custom JSON, part 2
WE2-587 Signed-off-by: Mart Somermaa <[email protected]>
1 parent 1219531 commit fbb1555

File tree

121 files changed

+1418
-3185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+1418
-3185
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Dotnet Linux build
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Setup dotnet
13+
uses: actions/setup-dotnet@v1
14+
with:
15+
dotnet-version: 5.0.x # SDK Version to use.
16+
17+
- name: Cache Nuget packages
18+
uses: actions/cache@v2
19+
with:
20+
path: ~/.nuget/packages
21+
# Look to see if there is a cache hit for the corresponding requirements file
22+
key: ${{ runner.os }}-nuget-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/packages.lock.json') }}
23+
restore-keys: ${{ runner.os }}-nuget-${{ secrets.CACHE_VERSION }}
24+
25+
- name: Install dependencies
26+
run: dotnet restore src/WebEid.Security.sln
27+
28+
- name: Build
29+
run: dotnet build --configuration Release --no-restore src/WebEid.Security.sln
30+
31+
- name: Test
32+
run: dotnet test --no-restore --verbosity normal src/WebEid.Security.sln

.github/workflows/dotnet-build.yml renamed to .github/workflows/dotnet-build-windows.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Dotnet build
1+
name: Dotnet Windows build
22

33
on: [ push, pull_request ]
44

@@ -27,8 +27,8 @@ jobs:
2727
with:
2828
path: ~/.nuget/packages
2929
# Look to see if there is a cache hit for the corresponding requirements file
30-
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
31-
restore-keys: ${{ runner.os }}-nuget
30+
key: ${{ runner.os }}-nuget-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/packages.lock.json') }}
31+
restore-keys: ${{ runner.os }}-nuget-${{ secrets.CACHE_VERSION }}
3232

3333
- name: Install dependencies
3434
run: dotnet restore src/WebEid.Security.sln

.github/workflows/sonarcloud-analysis.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ jobs:
1717
with:
1818
dotnet-version: 5.0.x # SDK Version to use.
1919

20-
- name: Setup MSBuild
21-
uses: microsoft/[email protected]
22-
with:
23-
vs-version: 16.10 # Visual Studio Version to use.
24-
25-
- name: Setup VSTest
26-
uses: darenm/Setup-VSTest@v1
27-
2820
- name: Set up JDK 11
2921
uses: actions/setup-java@v1
3022
with:
@@ -69,12 +61,10 @@ jobs:
6961
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
7062
shell: powershell
7163
run: |
72-
.\.sonar\scanner\dotnet-sonarscanner begin /k:"web-eid_web-eid-authtoken-validation-dotnet" /o:"web-eid" /d:sonar.cs.opencover.reportsPaths="TestResults/**/coverage.opencover.xml" -d:sonar.cs.vstest.reportsPaths="TestResults/*.trx" /d:sonar.verbose=true /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
73-
74-
msbuild src/WebEid.Security.sln /t:Build /p:Configuration=Release
64+
.\.sonar\scanner\dotnet-sonarscanner begin /k:"web-eid_web-eid-authtoken-validation-dotnet" /o:"web-eid" /d:sonar.cs.opencover.reportsPaths="**/TestResults/**/coverage.opencover.xml" -d:sonar.cs.vstest.reportsPaths="**/TestResults/*.trx" /d:sonar.verbose=true /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
7565
76-
dotnet publish src/WebEid.Security.sln -c Release
66+
dotnet build --configuration Release --no-restore src/WebEid.Security.sln
7767
78-
vstest.console.exe src/WebEid.Security.Tests/bin/Release/net5.0/publish/WebEID.Security.Tests.dll --logger:trx --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
68+
dotnet test src/WebEid.Security.sln --logger trx --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover --results-directory "TestResults"
7969
8070
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,6 @@ MigrationBackup/
361361
# Fody - auto-generated XML schema
362362
FodyWeavers.xsd
363363
/TestsResults
364+
365+
# Vim
366+
*.swp

src/WebEid.Security.Tests/Cache/MemoryCache.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/WebEid.Security.Tests/Cache/MemoryCacheTests.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/WebEid.Security.Tests/Fakes/System.Runtime.fakes

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/WebEid.Security.Tests/Logger.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ namespace WebEid.Security.Tests
66

77
public class Logger : ILogger
88
{
9-
public Logger()
10-
{
11-
this.Logs = new List<string>();
12-
}
9+
public Logger() => this.Logs = new List<string>();
1310

1411
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
1512
{
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
namespace WebEid.Security.Tests.Nonce
2+
{
3+
using System;
4+
using System.Security.Cryptography;
5+
using NUnit.Framework;
6+
using Challenge;
7+
8+
[TestFixture]
9+
public class ChallengeNonceGeneratorTests
10+
{
11+
private IChallengeNonceStore store;
12+
private TimeSpan ttl;
13+
14+
[SetUp]
15+
protected void SetUp()
16+
{
17+
this.store = new InMemoryChallengeNonceStore();
18+
this.ttl = TimeSpan.FromMinutes(5);
19+
}
20+
21+
[Test]
22+
public void NonceIsGeneratedAndStored()
23+
{
24+
using var rndGenerator = RandomNumberGenerator.Create();
25+
var nonceGenerator = new ChallengeNonceGenerator(rndGenerator, this.store);
26+
27+
var nonce1 = nonceGenerator.GenerateAndStoreNonce(this.ttl);
28+
var nonce2 = nonceGenerator.GenerateAndStoreNonce(this.ttl);
29+
30+
var nonce2FromStore = this.store.GetAndRemove();
31+
32+
// Validate that generated nonce was put into the store.
33+
Assert.That(nonce2, Is.EqualTo(nonce2FromStore));
34+
35+
Assert.That(nonce1.Base64EncodedNonce.Length, Is.EqualTo(44));
36+
Assert.That(nonce1.Base64EncodedNonce, Is.Not.EquivalentTo(nonce2.Base64EncodedNonce));
37+
38+
// It might be possible to add an entropy test by compressing the nonce bytes
39+
// and verifying that the result is longer than for non-random strings.
40+
}
41+
42+
[Test]
43+
public void BuildNonceGeneratorWithoutRandomNumberGeneratorThrowsArgumentNullException() =>
44+
Assert.Throws<ArgumentNullException>(() => new ChallengeNonceGenerator(null, null));
45+
46+
[Test]
47+
public void BuildNonceGeneratorWithoutStoreThrowsArgumentNullException()
48+
{
49+
using var rndGenerator = RandomNumberGenerator.Create();
50+
Assert.Throws<ArgumentNullException>(() =>
51+
new ChallengeNonceGenerator(rndGenerator, null));
52+
}
53+
54+
[Test]
55+
public void BuildNonceGeneratorWithNegativeTtlThrowsArgumentOutOfRangeException()
56+
{
57+
using var rndGenerator = RandomNumberGenerator.Create();
58+
var generator = new ChallengeNonceGenerator(rndGenerator, this.store);
59+
Assert.Throws<ArgumentOutOfRangeException>(() =>
60+
generator.GenerateAndStoreNonce(TimeSpan.FromMinutes(1).Negate()));
61+
}
62+
63+
[Test]
64+
public void BuildNonceGeneratorWithZeroTtlThrowsArgumentOutOfRangeException()
65+
{
66+
using var rndGenerator = RandomNumberGenerator.Create();
67+
var generator = new ChallengeNonceGenerator(rndGenerator, this.store);
68+
Assert.Throws<ArgumentOutOfRangeException>(() =>
69+
generator.GenerateAndStoreNonce(TimeSpan.Zero));
70+
}
71+
72+
[Test]
73+
public void BuildNonceGeneratorWithRandomNumberGeneratorAndCacheDoesNotThrowException()
74+
{
75+
using var rndGenerator = RandomNumberGenerator.Create();
76+
Assert.DoesNotThrow(() => new ChallengeNonceGenerator(rndGenerator, this.store));
77+
}
78+
79+
[Test]
80+
public void BuildNonceGeneratorWithRandomNumberGeneratorAndCacheAndPositiveTtlDoesNotThrowException()
81+
{
82+
using var rndGenerator = RandomNumberGenerator.Create();
83+
var generator = new ChallengeNonceGenerator(rndGenerator, this.store);
84+
Assert.DoesNotThrow(() => generator.GenerateAndStoreNonce(TimeSpan.FromMinutes(1)));
85+
}
86+
}
87+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace WebEid.Security.Tests.Nonce
2+
{
3+
using WebEid.Security.Challenge;
4+
5+
internal class InMemoryChallengeNonceStore : IChallengeNonceStore
6+
{
7+
private ChallengeNonce challengeNonce;
8+
9+
public ChallengeNonce GetAndRemoveImpl()
10+
{
11+
var result = this.challengeNonce;
12+
this.challengeNonce = null;
13+
return result;
14+
}
15+
16+
public void Put(ChallengeNonce challengeNonce) => this.challengeNonce = challengeNonce;
17+
}
18+
}

0 commit comments

Comments
 (0)