diff options
Diffstat (limited to 'tests/FundLab.Api.Tests')
| -rw-r--r-- | tests/FundLab.Api.Tests/ApiTests.fs | 24 | ||||
| -rw-r--r-- | tests/FundLab.Api.Tests/FundLab.Api.Tests.fsproj | 25 | ||||
| -rw-r--r-- | tests/FundLab.Api.Tests/Program.fs | 5 |
3 files changed, 54 insertions, 0 deletions
diff --git a/tests/FundLab.Api.Tests/ApiTests.fs b/tests/FundLab.Api.Tests/ApiTests.fs new file mode 100644 index 0000000..a46d330 --- /dev/null +++ b/tests/FundLab.Api.Tests/ApiTests.fs @@ -0,0 +1,24 @@ +namespace FundLab.Api.Tests + +module ApiTests = + + open Xunit + open FundLab.Api + + [<Theory>] + [<InlineData("")>] + [<InlineData("Basic secret")>] + [<InlineData("Bearer wrong")>] + let ``missing or wrong bearer token is unauthorized`` header = + Assert.Equal(AuthDecision.Unauthorized, Authentication.authorize "secret" header) + + [<Fact>] + let ``matching bearer token is authorized`` () = + Assert.Equal(AuthDecision.Authorized, Authentication.authorize "secret" "Bearer secret") + + [<Fact>] + let ``health payload is non-sensitive`` () = + let payload = Health.payload "fund-lab-api" + + Assert.Contains("\"status\":\"ok\"", payload) + Assert.DoesNotContain("secret", payload) diff --git a/tests/FundLab.Api.Tests/FundLab.Api.Tests.fsproj b/tests/FundLab.Api.Tests/FundLab.Api.Tests.fsproj new file mode 100644 index 0000000..ef9f063 --- /dev/null +++ b/tests/FundLab.Api.Tests/FundLab.Api.Tests.fsproj @@ -0,0 +1,25 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <TargetFramework>net8.0</TargetFramework> + <OutputType>Library</OutputType> + <IsPackable>false</IsPackable> + <IsTestProject>true</IsTestProject> + <GenerateProgramFile>false</GenerateProgramFile> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> + </PropertyGroup> + <ItemGroup> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> + <PackageReference Include="xunit" Version="2.9.2" /> + <PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"> + <PrivateAssets>all</PrivateAssets> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + </PackageReference> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\src\FundLab.Api\FundLab.Api.fsproj" /> + </ItemGroup> + <ItemGroup> + <Compile Include="ApiTests.fs" /> + <Compile Include="Program.fs" /> + </ItemGroup> +</Project> diff --git a/tests/FundLab.Api.Tests/Program.fs b/tests/FundLab.Api.Tests/Program.fs new file mode 100644 index 0000000..a139996 --- /dev/null +++ b/tests/FundLab.Api.Tests/Program.fs @@ -0,0 +1,5 @@ +module FundLab.Api.Tests.Program + +[<EntryPoint>] +let main _argv = + 0 |
