Skip to content

Commit

Permalink
Updated test to use OAuth 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
klaasvandeweerdt committed Apr 10, 2023
1 parent e3f94b6 commit 9012310
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
35 changes: 27 additions & 8 deletions Scr/Sdk4me.GraphQL.Tests/Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,42 @@ public static Sdk4meClient Get()
if (client != null)
return client;

//get account and token
//get all information
IConfigurationProvider secretProvider = new ConfigurationBuilder().AddUserSecrets<ConnectionSecret>().Build().Providers.First();
if (!secretProvider.TryGet("Account", out string? account) || !secretProvider.TryGet("Token", out string? token))
if (!secretProvider.TryGet("Account", out string? account)
|| !secretProvider.TryGet("Token", out string? token)
|| !secretProvider.TryGet("ClientID", out string? clientID)
|| !secretProvider.TryGet("ClientSecret", out string? clientSecret))
{
Assert.Fail("No account of token information available via the user secret file");
Assert.Fail("Missing information in the user secret file");
return null;
}

if (account == null || token == null)
if (account == null || token == null || clientID == null || clientSecret == null)
{
Assert.Fail("No account of token information available via the user secret file");
Assert.Fail("Null value information in the user secret file");
return null;
}

//connect to client
client = new(new AuthenticationToken(token), account, EnvironmentType.Demo, EnvironmentRegion.EU, 5);
client.MaximumQueryDepthLevelConnections = 3;
if (!string.IsNullOrEmpty(clientID) && !string.IsNullOrWhiteSpace(clientSecret))
{
client = new(new AuthenticationToken(clientID, clientSecret), account, EnvironmentType.Demo, EnvironmentRegion.EU, 5)
{
MaximumQueryDepthLevelConnections = 3
};
}
else if (!string.IsNullOrEmpty(token))
{
client = new(new AuthenticationToken(token), account, EnvironmentType.Demo, EnvironmentRegion.EU, 5)
{
MaximumQueryDepthLevelConnections = 3
};
}
else
{
Assert.Fail("Invalid information in the user secret file");
return null;
}
return client;
}
}
Expand Down
4 changes: 4 additions & 0 deletions Scr/Sdk4me.GraphQL.Tests/Client/ConnectionSecret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ internal class ConnectionSecret
public string Account { get; set; } = string.Empty;

public string Token { get; set; } = string.Empty;

public string ClientID { get; set; } = string.Empty;

public string ClientSecret { get; set; } = string.Empty;
}
}

0 comments on commit 9012310

Please sign in to comment.