< Summary - Syki

Information
Class: Syki.Back.Features.Identity.UpdateSsoConfiguration.UpdateSsoConfigurationService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Identity/UpdateSsoConfiguration/UpdateSsoConfigurationService.cs
Tag: 97_27801654829
Line coverage
0%
Covered lines: 0
Uncovered lines: 29
Coverable lines: 29
Total lines: 50
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(...)100%210%
.ctor()100%210%
.cctor()100%210%
Update()0%7280%

File(s)

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

#LineLine coverage
 1using Syki.Back.Auth.Managers;
 2
 3namespace Syki.Back.Features.Identity.UpdateSsoConfiguration;
 4
 05public class UpdateSsoConfigurationService(SykiDbContext ctx, SsoEncryptionManager encryption, SsoSchemeManager ssoSchem
 6{
 7    private class Validator : AbstractValidator<UpdateSsoConfigurationIn>
 8    {
 09        public Validator()
 10        {
 011            RuleFor(x => x.ProviderType).IsInEnum().WithError(InvalidSsoProviderType.I);
 012            RuleFor(x => x.Authority).NotEmpty().WithError(InvalidSsoAuthority.I);
 013            RuleFor(x => x.ClientId).NotEmpty().WithError(InvalidSsoClientId.I);
 014            RuleFor(x => x.ClientId).MinimumLength(5).WithError(InvalidSsoClientId.I);
 015        }
 16    }
 017    private static readonly Validator V = new();
 18
 19    public async Task<OneOf<UpdateSsoConfigurationOut, SykiError>> Update(Guid id, UpdateSsoConfigurationIn data)
 20    {
 021        if (V.Run(data, out var error)) return error;
 22
 023        var authorityError = data.Authority.ValidateSsoAuthority();
 024        if (authorityError != null) return authorityError;
 25
 026        var config = await ctx.WebSsoConfigurations
 027            .Where(x => x.PublicId == id && x.InstitutionId == ctx.RequestUser.InstitutionId)
 028            .FirstOrDefaultAsync();
 29
 030        if (config == null) return SsoConfigurationNotFound.I;
 31
 032        var clientSecret = string.IsNullOrEmpty(data.ClientSecret)
 033            ? config.ClientSecret
 034            : encryption.Encrypt(data.ClientSecret);
 35
 036        config.Update(
 037            data.ProviderType,
 038            data.Authority.TrimEnd('/'),
 039            data.ClientId.Trim(),
 040            clientSecret,
 041            data.IsActive,
 042            data.RequireSso);
 43
 044        await ctx.SaveChangesAsync();
 45
 046        ssoSchemeManager.RegisterScheme(config);
 47
 048        return new UpdateSsoConfigurationOut { Id = config.PublicId };
 049    }
 50}