Skip to content

Commit c2fc34e

Browse files
committed
Github Analyze fixes
WE2-965 Signed-off-by: Sven Mitt <[email protected]>
1 parent 2c24ca6 commit c2fc34e

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

src/WebEid.Security.Tests/Validator/AuthTokenValidationConfigurationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void AuthTokenValidationConfigurationWithoutSiteOriginThrowsArgumentExcep
3939
{
4040
var configuration = new AuthTokenValidationConfiguration();
4141
Assert.Throws<ArgumentNullException>(() => configuration.Validate())
42-
.WithMessage("Value cannot be null. (Parameter 'SiteOrigin')");
42+
.WithMessage("Value cannot be null. (Parameter 'siteOrigin')");
4343
}
4444

4545
[Test]

src/WebEid.Security.Tests/Validator/AuthTokenValidatorBuilderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class AuthTokenValidatorBuilderTest
3636
[Test]
3737
public void WhenOriginMissingThenBuildingFails() =>
3838
Assert.Throws<ArgumentNullException>(() => this.builder.Build())
39-
.WithMessage("Value cannot be null. (Parameter 'SiteOrigin')");
39+
.WithMessage("Value cannot be null. (Parameter 'siteOrigin')");
4040

4141
[Test]
4242
public void WhenRootCertificateAuthorityMissingThenBuildingFails()

src/WebEid.Security/Validator/AuthTokenValidationConfiguration.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ private AuthTokenValidationConfiguration(AuthTokenValidationConfiguration other)
107107

108108
private static void RequirePositiveTimeSpan(TimeSpan timeSpan, string fieldName)
109109
{
110-
if (timeSpan == null)
111-
{
112-
throw new ArgumentNullException($"{fieldName} must not be null");
113-
}
114-
115110
if (timeSpan.IsNegativeOrZero())
116111
{
117112
throw new ArgumentOutOfRangeException(nameof(timeSpan), $"{fieldName} must be greater than zero");
@@ -125,9 +120,7 @@ private static void RequirePositiveTimeSpan(TimeSpan timeSpan, string fieldName)
125120
/// <exception cref="ArgumentException">When required parameters are null</exception>
126121
public void Validate()
127122
{
128-
if (this.SiteOrigin == null)
129-
{ throw new ArgumentNullException(nameof(this.SiteOrigin)); }
130-
ValidateIsOriginURL(this.SiteOrigin);
123+
ValidateSiteOriginURL(this.SiteOrigin);
131124

132125
if (!this.TrustedCaCertificates.Any())
133126
{ throw new ArgumentException("At least one trusted certificate authority must be provided"); }
@@ -142,17 +135,23 @@ public void Validate()
142135
/// Validates that the given URI is an origin URL as defined in <a href="https://developer.mozilla.org/en-US/docs/Web/API/Location/origin">MDN</a>,
143136
/// in the form of <![CDATA[<code> <scheme> "://" <hostname> [ ":" <port> ]</code>]]>.
144137
/// </summary>
145-
/// <param name="uri">URI with origin URL</param>
138+
/// <param name="siteOrigin">URI with origin URL</param>
139+
/// <exception cref="ArgumentNullException">When siteOrigin parameter is null</exception>
146140
/// <exception cref="ArgumentException">When the URI is not in the form of origin URL</exception>
147-
private static void ValidateIsOriginURL(Uri uri)
141+
private static void ValidateSiteOriginURL(Uri siteOrigin)
148142
{
143+
if (siteOrigin == null)
144+
{
145+
throw new ArgumentNullException(nameof(siteOrigin));
146+
}
147+
149148
try
150149
{
151150
// 1. Verify that the URI can be converted to absolute URL.
152-
if (!uri.IsAbsoluteUri)
151+
if (!siteOrigin.IsAbsoluteUri)
153152
{ throw new ArgumentException("Provided URI is not a valid URL"); }
154153
// 2. Verify that the URI contains only HTTPS scheme, host and optional port components.
155-
if (!new Uri($"https://{uri.Host}:{uri.Port}").Equals(uri))
154+
if (!new Uri($"https://{siteOrigin.Host}:{siteOrigin.Port}").Equals(siteOrigin))
156155
{ throw new ArgumentException("Origin URI must only contain the HTTPS scheme, host and optional port component"); }
157156
}
158157
catch (InvalidOperationException e)

src/WebEid.Security/Validator/Ocsp/Service/AiaOcspService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ public AiaOcspService(AiaOcspServiceConfiguration configuration,
4242
{
4343
throw new ArgumentNullException(nameof(configuration));
4444
}
45-
this.AccessLocation = this.GetOcspAiaUrlFromCertificate(certificate);
45+
this.AccessLocation = GetOcspAiaUrlFromCertificate(certificate);
4646
this.trustedCaCertificates = configuration.TrustedCaCertificates;
4747
this.DoesSupportNonce = !configuration.NonceDisabledOcspUrls.Contains(this.AccessLocation);
4848
}
4949

5050
public bool DoesSupportNonce { get; }
5151
public Uri AccessLocation { get; }
5252

53-
private Uri GetOcspAiaUrlFromCertificate(Org.BouncyCastle.X509.X509Certificate certificate)
53+
private static Uri GetOcspAiaUrlFromCertificate(Org.BouncyCastle.X509.X509Certificate certificate)
5454
{
5555
if (certificate == null)
5656
{ throw new ArgumentNullException(nameof(certificate)); }

0 commit comments

Comments
 (0)