Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/common/TestRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,11 @@ public static void IgnoreInCIIfTimedOut (Exception ex)
IgnoreInCI ($"Ignored due to network error: {wex}");
}
}

var se = FindInner<System.Net.Sockets.SocketException> (ex);
if (se is not null && se.SocketErrorCode == System.Net.Sockets.SocketError.TimedOut) {
IgnoreInCI ($"Ignored due to socket timeout: {se.Message}");
}
}

public static void IgnoreInCIIfForbidden (Exception ex)
Expand Down
75 changes: 40 additions & 35 deletions tests/monotouch-test/Security/SecureTransportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,45 +130,50 @@ public void DatagramDefaults ()
[Test]
public void Tls12 ()
{
var client = new TcpClient ("google.ca", 443);
using (NetworkStream ns = client.GetStream ())
using (var ssl = new SslContext (SslProtocolSide.Client, SslConnectionType.Stream)) {

ssl.MinProtocol = SslProtocol.Tls_1_2;
Assert.That (ssl.MinProtocol, Is.EqualTo (SslProtocol.Tls_1_2), "MinProtocol");

ssl.Connection = new SslStreamConnection (ns);

var result = ssl.Handshake ();
while (result == SslStatus.WouldBlock || result == (SslStatus) (-108)) {
// we need to ask again - but if we're too fast we'll get -108 (errSecAllocate)
Thread.Sleep (100);
// during the above call SessionState is Handshake
Assert.That (ssl.SessionState, Is.EqualTo (SslSessionState.Handshake), "Handshake/in progress");
result = ssl.Handshake ();
}
Assert.That (result, Is.EqualTo (SslStatus.Success), "Handshake/done");
try {
var client = new TcpClient ("google.ca", 443);
using (NetworkStream ns = client.GetStream ())
using (var ssl = new SslContext (SslProtocolSide.Client, SslConnectionType.Stream)) {

ssl.MinProtocol = SslProtocol.Tls_1_2;
Assert.That (ssl.MinProtocol, Is.EqualTo (SslProtocol.Tls_1_2), "MinProtocol");

ssl.Connection = new SslStreamConnection (ns);

var result = ssl.Handshake ();
while (result == SslStatus.WouldBlock || result == (SslStatus) (-108)) {
// we need to ask again - but if we're too fast we'll get -108 (errSecAllocate)
Comment thread
rolfbjarne marked this conversation as resolved.
Outdated
Thread.Sleep (100);
// during the above call SessionState is Handshake
Assert.That (ssl.SessionState, Is.EqualTo (SslSessionState.Handshake), "Handshake/in progress");
Comment thread
rolfbjarne marked this conversation as resolved.
result = ssl.Handshake ();
}
Assert.That (result, Is.EqualTo (SslStatus.Success), "Handshake/done");

// FIXME: iOS 8 beta 1 bug ?!? the state is not updated (maybe delayed?) but the code still works
//Assert.That (ssl.SessionState, Is.EqualTo (SslSessionState.Connected), "Connected");
Assert.That (ssl.NegotiatedProtocol, Is.EqualTo (SslProtocol.Tls_1_2), "NegotiatedProtocol");
// FIXME: iOS 8 beta 1 bug ?!? the state is not updated (maybe delayed?) but the code still works
//Assert.That (ssl.SessionState, Is.EqualTo (SslSessionState.Connected), "Connected");
Assert.That (ssl.NegotiatedProtocol, Is.EqualTo (SslProtocol.Tls_1_2), "NegotiatedProtocol");

nint processed;
var data = Encoding.UTF8.GetBytes ("GET / HTTP/1.0" + Environment.NewLine + Environment.NewLine);
result = ssl.Write (data, out processed);
Assert.That (processed, Is.EqualTo ((nint) data.Length), "small buffer");
Assert.That (result, Is.EqualTo (SslStatus.Success), "Write");
nint processed;
var data = Encoding.UTF8.GetBytes ("GET / HTTP/1.0" + Environment.NewLine + Environment.NewLine);
result = ssl.Write (data, out processed);
Assert.That (processed, Is.EqualTo ((nint) data.Length), "small buffer");
Assert.That (result, Is.EqualTo (SslStatus.Success), "Write");

data = new byte [1024];
result = ssl.Read (data, out processed);
while (result == SslStatus.WouldBlock)
data = new byte [1024];
result = ssl.Read (data, out processed);
Assert.That (result, Is.EqualTo (SslStatus.Success), "Read");

string s = Encoding.UTF8.GetString (data, 0, (int) processed);
// The result apparently depends on where you are: I get a 302, the bots get a 200.
// Also sometimes it fails with 502 Bad Gateway on the bots
Assert.That (s, Does.StartWith ("HTTP/1.0 302 Found").Or.StartWith ("HTTP/1.0 200 OK").Or.StartWith ("HTTP/1.0 502 Bad Gateway"), "response");
while (result == SslStatus.WouldBlock)
result = ssl.Read (data, out processed);
Comment thread
rolfbjarne marked this conversation as resolved.
Assert.That (result, Is.EqualTo (SslStatus.Success), "Read");

string s = Encoding.UTF8.GetString (data, 0, (int) processed);
// The result apparently depends on where you are: I get a 302, the bots get a 200.
// Also sometimes it fails with 502 Bad Gateway on the bots
Assert.That (s, Does.StartWith ("HTTP/1.0 302 Found").Or.StartWith ("HTTP/1.0 200 OK").Or.StartWith ("HTTP/1.0 502 Bad Gateway"), "response");
}
} catch (Exception ex) {
TestRuntime.IgnoreInCIIfBadNetwork (ex);
throw;
}
}
}
Expand Down
Loading