< Summary - Syki

Information
Class: Syki.Back.Features.Identity.CheckSsoAvailability.CheckSsoAvailabilityService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Identity/CheckSsoAvailability/CheckSsoAvailabilityService.cs
Tag: 97_27801654829
Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 59
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
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(...)100%210%
.ctor()100%210%
.cctor()100%210%
Check()0%4260%
ExtractDomain(...)0%2040%

File(s)

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

#LineLine coverage
 1using Dapper;
 2
 3namespace Syki.Back.Features.Identity.CheckSsoAvailability;
 4
 05public class CheckSsoAvailabilityService(SykiDbContext ctx) : ISykiService
 6{
 7    private class Validator : AbstractValidator<CheckSsoAvailabilityIn>
 8    {
 09        public Validator()
 10        {
 011            RuleFor(x => x.Email).NotEmpty().WithError(InvalidEmail.I);
 012            RuleFor(x => x.Email).Must(x => x.IsValidEmail()).WithError(InvalidEmail.I);
 013        }
 14    }
 015    private static readonly Validator V = new();
 16
 17    public async Task<OneOf<CheckSsoAvailabilityOut, SykiError>> Check(CheckSsoAvailabilityIn data)
 18    {
 019        if (V.Run(data, out var error)) return error;
 20
 021        var domain = ExtractDomain(data.Email);
 022        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                syki.sso_allowed_domains d
 30            INNER JOIN
 31                syki.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
 039        var config = await ctx.Database.GetDbConnection().QueryFirstOrDefaultAsync<SsoConfigDto>(sql, new { Domain = dom
 040        if (config == null) return new CheckSsoAvailabilityOut { SsoEnabled = false };
 41
 042        return new CheckSsoAvailabilityOut
 043        {
 044            SsoEnabled = true,
 045            SsoRequired = config.RequireSso,
 046            ProviderType = config.ProviderType,
 047        };
 048    }
 49
 50    private static string? ExtractDomain(string email)
 51    {
 052        if (email.IsEmpty()) return null;
 53
 054        var parts = email.Split('@');
 055        if (parts.Length != 2) return null;
 56
 057        return parts[1].Trim().ToLowerInvariant();
 58    }
 59}