public void SetIPLocalAddressPreference() { TestRuntime.AssertXcodeVersion(11, 0); foreach (var ipOption in new [] { NWIPLocalAddressPreference.Default, NWIPLocalAddressPreference.Stable, NWIPLocalAddressPreference.Temporary }) { #if NET using (var options = new NWProtocolTlsOptions()) #else using (var options = NWProtocolOptions.CreateTls()) #endif Assert.DoesNotThrow(() => options.IPLocalAddressPreference = ipOption, "Tls"); #if NET using (var options = new NWProtocolTcpOptions()) #else using (var options = NWProtocolOptions.CreateTcp()) #endif Assert.DoesNotThrow(() => options.IPLocalAddressPreference = ipOption, "Tcp"); #if NET using (var options = new NWProtocolUdpOptions()) #else using (var options = NWProtocolOptions.CreateUdp()) #endif Assert.DoesNotThrow(() => options.IPLocalAddressPreference = ipOption, "Udp"); } }
public void CreateTlsTest() { #if NET using (var options = new NWProtocolTlsOptions()) { var sec = options.ProtocolOptions; #else using (var options = NWProtocolOptions.CreateTls()) { var sec = options.TlsProtocolOptions; #endif // we cannot test much more :( Assert.AreNotEqual(IntPtr.Zero, options.Handle); } }
public void SetUp() { #if NET using (var tcpOptions = new NWProtocolTcpOptions()) using (var tlsOptions = new NWProtocolTlsOptions()) #else using (var tcpOptions = NWProtocolOptions.CreateTcp()) using (var tlsOptions = NWProtocolOptions.CreateTls()) #endif using (var parameters = NWParameters.CreateTcp()) { parameters.ProtocolStack.PrependApplicationProtocol(tlsOptions); parameters.ProtocolStack.PrependApplicationProtocol(tcpOptions); parameters.IncludePeerToPeer = true; listener = NWListener.Create("1234", parameters); } }
public void NewTlsOptions() { TestRuntime.AssertXcodeVersion(11, 0); #if NET using (var npo = new NWProtocolTlsOptions()) { var options = npo.ProtocolOptions; #else using (var npo = NWProtocolOptions.CreateTls()) { var options = npo.TlsProtocolOptions; #endif options.SetTlsMaxVersion(TlsProtocolVersion.Tls12); options.SetTlsMinVersion(TlsProtocolVersion.Tls10); options.AddTlsCipherSuite(TlsCipherSuite.Aes128GcmSha256); options.AddTlsCipherSuiteGroup(TlsCipherSuiteGroup.Legacy); using (var dd = DispatchData.FromByteBuffer(new byte [1])) { options.SetTlsPreSharedKeyIdentityHint(dd); } } } }
public void Equals() { TestRuntime.AssertXcodeVersion(11, 0); #if NET using (var npo = new NWProtocolTlsOptions()) { var options = npo.ProtocolOptions; #else using (var npo = NWProtocolOptions.CreateTls()) { var options = npo.TlsProtocolOptions; #endif Assert.True(SecProtocolOptions.Equals(null, null), "1"); Assert.True(SecProtocolOptions.Equals(options, options), "2"); Assert.False(SecProtocolOptions.Equals(null, options), "3"); Assert.False(SecProtocolOptions.Equals(options, null), "4"); Assert.True(options.Equals(options), "5"); Assert.False(options.Equals(null), "6"); } }
public void SetUp() { options = new NWProtocolTlsOptions(); }
public void TestStateChangesHandler () { // In the test we are doing the following: // // 1. Start a browser. At this point, we have no listeners (unless someone is exposing it in the lab) // and therefore the browser cannot find any services/listeners. // 2. Start a listener that is using the same type/domain pair that the browser expects. // 3. Browser picks up the new listener, and sends an event (service found). // 4. Listener stops, and the service disappears. // 5. The browser is not yet canceled, so it picks up that the service/listener is not longer then and returns it. // // The test will block until the different events are set by the callbacks that are executed in a diff thread. bool didRun = false; bool receivedNotNullChange = false; bool eventsDone = false; bool listeningDone = false; Exception ex = null; var changesEvent = new AutoResetEvent (false); var browserReady = new AutoResetEvent (false); var finalEvent = new AutoResetEvent (false); TestRuntime.RunAsync (DateTime.Now.AddSeconds (30), async () => { // start the browser, before the listener browser.SetStateChangesHandler ((st, er) => { // assert here with a `st` of `Fail` Assert.IsNull (er, "Error"); if (st == NWBrowserState.Ready) browserReady.Set (); }); #if NET browser.IndividualChangesDelegate = (oldResult, newResult) => { #else browser.SetChangesHandler ((oldResult, newResult) => { #endif didRun = true; try { receivedNotNullChange = oldResult != null || newResult != null; } catch (Exception e) { ex = e; } finally { changesEvent.Set (); eventsDone = true; } #if NET }; #else }); #endif browser.Start (); browserReady.WaitOne (30000); using (var advertiser = NWAdvertiseDescriptor.CreateBonjourService ("MonoTouchFixtures.Network", type)) #if NET using (var tcpOptions = new NWProtocolTcpOptions ()) using (var tlsOptions = new NWProtocolTlsOptions ()) #else using (var tcpOptions = NWProtocolOptions.CreateTcp ()) using (var tlsOptions = NWProtocolOptions.CreateTls ()) #endif using (var paramenters = NWParameters.CreateTcp ()) { paramenters.ProtocolStack.PrependApplicationProtocol (tlsOptions); paramenters.ProtocolStack.PrependApplicationProtocol (tcpOptions); paramenters.IncludePeerToPeer = true; using (var listener = NWListener.Create ("1234", paramenters)) { listener.SetQueue (DispatchQueue.CurrentQueue); listener.SetAdvertiseDescriptor (advertiser); // we need the connection handler, else we will get an exception listener.SetNewConnectionHandler ((c) => { }); listener.SetStateChangedHandler ((s, e) => { if (e != null) { Console.WriteLine ($"Got error {e.ErrorCode} {e.ErrorDomain} '{e.CFError.FailureReason}' {e.ToString ()}"); } }); listener.Start (); changesEvent.WaitOne (30000); listener.Cancel (); listeningDone = true; finalEvent.Set (); } } }, () => eventsDone);