< Summary - Estud

Information
Class: Estud.Back.Features.Identity.CheckSsoAvailability.CheckSsoAvailabilityService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Identity/CheckSsoAvailability/CheckSsoAvailabilityService.cs
Tag: 114_29044117136
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 59
Line coverage: 100%
Branch coverage
70%
Covered branches: 7
Total branches: 10
Branch coverage: 70%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor()100%11100%
.cctor()100%11100%
Check()83.33%66100%
ExtractDomain(...)50%44100%

File(s)

/home/runner/work/syki/syki/Back/Features/Identity/CheckSsoAvailability/CheckSsoAvailabilityService.cs

#LineLine coverage
 1using Dapper;
 2
 3namespace Estud.Back.Features.Identity.CheckSsoAvailability;
 4
 105public class CheckSsoAvailabilityService(EstudDbContext ctx) : IEstudService
 6{
 7    private class Validator : AbstractValidator<CheckSsoAvailabilityIn>
 8    {
 29        public Validator()
 10        {
 211            RuleFor(x => x.Email).NotEmpty().WithError(InvalidEmail.I);
 1212            RuleFor(x => x.Email).Must(x => x.IsValidEmail()).WithError(InvalidEmail.I);
 213        }
 14    }
 215    private static readonly Validator V = new();
 16
 17    public async Task<OneOf<CheckSsoAvailabilityOut, EstudError>> Check(CheckSsoAvailabilityIn data)
 18    {
 1619        if (V.Run(data, out var error)) return error;
 20
 421        var domain = ExtractDomain(data.Email);
 422        if (domain == null) return new CheckSsoAvailabilityOut { SsoEnabled = false };
 23
 24        const string sql = @"
 25            SELECT
 26                c.require_sso,
 27                c.provider_type
 28            FROM
 29                estud.sso_allowed_domains d
 30            INNER JOIN
 31                estud.sso_configurations c ON c.id = d.sso_configuration_id
 32            WHERE
 33                d.domain = @Domain
 34                    AND
 35                c.is_active = true
 36            LIMIT 1
 37        ";
 38
 439        var config = await ctx.Database.GetDbConnection().QueryFirstOrDefaultAsync<SsoConfigDto>(sql, new { Domain = dom
 640        if (config == null) return new CheckSsoAvailabilityOut { SsoEnabled = false };
 41
 242        return new CheckSsoAvailabilityOut
 243        {
 244            SsoEnabled = true,
 245            SsoRequired = config.RequireSso,
 246            ProviderType = config.ProviderType,
 247        };
 1048    }
 49
 50    private static string? ExtractDomain(string email)
 51    {
 452        if (email.IsEmpty()) return null;
 53
 454        var parts = email.Split('@');
 455        if (parts.Length != 2) return null;
 56
 457        return parts[1].Trim().ToLowerInvariant();
 58    }
 59}