-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11b6b81
commit 8f7d42b
Showing
6 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using DuoSecurity.Auth.Http.Results; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace DuoSecurity.Auth.Http.Tests; | ||
|
||
[TestFixture] | ||
public class DuoAuthClientTests | ||
{ | ||
protected static DuoAuthClient Client => TestSetup.Client; | ||
|
||
protected static string UserName => TestSetup.UserName; | ||
|
||
[Test] | ||
public async Task Ping_works_as_expected() | ||
{ | ||
var response = await Client.PingAsync(); | ||
|
||
response.Should().NotBeNull(); | ||
response.IsSuccessful.Should().BeTrue(); | ||
response.Result.Should().NotBeNull(); | ||
response.Error.Should().BeNull(); | ||
} | ||
|
||
[Test] | ||
public async Task Check_works_as_expected() | ||
{ | ||
var response = await Client.CheckAsync(); | ||
|
||
response.Should().NotBeNull(); | ||
response.IsSuccessful.Should().BeTrue(); | ||
response.Result.Should().NotBeNull(); | ||
response.Error.Should().BeNull(); | ||
} | ||
|
||
[Test(Description = "Note that this test requires that your account has a logo configured.")] | ||
public async Task Logo_works_as_expected() | ||
{ | ||
var response = await Client.LogoAsync(); | ||
|
||
response.Should().NotBeNull(); | ||
response.IsSuccessful.Should().BeTrue(); | ||
response.Result.Should().NotBeNull(); | ||
response.Error.Should().BeNull(); | ||
} | ||
|
||
[Test(Description = "Note that this test will create an actual user on your account.")] | ||
public async Task Enroll_and_EnrollStatus_works_as_expected() | ||
{ | ||
var first = await Client.EnrollAsync(valid_secs: 30); | ||
|
||
first.Should().NotBeNull(); | ||
first.IsSuccessful.Should().BeTrue(); | ||
first.Result.Should().NotBeNull(); | ||
first.Error.Should().BeNull(); | ||
|
||
var enrollment = first.Result!; | ||
var userId = enrollment.UserId!; | ||
|
||
await Task.Delay(TimeSpan.FromSeconds(2)); | ||
var second = await Client.EnrollStatusAsync( | ||
userId, enrollment.ActivationCode); | ||
|
||
second.Should().NotBeNull(); | ||
second.IsSuccessful.Should().BeTrue(); | ||
second.Result.Should().NotBeNull(); | ||
second.Error.Should().BeNull(); | ||
|
||
second.Result.Status.Should().Be(EnrollStatus.Waiting); | ||
} | ||
|
||
[Test(Description = "The given username should be one that is already enrolled.")] | ||
public async Task PreAuth_works_as_expected() | ||
{ | ||
var response = await Client.PreAuthByUsernameAsync(UserName); | ||
|
||
response.Should().NotBeNull(); | ||
response.IsSuccessful.Should().BeTrue(); | ||
response.Result.Should().NotBeNull(); | ||
response.Error.Should().BeNull(); | ||
|
||
var result = response.Result!; | ||
result.Devices.Should().NotBeEmpty(); | ||
} | ||
|
||
[Test(Description = "The given username should be one that is already enrolled. This test will require auth to complete.")] | ||
public async Task Auth_works_as_expected() | ||
{ | ||
var response = await Client.AuthAutoByUsernameAsync(UserName); | ||
|
||
response.Should().NotBeNull(); | ||
response.IsSuccessful.Should().BeTrue(); | ||
response.Result.Should().NotBeNull(); | ||
response.Error.Should().BeNull(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
DuoSecurity.Auth.Http.Tests/DuoSecurity.Auth.Http.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
<UserSecretsId>9d9d08ac-5704-4b9c-8165-338ce75ac6be</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/> | ||
<PackageReference Include="NUnit" Version="3.13.3"/> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1"/> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DuoSecurity.Auth.Http\DuoSecurity.Auth.Http.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using NUnit.Framework; | ||
|
||
namespace DuoSecurity.Auth.Http.Tests; | ||
|
||
[SetUpFixture] | ||
public static class TestSetup | ||
{ | ||
public static DuoAuthClient Client { get; private set; } = null!; | ||
|
||
public static string UserName { get; private set; } = null!; | ||
|
||
[OneTimeSetUp] | ||
public static void OneTimeSetUp() | ||
{ | ||
var configuration = new ConfigurationBuilder() | ||
.AddUserSecrets(typeof(TestSetup).Assembly) | ||
.Build().Get<TestConfig>()!; | ||
|
||
var duoConfig = new DuoAuthConfig( | ||
configuration.HostName, | ||
configuration.IntegrationKey, | ||
configuration.SecretKey); | ||
|
||
Client = new DuoAuthClient(duoConfig); | ||
UserName = configuration.UserName; | ||
} | ||
|
||
[OneTimeTearDown] | ||
public static void OneTimeTearDown() | ||
{ | ||
Client?.Dispose(); | ||
} | ||
|
||
private record TestConfig(string IntegrationKey, string SecretKey, string HostName, string UserName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters