mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-20 15:34:24 +01:00
Do not create if create API key is called on a non-existant user (Fix #4731)
This commit is contained in:
@@ -218,6 +218,8 @@ namespace BTCPayServer.Tests
|
|||||||
Permissions = new Permission[] { Permission.Create(Policies.CanViewInvoices, store.Id) },
|
Permissions = new Permission[] { Permission.Create(Policies.CanViewInvoices, store.Id) },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await AssertAPIError("user-not-found", () => unrestricted.CreateAPIKey("fewiofwuefo", new CreateApiKeyRequest()));
|
||||||
|
|
||||||
// Despite the grant, the user shouldn't be able to get the invoices!
|
// Despite the grant, the user shouldn't be able to get the invoices!
|
||||||
newUserClient = acc.CreateClientFromAPIKey(newUserAPIKey.ApiKey);
|
newUserClient = acc.CreateClientFromAPIKey(newUserAPIKey.ApiKey);
|
||||||
await Assert.ThrowsAsync<GreenfieldAPIException>(() => newUserClient.GetInvoices(store.Id));
|
await Assert.ThrowsAsync<GreenfieldAPIException>(() => newUserClient.GetInvoices(store.Id));
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Cors;
|
using Microsoft.AspNetCore.Cors;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NBitcoin;
|
using NBitcoin;
|
||||||
using NBitcoin.DataEncoders;
|
using NBitcoin.DataEncoders;
|
||||||
|
|
||||||
@@ -66,7 +67,14 @@ namespace BTCPayServer.Controllers.Greenfield
|
|||||||
{
|
{
|
||||||
Permissions = request.Permissions.Select(p => p.ToString()).Distinct().ToArray()
|
Permissions = request.Permissions.Select(p => p.ToString()).Distinct().ToArray()
|
||||||
});
|
});
|
||||||
|
try
|
||||||
|
{
|
||||||
await _apiKeyRepository.CreateKey(key);
|
await _apiKeyRepository.CreateKey(key);
|
||||||
|
}
|
||||||
|
catch (DbUpdateException)
|
||||||
|
{
|
||||||
|
return this.CreateAPIError("user-not-found", "This user does not exists");
|
||||||
|
}
|
||||||
return Ok(FromModel(key));
|
return Ok(FromModel(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
### Bug fix
|
### Bug fix
|
||||||
|
|
||||||
* Avoid crash when some plugins are installed (#4725)
|
* Avoid crash when some plugins are installed (#4725)
|
||||||
|
* Greenfield: Do not create if create API key is called on a non-existant user (Fix #4731)
|
||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user