< 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: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 29
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 MassTransit.Initializers;
 3using Microsoft.EntityFrameworkCore;
 4using System.Security.Cryptography.X509Certificates;
 5
 6namespace LGDXRobotCloud.API.Authorisation;
 7
 48public class ValidateRobotClientsCertificate(LgdxContext context)
 9{
 410  private readonly LgdxContext _context = context ?? throw new ArgumentNullException(nameof(context));
 11
 12  public async Task<bool> Validate(X509Certificate2 clientCertificate, Guid robotId)
 413  {
 414    var certificate = await _context.RobotCertificates.AsNoTracking()
 415      .FirstOrDefaultAsync(c => c.RobotId == robotId)
 716      .Select(c => new {
 717        c!.Thumbprint,
 718        c.ThumbprintBackup
 719      });
 20
 421    if (certificate == null)
 122      return false;
 323    if (certificate.Thumbprint == clientCertificate.Thumbprint)
 124      return true;
 225    if (certificate.ThumbprintBackup == clientCertificate.Thumbprint)
 126      return true;
 127    return false;
 428  }
 29}