/
IsPkceRequiredTest.cs
37 lines (35 loc) · 1.82 KB
/
IsPkceRequiredTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using OAuch.Shared;
using OAuch.Shared.Enumerations;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace OAuch.Compliance.Tests.Pkce {
public class IsPkceRequiredTest : Test {
public override string Title => "Does the server require PKCE";
public override string Description => "This test determines whether the server requires the use of PKCE for the authorization code grant.";
public override TestResultFormatter ResultFormatter => TestResultFormatter.YesGoodNoBad;
public override Type ResultType => typeof(IsPkceRequiredTestResult);
}
public class IsPkceRequiredTestResult : TestResult {
public IsPkceRequiredTestResult(string testId) : base(testId) { }
public override Type ImplementationType => typeof(IsPkceRequiredTestImplementation);
}
public class IsPkceRequiredTestImplementation : TestImplementation {
public IsPkceRequiredTestImplementation(TestRunContext context, IsPkceRequiredTestResult result, IsPkceImplementedTestResult pkce) : base(context, result, pkce) { }
public override Task Run() {
if (HasFailed<IsPkceImplementedTestResult>()) {
Result.Outcome = TestOutcomes.Skipped;
return Task.CompletedTask;
}
var supportedTypes = Context.State.Get<List<PKCESupportTypes>>(StateKeys.WorkingPkceTypes);
if (supportedTypes.Contains(PKCESupportTypes.None)) {
Result.Outcome = TestOutcomes.SpecificationNotImplemented;
LogInfo("The server supports the authorization code grant without PKCE");
} else {
Result.Outcome = TestOutcomes.SpecificationFullyImplemented;
LogInfo("The server requires PKCE");
}
return Task.CompletedTask;
}
}
}