< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)0%620%
Validate()0%4260%

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
 08public class ValidateRobotClientsCertificate(LgdxContext context)
 9{
 010  private readonly LgdxContext _context = context ?? throw new ArgumentNullException(nameof(context));
 11
 12  public async Task<bool> Validate(X509Certificate2 clientCertificate, Guid robotId)
 013  {
 014    var certificate = await _context.RobotCertificates.AsNoTracking()
 015      .FirstOrDefaultAsync(c => c.RobotId == robotId)
 016      .Select(c => new {
 017        c!.Thumbprint,
 018        c.ThumbprintBackup
 019      });
 20
 021    if (certificate == null)
 022      return false;
 023    if (certificate.Thumbprint == clientCertificate.Thumbprint)
 024      return true;
 025    if (certificate.ThumbprintBackup == clientCertificate.Thumbprint)
 026      return true;
 027    return false;
 028  }
 29}