public void TestValidationOptionsWithoutAccessKey()
        {
            var testconnection = "Endpoint=http://abc;Version=1.0;";
            var configs        = new WebPubSubValidationOptions(testconnection);

            Assert.IsTrue(configs.TryGetKey("abc", out var key));
            Assert.Null(key);
        }
        public void TestValidationOptionsParser()
        {
            var testconnection = "Endpoint=http://abc;Port=888;AccessKey=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGH==A;Version=1.0;";
            var configs        = new WebPubSubValidationOptions(testconnection);

            Assert.IsTrue(configs.TryGetKey("abc", out var key));
            Assert.AreEqual("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGH==A", key);
        }
        public void TestSignatureCheck_SignatureNullFail()
        {
            var connectionContext = new WebPubSubConnectionContext(
                WebPubSubEventType.System,
                null, null, "0f9c97a2f0bf4706afe87a14e0797b11",
                origin: TestUri.Host);
            var options = new WebPubSubValidationOptions($"Endpoint={TestUri};AccessKey=7aab239577fd4f24bc919802fb629f5f;Version=1.0;");
            var result  = connectionContext.IsValidSignature(options);

            Assert.False(result);
        }
        public void TestAbuseProtectionCompare(string requestHost, bool expected)
        {
            var options = new WebPubSubValidationOptions($"Endpoint=https://my-host.com;AccessKey=7aab239577fd4f24bc919802fb629f5f;Version=1.0;");

            var result = false;

            if (options.ContainsHost(requestHost))
            {
                result = true;
            }
            Assert.AreEqual(expected, result);
        }
        public void TestSignatureCheck_AccessKeyEmptySuccess()
        {
            var connectionContext = new WebPubSubConnectionContext(
                WebPubSubEventType.System,
                null, null, "0f9c97a2f0bf4706afe87a14e0797b11",
                signature: "sha256=7767effcb3946f3e1de039df4b986ef02c110b1469d02c0a06f41b3b727ab561",
                origin: TestUri.Host);
            var options = new WebPubSubValidationOptions($"Endpoint={TestUri};Version=1.0;");
            var result  = connectionContext.IsValidSignature(options);

            Assert.True(result);
        }