From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- .../Tests/FlashPolicyParserSocketTests.cs | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 Runtime/Managed/CrossDomainPolicyParser/Tests/FlashPolicyParserSocketTests.cs (limited to 'Runtime/Managed/CrossDomainPolicyParser/Tests/FlashPolicyParserSocketTests.cs') diff --git a/Runtime/Managed/CrossDomainPolicyParser/Tests/FlashPolicyParserSocketTests.cs b/Runtime/Managed/CrossDomainPolicyParser/Tests/FlashPolicyParserSocketTests.cs new file mode 100644 index 0000000..8e0f62b --- /dev/null +++ b/Runtime/Managed/CrossDomainPolicyParser/Tests/FlashPolicyParserSocketTests.cs @@ -0,0 +1,124 @@ +using System.IO; +using System.Text; +using MonoForks.System.Windows.Browser.Net; +using NUnit.Framework; + +namespace CrossDomainPolicyParserTests +{ + [TestFixture] + public class FlashPolicyParserSocketTests + { + [Test] + public void AllDomains_AllPorts_IsAllowed() + { + string policy = @" + + +"; + Assert.IsTrue(RequestAllowed(policy, 123)); + } + + [Test] + public void AllDomains_AllPorts_Trailing0_IsAllowed() + { + string policy = @" + + +" + "\0"; + Assert.IsTrue(RequestAllowed(policy, 123)); + } + + [Test] + public void AllDomains_UsingSpecificPorts_IsAllowed() + { + string policy = @" + + +"; + Assert.IsTrue(RequestAllowed(policy, 1020)); + } + + [Test] + public void AllDomains_OutsideSpecificPorts_IsDisAllowed() + { + string policy = @" + + +"; + Assert.IsFalse(RequestAllowed(policy, 1020)); + } + + [Test] + public void AllDomains_OutsidePortRange_IsDisAllowed() + { + string policy = @" + + +"; + Assert.IsFalse(RequestAllowed(policy, 1020)); + } + + [Test] + public void AllDomains_InsidePortRange_IsAllowed() + { + string policy = @" + + +"; + Assert.IsTrue(RequestAllowed(policy, 1035)); + } + + [Test] + public void PolicyReceivedFromHigherThan1024_DisallowsAccessToBelow1024Ports() + { + string policy = @" + + +"; + Assert.IsFalse(RequestAllowed(policy, 1010, 1300)); + } + + [Test] + public void PolicyReceivedFromHigherThan1024_AllowsAccessToAbove1024Ports() + { + string policy = @" + + +"; + Assert.IsTrue(RequestAllowed(policy, 1035, 1300)); + } + + [Test] + public void PolicyReceivedFromLowerThan1024_AllowsAccessToBelow1024Ports() + { + string policy = @" + + +"; + Assert.IsTrue(RequestAllowed(policy, 1010, 1000)); + } + [Test] + public void PolicyReceivedFromLowerThan1024_AllowsAccessToAbove1024Ports() + { + string policy = @" + + +"; + Assert.IsTrue(RequestAllowed(policy, 1030, 1000)); + } + + private bool RequestAllowed(string xdomain, int port) + { + return RequestAllowed(xdomain, port, 843); + } + + private bool RequestAllowed(string xdomain, int port, int policyport) + { + var ms = new MemoryStream(Encoding.UTF8.GetBytes(xdomain)); + var policy = FlashCrossDomainPolicy.FromStream(ms); + policy.PolicyPort = policyport; + return policy.IsSocketConnectionAllowed(port); + } + + } +} \ No newline at end of file -- cgit v1.1-26-g67d0