From c7fbc7e1237f0cc907070cd85167ac5728b0b518 Mon Sep 17 00:00:00 2001 From: StevenWdV Date: Thu, 25 Nov 2021 15:18:20 +0100 Subject: Add/improve subspan testcases --- wrappers/csharp/Discovery.cs | 2 +- wrappers/csharp/EduVpnCommonTests/VerifyTests.cs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'wrappers/csharp') diff --git a/wrappers/csharp/Discovery.cs b/wrappers/csharp/Discovery.cs index 0d6fef1..1f3d1e8 100644 --- a/wrappers/csharp/Discovery.cs +++ b/wrappers/csharp/Discovery.cs @@ -17,7 +17,7 @@ namespace EduVpnCommon /// Signed .json file contents. /// The file type to be verified, one of server_list.json or organization_list.json. /// Minimum time for signature. Should be set to at least the time in a previously retrieved file. - /// If expectedFileName is not one of the allowed valued. + /// If expectedFileName is not one of the allowed values. /// If signature verification fails. public static void Verify( ArraySegment signatureFileContent, diff --git a/wrappers/csharp/EduVpnCommonTests/VerifyTests.cs b/wrappers/csharp/EduVpnCommonTests/VerifyTests.cs index 933f2bc..41faf87 100644 --- a/wrappers/csharp/EduVpnCommonTests/VerifyTests.cs +++ b/wrappers/csharp/EduVpnCommonTests/VerifyTests.cs @@ -25,7 +25,20 @@ namespace EduVpnCommonTests File.ReadAllBytes($"{testDataDir_}/{jsonFile}"), expectedFileName, DateTimeOffset.UnixEpoch); - + + [Test] + [TestCase("dummy/server_list.json.minisig", "dummy/server_list.json", "server_list.json")] + public void TestValidSegment(string sigFile, string jsonFile, string expectedFileName) + { + var bytes = new byte[] { 1, 2, 3 }.Concat(File.ReadAllBytes($"{testDataDir_}/{jsonFile}")) + .Concat(new byte[] { 1, 2, 3 }).ToArray(); + Discovery.Verify( + File.ReadAllBytes($"{testDataDir_}/{sigFile}"), + new(bytes, 3, bytes.Length - 3 - 3), + expectedFileName, + DateTimeOffset.UnixEpoch); + } + [Test] [TestCase("dummy/random.txt", "dummy/server_list.json", "server_list.json")] public void TestInvalidSignature(string sigFile, string jsonFile, string expectedFileName) => -- cgit v1.2.3