Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QUIC ALPN list narrowing down scenario test #86659

Merged
merged 9 commits into from
Jun 22, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -372,5 +372,67 @@ await Task.WhenAll(
await connection.DisposeAsync();
}).WaitAsync(TimeSpan.FromSeconds(5)));
}

[Fact]
public async Task Listener_AlpnChange() {
liveans marked this conversation as resolved.
Show resolved Hide resolved
var listenerOptions = new QuicListenerOptions()
{
ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0),
ApplicationProtocols = new List<SslApplicationProtocol>()
{
new SslApplicationProtocol("foo"),
new SslApplicationProtocol("bar"),
new SslApplicationProtocol("test"),
},
ConnectionOptionsCallback = (_, _, _) =>
{
// Narrowing down alpn list to more specific.
var options = CreateQuicServerOptions();
options.ServerAuthenticationOptions.ApplicationProtocols = new()
{
new SslApplicationProtocol("bar"),
new SslApplicationProtocol("test"),
};
return ValueTask.FromResult(options);
}
};
await using QuicListener listener = await CreateQuicListener(listenerOptions);

// Successful connection with bar ALPN
QuicClientConnectionOptions clientOptions1 = CreateQuicClientOptions(listener.LocalEndPoint);
clientOptions1.ClientAuthenticationOptions.ApplicationProtocols = new()
{
new SslApplicationProtocol("foo"),
new SslApplicationProtocol("bar"),
};
ValueTask<QuicConnection> connectTask1 = CreateQuicConnection(clientOptions1);
await using QuicConnection serverConnection1 = await listener.AcceptConnectionAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(30));
liveans marked this conversation as resolved.
Show resolved Hide resolved
await using QuicConnection clientConnection1 = await connectTask1.AsTask().WaitAsync(TimeSpan.FromSeconds(30));

Assert.Equal(new SslApplicationProtocol("bar"), clientConnection1.NegotiatedApplicationProtocol);

// Successful connection with test ALPN
liveans marked this conversation as resolved.
Show resolved Hide resolved
QuicClientConnectionOptions clientOptions2 = CreateQuicClientOptions(listener.LocalEndPoint);
clientOptions2.ClientAuthenticationOptions.ApplicationProtocols = new()
{
new SslApplicationProtocol("foo"),
new SslApplicationProtocol("test"),
};
ValueTask<QuicConnection> connectTask2 = CreateQuicConnection(clientOptions2);
await using QuicConnection serverConnection2 = await listener.AcceptConnectionAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(30));
await using QuicConnection clientConnection2 = await connectTask2.AsTask().WaitAsync(TimeSpan.FromSeconds(30));

Assert.Equal(new SslApplicationProtocol("test"), clientConnection2.NegotiatedApplicationProtocol);

// Failure case should throw QuicException
QuicClientConnectionOptions clientOptions3 = CreateQuicClientOptions(listener.LocalEndPoint);
clientOptions3.ClientAuthenticationOptions.ApplicationProtocols = new()
{
new SslApplicationProtocol("foo"),
};
ValueTask<QuicConnection> connectTask3 = CreateQuicConnection(clientOptions3);
await Assert.ThrowsAsync<QuicException>(() => listener.AcceptConnectionAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(30)));
liveans marked this conversation as resolved.
Show resolved Hide resolved
await Assert.ThrowsAsync<QuicException>(() => connectTask3.AsTask().WaitAsync(TimeSpan.FromSeconds(30)));
}
}
}