Skip to content

Commit 6e05a47

Browse files
doxthreeGermanCodingpstadermannata-no-onelennartdohmann
authored
Cs/http api (#671)
* WIP: Improve authenticator * check expiration in seconds * 1 test * Parse IDP error messages, add test * El testo * Add authenticator throttling; Add even more tests * New api * WIP: ForSha256 * Remove websocket * Option defaults * Reorder methods like interface * WIP * Remaining tests for For* * add forurl method * add mssing urlreport * ForStream * add forfile test * check options * ForFile: Check if ForSha256 returns Detection, FileType, MimeType * add options in url * CSharpier this! * Rider CSharpier * ForSha256Async_SendsOptions * fun with mocked httpclient * http mocking * WIP add more tests and error parsing for non success status codes * Fix parsing of Vaas errors with problem details * some broken test * WIP tests * add new test cases for user agent and request id * fix client exception test * Completed forfile tests * Finished test for forstream & forurl + bugfixes * exclude dotnet dirs * fix test error * remove handler mock * cleanup and remove unsused websocket stuff * use https aas vaas endpoint * Refactor: * Same usage as other SDKs * Fix override of VaasOptions if no specific options are passed * diable examples because it expects the websocket uri * Making TokenReceiver.cs class abstract, and just implement TokenRequestToForm in ClientCredentialsGrantAuthenticator/ResourceOwnerPasswordGrantAuthenticator, thus getting rid of the authenticator switch and logically separating the two * Update authenticators * Always create a new request in while loop because 'Cannot send the same request message multiple times.' * Add unit test for ForFileAsync method to verify timeout behavior * Fix tests * Refactor timeout handling to use TimeSpan instead of int for improved clarity --------- Co-authored-by: Fröhling, Maximilian <[email protected]> Co-authored-by: Philip Stadermann <[email protected]> Co-authored-by: PT-ATA No One <[email protected]> Co-authored-by: Lennart Dohmann <[email protected]> Co-authored-by: Lennart Dohmann <[email protected]>
1 parent d573caf commit 6e05a47

File tree

63 files changed

+2346
-1449
lines changed

Some content is hidden

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

63 files changed

+2346
-1449
lines changed

.github/workflows/ci-dotnet.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ on:
2828
env:
2929
CLIENT_ID: ${{ secrets.CLIENT_ID }}
3030
CLIENT_SECRET: ${{secrets.CLIENT_SECRET}}
31-
VAAS_URL: "wss://gateway.production.vaas.gdatasecurity.de"
31+
VAAS_URL: "https://gateway.production.vaas.gdatasecurity.de"
3232
TOKEN_URL: "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
3333
VAAS_CLIENT_ID: ${{ secrets.VAAS_CLIENT_ID }}
3434
VAAS_USER_NAME: ${{ secrets.VAAS_USER_NAME }}
@@ -56,7 +56,7 @@ jobs:
5656
run: |
5757
echo "CLIENT_ID=${{ secrets.STAGING_CLIENT_ID }}" >> $GITHUB_ENV
5858
echo "CLIENT_SECRET=${{ secrets.STAGING_CLIENT_SECRET }}" >> $GITHUB_ENV
59-
echo "VAAS_URL=wss://gateway.staging.vaas.gdatasecurity.de" >> $GITHUB_ENV
59+
echo "VAAS_URL=https://gateway.staging.vaas.gdatasecurity.de" >> $GITHUB_ENV
6060
echo "TOKEN_URL=https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token" >> $GITHUB_ENV
6161
echo "VAAS_CLIENT_ID=${{ secrets.STAGING_VAAS_CLIENT_ID }}" >> $GITHUB_ENV
6262
echo "VAAS_USER_NAME=${{ secrets.STAGING_VAAS_USER_NAME }}" >> $GITHUB_ENV
@@ -67,7 +67,7 @@ jobs:
6767
run: |
6868
echo "CLIENT_ID=${{ secrets.DEVELOP_CLIENT_ID }}" >> $GITHUB_ENV
6969
echo "CLIENT_SECRET=${{ secrets.DEVELOP_CLIENT_SECRET }}" >> $GITHUB_ENV
70-
echo "VAAS_URL=wss://gateway.develop.vaas.gdatasecurity.de" >> $GITHUB_ENV
70+
echo "VAAS_URL=https://gateway.develop.vaas.gdatasecurity.de" >> $GITHUB_ENV
7171
echo "TOKEN_URL=https://account-staging.gdata.de/realms/vaas-develop/protocol/openid-connect/token" >> $GITHUB_ENV
7272
echo "VAAS_CLIENT_ID=${{ secrets.DEVELOP_VAAS_CLIENT_ID }}" >> $GITHUB_ENV
7373
echo "VAAS_USER_NAME=${{ secrets.DEVELOP_VAAS_USER_NAME }}" >> $GITHUB_ENV
@@ -101,19 +101,19 @@ jobs:
101101
run: dotnet test --no-restore --verbosity normal
102102
working-directory: dotnet/Vaas
103103

104-
- name: Run example FileScan
105-
env:
106-
SCAN_PATH: "Program.cs"
107-
run: dotnet run FileScan
108-
working-directory: dotnet/examples/VaasExample
104+
# - name: Run example FileScan
105+
# env:
106+
# SCAN_PATH: "Program.cs"
107+
# run: dotnet run FileScan
108+
# working-directory: dotnet/examples/VaasExample
109109

110-
- name: Run example UrlScan
111-
run: dotnet run UrlScan
112-
working-directory: dotnet/examples/VaasExample
110+
# - name: Run example UrlScan
111+
# run: dotnet run UrlScan
112+
# working-directory: dotnet/examples/VaasExample
113113

114-
- name: Run example HashsumScan
115-
run: dotnet run HashsumScan
116-
working-directory: dotnet/examples/VaasExample
114+
# - name: Run example HashsumScan
115+
# run: dotnet run HashsumScan
116+
# working-directory: dotnet/examples/VaasExample
117117

118118
- name: Pack
119119
if: startsWith(github.ref, 'refs/tags/cs')

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ lib/
4242

4343
bin/
4444
obj/
45+
.idea/
46+
.mono/
4547

4648
# Python
4749
__pycache__/

dotnet/.devcontainer/devcontainer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
{
44
"name": "C# (.NET)",
55
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6-
"image": "mcr.microsoft.com/devcontainers/dotnet:1-6.0-bullseye",
6+
"image": "mcr.microsoft.com/devcontainers/dotnet:1-8.0-bookworm",
77
"customizations": {
88
"vscode": {
99
"extensions": [
10-
"jcamp.dotnet-test-provider-explorer"
10+
"jcamp.dotnet-test-provider-explorer",
11+
"ms-dotnettools.csdevkit"
1112
]
1213
}
1314
}

dotnet/Vaas/.idea/.idea.Vaas/.idea/CSharpierPlugin.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dotnet/Vaas/.idea/.idea.Vaas/.idea/externalDependencies.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dotnet/Vaas/Vaas.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vaas", "src\Vaas\Vaas.csproj", "{F83EA992-9DB1-43FF-89F2-836F4B325345}"
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{59EEE214-8910-4FBC-AA18-F7070B700D49}"
11+
ProjectSection(SolutionItems) = preProject
12+
test\.env = test\.env
13+
EndProjectSection
1114
EndProject
1215
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vaas.Test", "test\Vaas.Test\Vaas.Test.csproj", "{5C11F0F4-1483-4850-BB24-4A04E7EED14A}"
1316
EndProject

dotnet/Vaas/src/Vaas/Authentication/Authenticator.cs

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

dotnet/Vaas/src/Vaas/Authentication/BearerTokenHandler.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Net.Http;
4+
5+
namespace Vaas.Authentication;
6+
7+
public class ClientCredentialsGrantAuthenticator(
8+
string clientId,
9+
string clientSecret,
10+
Uri? tokenEndpoint = null,
11+
HttpClient? httpClient = null,
12+
ISystemClock? systemClock = null
13+
) : TokenReceiver(tokenEndpoint, httpClient, systemClock), IAuthenticator
14+
{
15+
private string ClientId { get; } = clientId;
16+
private string ClientSecret { get; } = clientSecret;
17+
18+
protected override FormUrlEncodedContent TokenRequestToForm()
19+
{
20+
return new FormUrlEncodedContent(
21+
new List<KeyValuePair<string, string>>
22+
{
23+
new("client_id", ClientId),
24+
new("client_secret", ClientSecret ?? throw new InvalidOperationException()),
25+
new("grant_type", "client_credentials"),
26+
}
27+
);
28+
}
29+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace Vaas.Authentication;
4+
5+
public class ErrorResponse
6+
{
7+
[JsonPropertyName("error")]
8+
public required string Error { get; init; }
9+
10+
[JsonPropertyName("error_description")]
11+
public string? ErrorDescription { get; init; }
12+
}

0 commit comments

Comments
 (0)