Skip to content

Commit

Permalink
9 translate the preferred client mode names (#10)
Browse files Browse the repository at this point in the history
* add mode translation

* Update tests

* Update Tests.cs

* Update Tests.cs

* Update Tests.cs

* Update tests

* Update TestTriggerChallenges.cs

* Update tests

coverage 77.1%

* naming convention

* fix SSLVerify setter

* Update TestValidateCheck.cs

* Update tests

* Update tests

85.9% code coverage

* Update PrivacyIDEA.cs
  • Loading branch information
lukasmatusiewicz authored Jan 11, 2023
1 parent 7eddfe9 commit 688888d
Show file tree
Hide file tree
Showing 8 changed files with 1,004 additions and 365 deletions.
10 changes: 9 additions & 1 deletion PrivacyIDEA_Client/PIResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,15 @@ public List<string> WebAuthnSignRequests()

if (jobj["detail"] is JToken detail && detail.Type is not JTokenType.Null)
{
if ((string?)detail["preferred_client_mode"] is string prefClientMode)
if ((string?)detail["preferred_client_mode"] == "poll")
{
ret.PreferredClientMode = "push";
}
else if ((string?)detail["preferred_client_mode"] == "interactive")
{
ret.PreferredClientMode = "otp";
}
else if ((string?)detail["preferred_client_mode"] is string prefClientMode)
{
ret.PreferredClientMode = prefClientMode;
}
Expand Down
23 changes: 10 additions & 13 deletions PrivacyIDEA_Client/PrivacyIDEA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ public class PrivacyIDEA : IDisposable
public string Realm { get; set; } = "";
public Dictionary<string, string> RealmMap { get; set; } = new Dictionary<string, string>();

private bool _SSLVerify = true;
private bool _sslVerify = true;
public bool SSLVerify
{
get
{
return _SSLVerify;
return _sslVerify;
}
set
{
if (SSLVerify != _SSLVerify)
if (value != _sslVerify)
{
_httpClientHandler = new HttpClientHandler();
if (SSLVerify is false)
if (value is false)
{
_httpClientHandler.ClientCertificateOptions = ClientCertificateOption.Manual;
_httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
}
_httpClient = new HttpClient(_httpClientHandler);
_httpClient.DefaultRequestHeaders.Add("User-Agent", _userAgent);
_SSLVerify = SSLVerify;
_sslVerify = value;
}
}
}
}

private HttpClientHandler _httpClientHandler;
Expand All @@ -53,10 +53,10 @@ public bool SSLVerify
private static readonly List<String> _logExcludedEndpoints = new(new string[]
{ "/auth", "/validate/polltransaction" });

public PrivacyIDEA(string url, string useragent, bool sslVerify = true)
public PrivacyIDEA(string url, string userAgent, bool sslVerify = true)
{
this.Url = url;
this._userAgent = useragent;
this._userAgent = userAgent;

_httpClientHandler = new HttpClientHandler();
if (sslVerify is false)
Expand All @@ -65,7 +65,7 @@ public PrivacyIDEA(string url, string useragent, bool sslVerify = true)
_httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
}
_httpClient = new HttpClient(_httpClientHandler);
_httpClient.DefaultRequestHeaders.Add("User-Agent", useragent);
_httpClient.DefaultRequestHeaders.Add("User-Agent", userAgent);
}

/// <summary>
Expand Down Expand Up @@ -355,10 +355,7 @@ public void SetServiceAccount(string user, string pass, string realm = "")
{
_serviceUser = user;
_servicePass = pass;
if (string.IsNullOrEmpty(realm) is false)
{
_serviceRealm = realm;
}
_serviceRealm = realm ?? "";
}

private Task<string> SendRequest(string endpoint, Dictionary<string, string> parameters, string method,
Expand Down
2 changes: 1 addition & 1 deletion PrivacyIDEA_Client/PrivacyIDEA_Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>

</Project>
Loading

0 comments on commit 688888d

Please sign in to comment.