< Summary

Information
Class: LGDXRobotCloud.API.Authorisation.ValidateRobotClientsCertificate
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Authorisation/ValidateRobotClientsCertificate.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 30
Line coverage: 100%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%22100%
Validate()100%66100%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Authorisation/ValidateRobotClientsCertificate.cs

#LineLine coverage
 1using LGDXRobotCloud.Data.DbContexts;
 2using Microsoft.EntityFrameworkCore;
 3using System.Security.Cryptography.X509Certificates;
 4
 5namespace LGDXRobotCloud.API.Authorisation;
 6
 47public class ValidateRobotClientsCertificate(LgdxContext context)
 8{
 49  private readonly LgdxContext _context = context ?? throw new ArgumentNullException(nameof(context));
 10
 11  public async Task<bool> Validate(X509Certificate2 clientCertificate, Guid robotId)
 412  {
 413    var certificate = await _context.RobotCertificates.AsNoTracking()
 414      .Where(c => c.RobotId == robotId)
 415      .Select(c => new {
 416        c.RobotId,
 417        c!.Thumbprint,
 418        c.ThumbprintBackup
 419      })
 420      .FirstOrDefaultAsync();
 21
 422    if (certificate == null)
 123      return false;
 324    if (certificate.Thumbprint == clientCertificate.Thumbprint)
 125      return true;
 226    if (certificate.ThumbprintBackup == clientCertificate.Thumbprint)
 127      return true;
 128    return false;
 429  }
 30}