|
|
|
@ -903,6 +903,234 @@ public abstract partial class OpenIddictServerIntegrationTests |
|
|
|
Assert.NotNull(response.AccessToken); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task ProcessAuthentication_MissingClientIdInDeviceRequestCausesAnError() |
|
|
|
{ |
|
|
|
// Arrange
|
|
|
|
await using var server = await CreateServerAsync(options => |
|
|
|
{ |
|
|
|
options.Configure(options => options.AcceptAnonymousClients = false); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var client = await server.CreateClientAsync(); |
|
|
|
|
|
|
|
// Act
|
|
|
|
var response = await client.PostAsync("/connect/device", new OpenIddictRequest |
|
|
|
{ |
|
|
|
ClientId = null |
|
|
|
}); |
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.Equal(Errors.InvalidClient, response.Error); |
|
|
|
Assert.Equal(SR.FormatID2029(Parameters.ClientId), response.ErrorDescription); |
|
|
|
Assert.Equal(SR.FormatID8000(SR.ID2029), response.ErrorUri); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task ProcessAuthentication_InvalidClientIdInDeviceRequestCausesAnError() |
|
|
|
{ |
|
|
|
// Arrange
|
|
|
|
var manager = CreateApplicationManager(mock => |
|
|
|
{ |
|
|
|
mock.Setup(manager => manager.FindByClientIdAsync("Fabrikam", It.IsAny<CancellationToken>())) |
|
|
|
.ReturnsAsync(value: null); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var server = await CreateServerAsync(options => |
|
|
|
{ |
|
|
|
options.Services.AddSingleton(manager); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var client = await server.CreateClientAsync(); |
|
|
|
|
|
|
|
// Act
|
|
|
|
var response = await client.PostAsync("/connect/device", new OpenIddictRequest |
|
|
|
{ |
|
|
|
ClientId = "Fabrikam" |
|
|
|
}); |
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.Equal(Errors.InvalidClient, response.Error); |
|
|
|
Assert.Equal(SR.FormatID2052(Parameters.ClientId), response.ErrorDescription); |
|
|
|
Assert.Equal(SR.FormatID8000(SR.ID2052), response.ErrorUri); |
|
|
|
|
|
|
|
Mock.Get(manager).Verify(manager => manager.FindByClientIdAsync("Fabrikam", It.IsAny<CancellationToken>()), Times.Once()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task ProcessAuthentication_MissingClientIdInIntrospectionRequestCausesAnError() |
|
|
|
{ |
|
|
|
// Arrange
|
|
|
|
await using var server = await CreateServerAsync(options => |
|
|
|
{ |
|
|
|
options.Configure(options => options.AcceptAnonymousClients = false); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var client = await server.CreateClientAsync(); |
|
|
|
|
|
|
|
// Act
|
|
|
|
var response = await client.PostAsync("/connect/introspect", new OpenIddictRequest |
|
|
|
{ |
|
|
|
Token = "2YotnFZFEjr1zCsicMWpAA" |
|
|
|
}); |
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.Equal(Errors.InvalidClient, response.Error); |
|
|
|
Assert.Equal(SR.FormatID2029(Parameters.ClientId), response.ErrorDescription); |
|
|
|
Assert.Equal(SR.FormatID8000(SR.ID2029), response.ErrorUri); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task ProcessAuthentication_InvalidClientIdInIntrospectionRequestCausesAnError() |
|
|
|
{ |
|
|
|
// Arrange
|
|
|
|
var manager = CreateApplicationManager(mock => |
|
|
|
{ |
|
|
|
mock.Setup(manager => manager.FindByClientIdAsync("Fabrikam", It.IsAny<CancellationToken>())) |
|
|
|
.ReturnsAsync(value: null); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var server = await CreateServerAsync(options => |
|
|
|
{ |
|
|
|
options.Services.AddSingleton(manager); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var client = await server.CreateClientAsync(); |
|
|
|
|
|
|
|
// Act
|
|
|
|
var response = await client.PostAsync("/connect/introspect", new OpenIddictRequest |
|
|
|
{ |
|
|
|
ClientId = "Fabrikam", |
|
|
|
ClientSecret = "7Fjfp0ZBr1KtDRbnfVdmIw", |
|
|
|
Token = "2YotnFZFEjr1zCsicMWpAA" |
|
|
|
}); |
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.Equal(Errors.InvalidClient, response.Error); |
|
|
|
Assert.Equal(SR.FormatID2052(Parameters.ClientId), response.ErrorDescription); |
|
|
|
Assert.Equal(SR.FormatID8000(SR.ID2052), response.ErrorUri); |
|
|
|
|
|
|
|
Mock.Get(manager).Verify(manager => manager.FindByClientIdAsync("Fabrikam", It.IsAny<CancellationToken>()), Times.Once()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task ProcessAuthentication_MissingClientIdInRevocationRequestCausesAnError() |
|
|
|
{ |
|
|
|
// Arrange
|
|
|
|
await using var server = await CreateServerAsync(options => |
|
|
|
{ |
|
|
|
options.Configure(options => options.AcceptAnonymousClients = false); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var client = await server.CreateClientAsync(); |
|
|
|
|
|
|
|
// Act
|
|
|
|
var response = await client.PostAsync("/connect/revoke", new OpenIddictRequest |
|
|
|
{ |
|
|
|
Token = "SlAV32hkKG", |
|
|
|
TokenTypeHint = TokenTypeHints.RefreshToken |
|
|
|
}); |
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.Equal(Errors.InvalidClient, response.Error); |
|
|
|
Assert.Equal(SR.FormatID2029(Parameters.ClientId), response.ErrorDescription); |
|
|
|
Assert.Equal(SR.FormatID8000(SR.ID2029), response.ErrorUri); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task ProcessAuthentication_InvalidClientIdInRevocationRequestCausesAnError() |
|
|
|
{ |
|
|
|
// Arrange
|
|
|
|
var manager = CreateApplicationManager(mock => |
|
|
|
{ |
|
|
|
mock.Setup(manager => manager.FindByClientIdAsync("Fabrikam", It.IsAny<CancellationToken>())) |
|
|
|
.ReturnsAsync(value: null); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var server = await CreateServerAsync(options => |
|
|
|
{ |
|
|
|
options.Services.AddSingleton(manager); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var client = await server.CreateClientAsync(); |
|
|
|
|
|
|
|
// Act
|
|
|
|
var response = await client.PostAsync("/connect/revoke", new OpenIddictRequest |
|
|
|
{ |
|
|
|
ClientId = "Fabrikam", |
|
|
|
ClientSecret = "7Fjfp0ZBr1KtDRbnfVdmIw", |
|
|
|
Token = "2YotnFZFEjr1zCsicMWpAA" |
|
|
|
}); |
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.Equal(Errors.InvalidClient, response.Error); |
|
|
|
Assert.Equal(SR.FormatID2052(Parameters.ClientId), response.ErrorDescription); |
|
|
|
Assert.Equal(SR.FormatID8000(SR.ID2052), response.ErrorUri); |
|
|
|
|
|
|
|
Mock.Get(manager).Verify(manager => manager.FindByClientIdAsync("Fabrikam", It.IsAny<CancellationToken>()), Times.Once()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task ProcessAuthentication_MissingClientIdInTokenRequestCausesAnError() |
|
|
|
{ |
|
|
|
// Arrange
|
|
|
|
await using var server = await CreateServerAsync(options => |
|
|
|
{ |
|
|
|
options.Configure(options => options.AcceptAnonymousClients = false); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var client = await server.CreateClientAsync(); |
|
|
|
|
|
|
|
// Act
|
|
|
|
var response = await client.PostAsync("/connect/token", new OpenIddictRequest |
|
|
|
{ |
|
|
|
ClientId = null, |
|
|
|
Code = "SplxlOBeZQQYbYS6WxSbIA", |
|
|
|
GrantType = GrantTypes.Password, |
|
|
|
Username = "johndoe", |
|
|
|
Password = "A3ddj3w" |
|
|
|
}); |
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.Equal(Errors.InvalidClient, response.Error); |
|
|
|
Assert.Equal(SR.FormatID2029(Parameters.ClientId), response.ErrorDescription); |
|
|
|
Assert.Equal(SR.FormatID8000(SR.ID2029), response.ErrorUri); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task ProcessAuthentication_InvalidClientIdInTokenRequestCausesAnError() |
|
|
|
{ |
|
|
|
// Arrange
|
|
|
|
var manager = CreateApplicationManager(mock => |
|
|
|
{ |
|
|
|
mock.Setup(manager => manager.FindByClientIdAsync("Fabrikam", It.IsAny<CancellationToken>())) |
|
|
|
.ReturnsAsync(value: null); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var server = await CreateServerAsync(options => |
|
|
|
{ |
|
|
|
options.Services.AddSingleton(manager); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var client = await server.CreateClientAsync(); |
|
|
|
|
|
|
|
// Act
|
|
|
|
var response = await client.PostAsync("/connect/token", new OpenIddictRequest |
|
|
|
{ |
|
|
|
ClientId = "Fabrikam", |
|
|
|
GrantType = GrantTypes.Password, |
|
|
|
Username = "johndoe", |
|
|
|
Password = "A3ddj3w" |
|
|
|
}); |
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.Equal(Errors.InvalidClient, response.Error); |
|
|
|
Assert.Equal(SR.FormatID2052(Parameters.ClientId), response.ErrorDescription); |
|
|
|
Assert.Equal(SR.FormatID8000(SR.ID2052), response.ErrorUri); |
|
|
|
|
|
|
|
Mock.Get(manager).Verify(manager => manager.FindByClientIdAsync("Fabrikam", It.IsAny<CancellationToken>()), Times.AtLeastOnce()); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(OpenIddictServerEndpointType.DeviceAuthorization)] |
|
|
|
[InlineData(OpenIddictServerEndpointType.Introspection)] |
|
|
|
|