From 418b476725acefa7fb386d81bf5494966db917d6 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sat, 27 May 2023 12:51:48 +0900 Subject: [PATCH] Bug fix on StoreRoleId parsing --- BTCPayServer.Tests/FastTests.cs | 19 +++++++++++++++++++ .../Services/Stores/StoreRepository.cs | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/BTCPayServer.Tests/FastTests.cs b/BTCPayServer.Tests/FastTests.cs index ff46a8fab..704721b27 100644 --- a/BTCPayServer.Tests/FastTests.cs +++ b/BTCPayServer.Tests/FastTests.cs @@ -26,6 +26,7 @@ using BTCPayServer.Services; using BTCPayServer.Services.Invoices; using BTCPayServer.Services.Labels; using BTCPayServer.Services.Rates; +using BTCPayServer.Services.Stores; using BTCPayServer.Validation; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -1382,6 +1383,24 @@ namespace BTCPayServer.Tests Assert.Equal(cache.States[0].Rates[0].Pair, cache2.States[0].Rates[0].Pair); } + [Fact] + public void CanParseStoreRoleId() + { + var id = StoreRoleId.Parse("test::lol"); + Assert.Equal("test", id.StoreId); + Assert.Equal("lol", id.Role); + Assert.Equal("test::lol", id.ToString()); + Assert.Equal("test::lol", id.Id); + Assert.False(id.IsServerRole); + + id = StoreRoleId.Parse("lol"); + Assert.Null(id.StoreId); + Assert.Equal("lol", id.Role); + Assert.Equal("lol", id.ToString()); + Assert.Equal("lol", id.Id); + Assert.True(id.IsServerRole); + } + [Fact] public void KitchenSinkTest() { diff --git a/BTCPayServer/Services/Stores/StoreRepository.cs b/BTCPayServer/Services/Stores/StoreRepository.cs index 3d2782c74..06dfb4e49 100644 --- a/BTCPayServer/Services/Stores/StoreRepository.cs +++ b/BTCPayServer/Services/Stores/StoreRepository.cs @@ -603,8 +603,8 @@ retry: } else { - role = str[0..i]; - storeId = str[(i + 2)..]; + storeId = str[0..i]; + role = str[(i + 2)..]; return new StoreRoleId(storeId, role); } }