< Summary - Estud

Information
Class: Estud.Back.Features.Identity.UpdateSsoConfiguration.UpdateSsoConfigurationService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Identity/UpdateSsoConfiguration/UpdateSsoConfigurationService.cs
Tag: 114_29044117136
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 50
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%
Update()87.5%88100%

File(s)

/home/runner/work/syki/syki/Back/Features/Identity/UpdateSsoConfiguration/UpdateSsoConfigurationService.cs

#LineLine coverage
 1using Estud.Back.Auth.Managers;
 2
 3namespace Estud.Back.Features.Identity.UpdateSsoConfiguration;
 4
 185public class UpdateSsoConfigurationService(EstudDbContext ctx, SsoEncryptionManager encryption, SsoSchemeManager ssoSche
 6{
 7    private class Validator : AbstractValidator<UpdateSsoConfigurationIn>
 8    {
 29        public Validator()
 10        {
 211            RuleFor(x => x.ProviderType).IsInEnum().WithError(InvalidSsoProviderType.I);
 212            RuleFor(x => x.Authority).NotEmpty().WithError(InvalidSsoAuthority.I);
 213            RuleFor(x => x.ClientId).NotEmpty().WithError(InvalidSsoClientId.I);
 214            RuleFor(x => x.ClientId).MinimumLength(5).WithError(InvalidSsoClientId.I);
 215        }
 16    }
 217    private static readonly Validator V = new();
 18
 19    public async Task<OneOf<UpdateSsoConfigurationOut, EstudError>> Update(Guid id, UpdateSsoConfigurationIn data)
 20    {
 2621        if (V.Run(data, out var error)) return error;
 22
 1023        var authorityError = data.Authority.ValidateSsoAuthority();
 1624        if (authorityError != null) return authorityError;
 25
 426        var config = await ctx.WebSsoConfigurations
 427            .Where(x => x.PublicId == id && x.InstitutionId == ctx.RequestUser.InstitutionId)
 428            .FirstOrDefaultAsync();
 29
 630        if (config == null) return SsoConfigurationNotFound.I;
 31
 232        var clientSecret = data.ClientSecret.IsEmpty()
 233            ? config.ClientSecret
 234            : encryption.Encrypt(data.ClientSecret);
 35
 236        config.Update(
 237            data.ProviderType,
 238            data.Authority.TrimEnd('/'),
 239            data.ClientId.Trim(),
 240            clientSecret,
 241            data.IsActive,
 242            data.RequireSso);
 43
 244        await ctx.SaveChangesAsync();
 45
 246        ssoSchemeManager.RegisterScheme(config);
 47
 248        return new UpdateSsoConfigurationOut { Id = config.PublicId };
 1849    }
 50}