< Summary - Estud

Information
Class: Estud.Back.Features.Identity.CreateSsoConfiguration.CreateSsoConfigurationService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Identity/CreateSsoConfiguration/CreateSsoConfigurationService.cs
Tag: 114_29044117136
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 54
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(...)100%11100%
.ctor()100%11100%
.cctor()100%11100%
Create()87.5%88100%

File(s)

/home/runner/work/syki/syki/Back/Features/Identity/CreateSsoConfiguration/CreateSsoConfigurationService.cs

#LineLine coverage
 1using Estud.Back.Auth.Managers;
 2using Estud.Back.Domain.Identity;
 3
 4namespace Estud.Back.Features.Identity.CreateSsoConfiguration;
 5
 306public class CreateSsoConfigurationService(EstudDbContext ctx, SsoEncryptionManager encryption, SsoSchemeManager ssoSche
 7{
 8    private class Validator : AbstractValidator<CreateSsoConfigurationIn>
 9    {
 210        public Validator()
 11        {
 212            RuleFor(x => x.ProviderType).IsInEnum().WithError(InvalidSsoProviderType.I);
 13
 214            RuleFor(x => x.Authority).NotEmpty().WithError(InvalidSsoAuthority.I);
 15
 216            RuleFor(x => x.ClientId).NotEmpty().WithError(InvalidSsoClientId.I);
 217            RuleFor(x => x.ClientId).MinimumLength(5).WithError(InvalidSsoClientId.I);
 18
 219            RuleFor(x => x.ClientSecret).NotEmpty().WithError(InvalidSsoClientSecret.I);
 220            RuleFor(x => x.ClientSecret).MinimumLength(10).WithError(InvalidSsoClientSecret.I);
 221        }
 22    }
 223    private static readonly Validator V = new();
 24
 25    public async Task<OneOf<CreateSsoConfigurationOut, EstudError>> Create(CreateSsoConfigurationIn data)
 26    {
 4227        if (V.Run(data, out var error)) return error;
 28
 1829        var authorityError = data.Authority.ValidateSsoAuthority();
 2430        if (authorityError != null) return authorityError;
 31
 1232        var userEmail = await ctx.Users.Where(x => x.Id == ctx.RequestUser.Id).Select(x => x.Email).FirstAsync();
 33
 1234        var domain = userEmail!.Split('@').Last().NormalizeSsoDomain();
 1235        if (domain == null) return InvalidSsoAllowedDomains.I;
 36
 1237        var domainExists = await ctx.WebSsoAllowedDomains.AnyAsync(d => d.Domain == domain);
 1438        if (domainExists) return SsoDomainAlreadyConfigured.I;
 39
 1040        var config = new SsoConfiguration(
 1041            ctx.RequestUser.InstitutionId,
 1042            data.ProviderType,
 1043            data.Authority.TrimEnd('/'),
 1044            data.ClientId.Trim(),
 1045            encryption.Encrypt(data.ClientSecret),
 1046            [domain]);
 47
 1048        await ctx.SaveChangesAsync(config);
 49
 1050        ssoSchemeManager.RegisterScheme(config);
 51
 1052        return new CreateSsoConfigurationOut { Id = config.PublicId };
 3053    }
 54}