52 lines
1.5 KiB
Text
52 lines
1.5 KiB
Text
|
|
#load "bots.fsx"
|
||
|
|
|
||
|
|
open System.Text.Json
|
||
|
|
open Bots
|
||
|
|
|
||
|
|
let bot =
|
||
|
|
{ Slug = "test"
|
||
|
|
Patterns = [ " Bot/1.0" ]
|
||
|
|
Examples = [ "Bot/1.0"; "Alternate/1.0"; "Browser" ]
|
||
|
|
Signer = Some "https://agent.example.test/keys" }
|
||
|
|
|
||
|
|
let matches = headers (Set.singleton "Browser") bot
|
||
|
|
assert (matches.Length = 3)
|
||
|
|
|
||
|
|
assert
|
||
|
|
(matches
|
||
|
|
|> List.exists (fun header -> header.Kind = "Exact" && header.Value = "Alternate/1.0"))
|
||
|
|
|
||
|
|
assert
|
||
|
|
(matches
|
||
|
|
|> List.exists (fun header ->
|
||
|
|
header.Name = "Signature-Agent"
|
||
|
|
&& header.Value = "\"https://agent.example.test/keys\""))
|
||
|
|
|
||
|
|
assert (matches |> List.forall (fun header -> header.Value <> "Browser"))
|
||
|
|
|
||
|
|
let config =
|
||
|
|
JsonDocument.Parse(
|
||
|
|
"""{"namespace":"test","gateway":"relay","gatewayNamespace":"test","source":"git.example.test","target":"code.example.test"}"""
|
||
|
|
)
|
||
|
|
|
||
|
|
let many =
|
||
|
|
[ for index in 0..128 ->
|
||
|
|
{ Name = "User-Agent"
|
||
|
|
Kind = "Exact"
|
||
|
|
Value = string index } ]
|
||
|
|
|
||
|
|
let output = routes config.RootElement many
|
||
|
|
assert (output.Length = 2)
|
||
|
|
assert (output.Head.spec.rules.Length = 2)
|
||
|
|
assert (output.Head.spec.rules.Head.matches.Length = 64)
|
||
|
|
assert (output.Tail.Head.spec.rules.Head.matches.Length = 1)
|
||
|
|
let encoded = JsonDocument.Parse(JsonSerializer.Serialize output)
|
||
|
|
|
||
|
|
assert
|
||
|
|
(encoded.RootElement[0]
|
||
|
|
.GetProperty("metadata")
|
||
|
|
.GetProperty("labels")
|
||
|
|
.GetProperty("app.kubernetes.io/managed-by")
|
||
|
|
.GetString() = "bot-redirect")
|
||
|
|
|
||
|
|
printfn "bot matching and route partition tests passed"
|