Skip to content

[dotnet] [bidi] Make ContinueWithAuthCommand closer to spec (breaking change) #15545

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

Merged
merged 3 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
[JsonSerializable(typeof(Modules.BrowsingContext.UserPromptOpenedEventArgs))]
[JsonSerializable(typeof(Modules.BrowsingContext.UserPromptClosedEventArgs))]

[JsonSerializable(typeof(Modules.Network.ContinueWithAuthParameters.Default), TypeInfoPropertyName = "Network_ContinueWithAuthParameters_Default")]
[JsonSerializable(typeof(Modules.Network.AddInterceptCommand))]
[JsonSerializable(typeof(Modules.Network.AddInterceptResult))]
[JsonSerializable(typeof(Modules.Network.ContinueRequestCommand))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,26 @@ internal class ContinueWithAuthCommand(ContinueWithAuthParameters @params)
: Command<ContinueWithAuthParameters>(@params, "network.continueWithAuth");

[JsonPolymorphic(TypeDiscriminatorPropertyName = "action")]
[JsonDerivedType(typeof(Credentials), "provideCredentials")]
[JsonDerivedType(typeof(Default), "default")]
[JsonDerivedType(typeof(Cancel), "cancel")]
internal abstract record ContinueWithAuthParameters(Request Request) : CommandParameters
{
internal record Credentials(Request Request, [property: JsonPropertyName("credentials")] AuthCredentials AuthCredentials) : ContinueWithAuthParameters(Request);
[JsonDerivedType(typeof(ContinueWithAuthCredentials), "provideCredentials")]
[JsonDerivedType(typeof(ContinueWithAuthDefaultCredentials), "default")]
[JsonDerivedType(typeof(ContinueWithAuthCancelCredentials), "cancel")]
internal abstract record ContinueWithAuthParameters(Request Request) : CommandParameters;

internal record Default(Request Request) : ContinueWithAuthParameters(Request);
internal record ContinueWithAuthCredentials(Request Request, AuthCredentials Credentials) : ContinueWithAuthParameters(Request);

internal record Cancel(Request Request) : ContinueWithAuthParameters(Request);
}
internal abstract record ContinueWithAuthNoCredentials(Request Request) : ContinueWithAuthParameters(Request);

internal record ContinueWithAuthDefaultCredentials(Request Request) : ContinueWithAuthNoCredentials(Request);

internal record ContinueWithAuthCancelCredentials(Request Request) : ContinueWithAuthNoCredentials(Request);

public record ContinueWithAuthOptions : CommandOptions;

public record ContinueWithDefaultAuthOptions : CommandOptions;
public record ContinueWithAuthCredentialsOptions : ContinueWithAuthOptions;

public record ContinueWithAuthNoCredentialsOptions : ContinueWithAuthOptions;

public record ContinueWithAuthDefaultCredentialsOptions : ContinueWithAuthNoCredentialsOptions;

public record ContinueWithAuthCancelCredentialsOptions : ContinueWithAuthNoCredentialsOptions;

public record ContinueWithCancelledAuthOptions : CommandOptions;
12 changes: 6 additions & 6 deletions dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@ internal async Task ProvideResponseAsync(Request request, ProvideResponseOptions
await Broker.ExecuteCommandAsync(new ProvideResponseCommand(@params), options).ConfigureAwait(false);
}

internal async Task ContinueWithAuthAsync(Request request, AuthCredentials credentials, ContinueWithAuthOptions? options = null)
internal async Task ContinueWithAuthAsync(Request request, AuthCredentials credentials, ContinueWithAuthCredentialsOptions? options = null)
{
await Broker.ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthParameters.Credentials(request, credentials)), options).ConfigureAwait(false);
await Broker.ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthCredentials(request, credentials)), options).ConfigureAwait(false);
}

internal async Task ContinueWithAuthAsync(Request request, ContinueWithDefaultAuthOptions? options = null)
internal async Task ContinueWithAuthAsync(Request request, ContinueWithAuthDefaultCredentialsOptions? options = null)
{
await Broker.ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthParameters.Default(request)), options).ConfigureAwait(false);
await Broker.ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthDefaultCredentials(request)), options).ConfigureAwait(false);
}

internal async Task ContinueWithAuthAsync(Request request, ContinueWithCancelledAuthOptions? options = null)
internal async Task ContinueWithAuthAsync(Request request, ContinueWithAuthCancelCredentialsOptions? options = null)
{
await Broker.ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthParameters.Cancel(request)), options).ConfigureAwait(false);
await Broker.ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthCancelCredentials(request)), options).ConfigureAwait(false);
}

public async Task<Subscription> OnBeforeRequestSentAsync(Func<BeforeRequestSentEventArgs, Task> handler, SubscriptionOptions? options = null)
Expand Down
6 changes: 3 additions & 3 deletions dotnet/src/webdriver/BiDi/Modules/Network/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ public Task ContinueResponseAsync(ContinueResponseOptions? options = null)
return _bidi.Network.ContinueResponseAsync(this, options);
}

public Task ContinueWithAuthAsync(AuthCredentials credentials, ContinueWithAuthOptions? options = null)
public Task ContinueWithAuthAsync(AuthCredentials credentials, ContinueWithAuthCredentialsOptions? options = null)
{
return _bidi.Network.ContinueWithAuthAsync(this, credentials, options);
}

public Task ContinueWithAuthAsync(ContinueWithDefaultAuthOptions? options = null)
public Task ContinueWithAuthAsync(ContinueWithAuthDefaultCredentialsOptions? options = null)
{
return _bidi.Network.ContinueWithAuthAsync(this, options);
}

public Task ContinueWithAuthAsync(ContinueWithCancelledAuthOptions? options = null)
public Task ContinueWithAuthAsync(ContinueWithAuthCancelCredentialsOptions? options = null)
{
return _bidi.Network.ContinueWithAuthAsync(this, options);
}
Expand Down
5 changes: 2 additions & 3 deletions dotnet/test/common/BiDi/Network/NetworkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ public async Task CanContinueWithAuthCredentials()
{
await using var intercept = await bidi.Network.InterceptAuthAsync(async e =>
{
//TODO Seems it would be better to have method which takes abstract options
await e.Request.Request.ContinueWithAuthAsync(new AuthCredentials("test", "test"));
});

Expand All @@ -177,7 +176,7 @@ public async Task CanContinueWithDefaultCredentials()
{
await using var intercept = await bidi.Network.InterceptAuthAsync(async e =>
{
await e.Request.Request.ContinueWithAuthAsync(new ContinueWithDefaultAuthOptions());
await e.Request.Request.ContinueWithAuthAsync(new ContinueWithAuthDefaultCredentialsOptions());
});

var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = ReadinessState.Complete });
Expand All @@ -191,7 +190,7 @@ public async Task CanContinueWithCanceledCredentials()
{
await using var intercept = await bidi.Network.InterceptAuthAsync(async e =>
{
await e.Request.Request.ContinueWithAuthAsync(new ContinueWithCancelledAuthOptions());
await e.Request.Request.ContinueWithAuthAsync(new ContinueWithAuthCancelCredentialsOptions());
});

var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = ReadinessState.Complete });
Expand Down
Loading