Compare commits

...

318 Commits

Author SHA1 Message Date
2b9f390c64 update translation 2019-11-21 14:17:27 +09:00
ee42d5c7b4 bump 2019-11-21 14:15:04 +09:00
f809dd51a6 Merge pull request from NicolasDorier/feature/vault
Add hardware support via BTCPayServer Vault
2019-11-21 14:13:43 +09:00
1a8d6e5c05 Implement BTCPayServer vault derivation scheme import 2019-11-21 14:06:16 +09:00
869ba745b2 Merge pull request from bolatovumar/fix-1169
Add CSS variable for preformatted text color
2019-11-21 14:03:05 +09:00
180dfb6edf Add CSS variable for preformatted text color
fix 
2019-11-20 11:12:31 -08:00
45b08ac8d2 Add sponsor 2019-11-19 20:37:15 +09:00
9a4b385432 Add sponsor 2019-11-19 20:33:26 +09:00
08289b89c5 Merge pull request from pavlenex/supporters-sw
Add new supporter to readme
2019-11-19 20:32:42 +09:00
a31d1d81c8 Update README.md 2019-11-19 09:20:31 +01:00
e4c7bb0378 add wallet of satoshi to readme
add wallet of Satoshi, fix Lunanode spacing
2019-11-19 09:16:04 +01:00
374aaf2e2b add walletofsatoshi svg logo 2019-11-19 09:12:38 +01:00
52fd686993 Merge pull request from pavlenex/new-supporters-lw
add new supporter to readme
2019-11-19 00:31:06 +09:00
03c36ef0d2 add lunanode to readme 2019-11-18 15:55:56 +01:00
71a6ffac2e Adjust status message for WalletTransactions 2019-11-18 21:47:09 +09:00
92777ba181 Make sure SSH does not throw in separate thread 2019-11-18 17:15:40 +09:00
81843fb609 Do not delete the password from the seed 2019-11-18 17:00:54 +09:00
3af3ffd038 Merge pull request from dennisreimann/ui-improvements
UI: Payment request improvement
2019-11-18 14:23:51 +09:00
2ce5cd0b6f Merge pull request from bitcoinbrisbane/master
Add office 365 to the quick fill settings
2019-11-18 14:23:12 +09:00
d791fd59e9 Merge branch 'master' of github.com:bitcoinbrisbane/btcpayserver 2019-11-18 08:12:30 +10:00
6064e3ce55 Add office365 quick settings 2019-11-18 08:12:06 +10:00
0fcfe0e977 Can prune wallet transaction history 2019-11-17 17:13:09 +09:00
997df5c64d Remove build warnings 2019-11-17 16:50:28 +09:00
27af96662f Fix bug for Network not having a NBitcoin Network 2019-11-17 13:04:42 +09:00
0be6f3ca70 UI: Remove superfluous spaces when description is empty 2019-11-16 23:28:53 +01:00
7af80611b6 UI: Better payment request amounts display
Uses a table instead of list group items, so that the columns properly align (rows use the same grid). Also aligns the values on the right.
2019-11-16 22:59:51 +01:00
4c349803b6 Use Channel instead of blocking collection for the Invoice Watcher 2019-11-16 19:12:26 +09:00
35a4278ae8 Merge pull request from britttttk/app-button
Hide View button in crowdfund
2019-11-16 18:58:11 +09:00
06365b7b73 Merge pull request from Kukks/register-login-secure-lock
Do not allow login or register over an insecure connection
2019-11-16 18:15:16 +09:00
f31e013986 bump 2019-11-16 18:03:16 +09:00
fe1df743ce bump nbx 2019-11-16 17:22:51 +09:00
22ffd48cd4 refactor 2019-11-16 08:57:16 +01:00
c83bcd259d Testing happy messages, fix approval button 2019-11-16 15:20:54 +09:00
8ebac28ccf Fix tests 2019-11-16 15:07:02 +09:00
4e5001d7ef Delete password from the lnd seed backup 2019-11-16 14:07:43 +09:00
84fe14a1ed Test LND Seed Backup service and Logs. Use the Confirm View instead of poppup 2019-11-16 14:06:37 +09:00
6828730313 Merge pull request from dennisreimann/theme-fixes
Theme fixes
2019-11-16 12:36:50 +09:00
e540079220 Merge pull request from dennisreimann/main-bundle-script-order
Fix script order in main bundle
2019-11-16 12:36:03 +09:00
e99f806b66 Merge pull request from dennisreimann/page-titles
Page title fixes
2019-11-16 12:35:45 +09:00
b452f1d125 Limit custom table styles to small tables
Otherwise it overrides to many styles so that i.e. font-sizes with th .h*-classes do not work anymore.
2019-11-15 15:15:22 +01:00
f0a9d209a5 Fix bootstrap reference in cart bundle 2019-11-15 15:15:21 +01:00
984aa2912a Fix script order in main bundle
creative.js relies on ScrollReveal being present on initialization, so it has to be included after scrollreveal.min.js
2019-11-15 15:15:20 +01:00
c8937f6d46 POS app theme fixes 2019-11-15 15:15:19 +01:00
cb849ab23e Light/dark color fixes
fix
2019-11-15 15:15:18 +01:00
3bca3427eb Consistent use of page title on Pay Button page 2019-11-15 14:44:08 +01:00
a127b13db1 Add missing payment request page titles 2019-11-15 14:43:36 +01:00
a2f608266b Fix bootstrap reference in cart bundle 2019-11-15 14:01:18 +01:00
05f8b8d8af Fix script order in main bundle
creative.js relies on ScrollReveal being present on initialization, so it has to be included after scrollreveal.min.js
2019-11-15 13:56:03 +01:00
f1cef81d76 Do not allow login or register over an insecure connection 2019-11-15 12:39:17 +01:00
e1bf376f10 Mark up alert-links for better display 2019-11-15 11:24:27 +01:00
9298eab30d Improve QR code display on dark background 2019-11-15 11:23:52 +01:00
584528f903 Improve pay button display on dark background 2019-11-15 11:08:10 +01:00
3501920956 Set apart theme select from custom css file references 2019-11-15 11:06:09 +01:00
65a867e82d Fix css references on bootstrap kitchensink page 2019-11-15 11:05:12 +01:00
2bfea50014 Update NBXplorer 2019-11-15 18:53:20 +09:00
89539fca01 Fix build 2019-11-15 18:20:10 +09:00
240f6fa45a Allow /rates to pass storeId 2019-11-15 18:10:14 +09:00
c004065eea Apply some lipstick on the lnd seed backup 2019-11-15 17:55:55 +09:00
1cfba82d77 Hide button when missing required fields 2019-11-14 23:58:38 -07:00
3bdcbd8907 Small adjustment to make tables look better 2019-11-15 15:22:01 +09:00
fd53811fdd Adjust base font-size to match old style 2019-11-15 14:45:53 +09:00
5eeda40098 Addressing CSS inconsistencies compared to old design
Fixes: 
2019-11-14 22:48:15 -06:00
7bce316e78 Merge branch 'master' into feature/lndseedbackup 2019-11-14 21:02:56 -06:00
68f172b9ef Switching back to v as prefix, other scripts assume it's presence
z wouldn't work because some scripts in btcpayserver-docker re-append v as prefix to find tag
2019-11-14 21:00:39 -06:00
9b3e7338ba Fixing broken CrowdfundTests.CanContributeOnlyWhenAllowed test 2019-11-14 20:56:28 -06:00
c6ef6fc17d Removing bootstrap and creative start vendor dirs, moving to main 2019-11-14 20:41:53 -06:00
e4c797eaa7 Merge pull request from dennisreimann/ui-css-refactoring
UI: Support themes via CSS variables
2019-11-14 20:28:01 -06:00
bdca51a178 Fine tuning the classic theme 2019-11-14 21:10:17 +01:00
e147ce8606 Minor layout improvements 2019-11-14 18:45:35 +01:00
830286ecc1 Center content on forgot password page 2019-11-14 18:44:14 +01:00
bc56cab488 Fix colors in wallet send view 2019-11-14 18:44:13 +01:00
dd683db6d5 Bump up font size and spacings in classic theme 2019-11-14 18:44:12 +01:00
5436999b13 Fix welcome layout background 2019-11-14 18:44:11 +01:00
29946763ba Move theme switch to top 2019-11-14 18:42:58 +01:00
7160f7dc22 Add bootstrap kitchensink
Can be used to control the look of all elements:
/_bootstrap_kitchensink.html?theme=casa
2019-11-14 18:42:57 +01:00
e44db30ddb Finetune color settings
fix
2019-11-14 18:42:56 +01:00
458b2fd72e Register page fixes 2019-11-14 18:42:55 +01:00
66ffa5f987 Rename alpha theme variables to backdrop 2019-11-14 18:42:54 +01:00
dd8caa46c4 Remove modern theme option
For now as it is not really shaped yet.
2019-11-14 18:42:53 +01:00
55de85d829 Casa theme color fixes 2019-11-14 18:42:52 +01:00
10f782aa11 Integrate and adapt new register page 2019-11-14 18:42:51 +01:00
5bb6918465 Add Casa theme draft 2019-11-14 18:42:50 +01:00
205fd3c9ce Use grid consistently 2019-11-14 18:42:49 +01:00
50bf55cbdf Unify section headings 2019-11-14 18:42:48 +01:00
3a9ecd8b33 Dissect css rules and simplify color variables 2019-11-14 18:42:48 +01:00
5942a840b2 Move main bundle files also 2019-11-14 18:42:47 +01:00
6dd3c79c23 Move themes and bootstrap 2019-11-14 18:42:46 +01:00
a25e0ef592 add-theme-picker 2019-11-14 18:42:45 +01:00
29465cbadc Use "modern" theme as example 2019-11-14 18:42:44 +01:00
fdc1aa25e4 Use variable based bootstrap and creativestart
fix
2019-11-14 18:42:40 +01:00
04fbe42bda Merge pull request from bolatovumar/issue-1138
Vary page layout for registering new accounts
2019-11-14 23:58:37 +09:00
57a6949565 Fix View app on Crowdfunding () 2019-11-14 21:13:41 +09:00
bcb85e2084 Errors not working in PointOfSale () 2019-11-14 20:55:18 +09:00
6900964c03 Fix debug log not showing (Fix ) 2019-11-14 18:49:33 +09:00
3d2b8d2969 Merge pull request from bolatovumar/fix-1155
Improve mobile view on new welcome layout
2019-11-14 17:26:58 +09:00
c7da4e3eff Add TestTimeouts 2019-11-14 17:14:08 +09:00
9e31154808 Improve mobile view on new welcome layout
fix 
2019-11-13 18:46:58 -08:00
89353b8e7c Remove svg trash 2019-11-13 18:50:23 +09:00
b8eea53e01 Merge pull request from pavlenex/supporters-dglabs
Add supporter to readme
2019-11-13 18:43:43 +09:00
9bafce8069 Add DG Labs logo to readme 2019-11-13 10:38:31 +01:00
a9de1c2c64 Add link to foundation website 2019-11-13 17:37:57 +09:00
e6505040e0 Missing svg 2019-11-13 16:06:41 +09:00
92bdb20e1c Add new sponsor 2019-11-13 16:04:47 +09:00
c6bba9188b Improve error message for CanUsePosApp 2019-11-13 15:56:58 +09:00
c3a84f6577 Merge pull request from Kukks/bugfix/u2f
Fix U2F bug when using multiple devices
2019-11-13 15:37:14 +09:00
ba54b5aacf Merge pull request from Kukks/ndax
Bump ExchangeSharp, fixes breaking changes and switch to exchangeshar…
2019-11-13 15:36:52 +09:00
e92a15e072 Add logs to find out if tests hang on website getting operational 2019-11-13 15:24:56 +09:00
ad853c6985 Merge pull request from NicolasDorier/nico/remove-trezor
Remove Trezor in AddDerivationScheme
2019-11-13 15:20:12 +09:00
e7ff5c0a4b Remove Trezor in AddDerivationScheme 2019-11-13 15:10:33 +09:00
fef1bde9b6 Merge pull request from NicolasDorier/update/nbxplorerclient
Bump NBXplorer.Client
2019-11-13 14:45:10 +09:00
eb87d7cadc Bump NBXplorer.Client 2019-11-13 13:51:06 +09:00
5394e0a4a0 Merge pull request from Kukks/bugfix/ln-sats
Display proper rate for ln sats feature
2019-11-12 14:01:13 +09:00
0f0b846e04 Merge pull request from bolatovumar/fix-1029
Retain store ids when filtering invoices
2019-11-11 21:00:42 +09:00
ae869489b5 Merge pull request from pavlenex/readme-2
Add CTA at the bottom + fix broken table tag
2019-11-11 20:58:53 +09:00
cdc973cbea fix tests 2019-11-11 11:25:23 +01:00
bae9ca2a7a fix ambigous ref 2019-11-11 10:08:10 +01:00
0df7506ad5 Bump ExchangeSharp, fixes breaking changes and switch to exchangesharp provider for ndax 2019-11-11 07:14:29 +01:00
974101624b fix text 2019-11-10 18:51:51 +01:00
621a7d998d Display proper rate for ln sats feature
fixes 
2019-11-10 18:49:24 +01:00
539c7d6e17 fix for multiple U2F devices 2019-11-10 18:12:20 +01:00
2743641122 hidden challenges rendered 2019-11-10 17:32:28 +01:00
1d08a811e7 Enabling circleci builds on feature tags 2019-11-10 07:00:30 -06:00
c5ca02e48e Js cleanup based on Kukks feedback 2019-11-10 06:22:17 -06:00
bce201038f Including walletunlock.json file in TestData for easier debugging 2019-11-10 06:19:59 -06:00
c24bb443d3 Fixing check for external services that don't specify server 2019-11-10 06:12:32 -06:00
9c165d84ef Removing LND seed information from walletunlock.json 2019-11-10 06:12:32 -06:00
58b834fe9d Displaying information from walletunlock.json if file is present 2019-11-10 06:12:32 -06:00
2b1aac9aa9 Service page for LND Seed Backup 2019-11-10 06:12:32 -06:00
dfdb99165b Vary page layout for registering new accounts
address 
2019-11-09 21:24:19 -08:00
b75eaee6dd Merge pull request from escapedcat/feat/ledger-xpub-help
feat(stores): add ledger specific xpub help
2019-11-10 00:28:05 +09:00
888b06376d Merge pull request from Kukks/xmr-fix
fix moneromoney util
2019-11-10 00:07:27 +09:00
7f6b1e7e6e Merge pull request from bolatovumar/fix-1129
Make sure documentation tooltip link stays inline with label
2019-11-10 00:06:36 +09:00
8dd1efc126 Adding test timeout 2019-11-09 16:57:40 +09:00
9cd64bf81a Inline "allow custom payment amount" checkbox with label 2019-11-08 19:12:52 -08:00
2c14cece6b Make sure documentation tooltip link stays inline with label
close 
2019-11-08 19:12:51 -08:00
11c269693e feat(stores): add ledger specific xpub help
problem: maximum of 20 ledger accounts are being listed in the derivation-scheme select
solution: help users with i.e. multiple ledger accounts by providing link to docs for detailed info on where to find the xpub key manually
2019-11-08 15:24:12 +01:00
ae9b93ca8f Removing useless tool 2019-11-08 22:41:14 +09:00
563e95df7c Fix tests 2019-11-08 21:42:34 +09:00
5b37a9df0b Make sure we don't pass the psbt in GET url 2019-11-08 21:21:23 +09:00
28396206de Show the torrc config when debugging via F5 2019-11-08 17:26:32 +09:00
9d3026f676 Add torrc files in tests 2019-11-08 16:10:49 +09:00
0f7458254e Retain store ids when filtering invoices 2019-11-07 18:14:38 -08:00
2305a0a5c8 Add CTA at the bottom + fix broken table tag 2019-11-07 19:43:25 +01:00
7ce2ddb400 fix moneromoney util 2019-11-07 18:41:10 +01:00
13c8372329 Merge pull request from pavlenex/supporters-final
Add supporters, remove listed alts
2019-11-07 23:17:29 +09:00
8fd7ee0763 Add supporters, remove listed alts 2019-11-07 11:33:11 +01:00
aab7c08500 Unify StatusMessage handling 2019-11-07 18:59:51 +09:00
ff8de47e69 Fix tests 2019-11-07 18:36:45 +09:00
3ff9cc85ef Fix tests 2019-11-07 18:35:47 +09:00
0a2440e14c Fix test 2019-11-07 18:29:52 +09:00
d37abb53f0 Fix status message when a model is passed 2019-11-07 18:20:17 +09:00
656a3956b1 Fix strange message in PaymentRequests (Fix ) 2019-11-07 17:59:35 +09:00
c31e7593b6 Add label to FullyNoded 2019-11-07 17:08:24 +09:00
7be9083220 Update sponsor 2019-11-07 16:46:10 +09:00
b85667a191 Fix status message of PaymentRequest 2019-11-07 16:19:36 +09:00
892d906ac7 Fix tx link in payment request 2019-11-07 16:12:05 +09:00
0277708b2a Fix tor service parsing 2019-11-07 15:58:03 +09:00
d757aa2978 Fix typo 2019-11-07 15:48:56 +09:00
cf7bba9600 Fix services if there is more than one tor external services 2019-11-07 15:41:39 +09:00
a0d498812d bump 2019-11-07 14:35:18 +09:00
29e8783beb Update translations 2019-11-07 14:34:34 +09:00
57b87a55bc Show Bitcoin RPC service 2019-11-07 14:33:10 +09:00
9ff9377bc7 Make sure the recommended fees are different from the network fee rate 2019-11-07 13:45:45 +09:00
163ef031b9 Make sure the recommended fees are different from the network fee rate 2019-11-07 13:35:47 +09:00
1cfdd1489b Merge pull request from bolatovumar/master
Make recommended fee confirmation target configurable
2019-11-07 13:27:03 +09:00
0a9290a980 Make recommended fee confirmation target configurable
Address 
2019-11-06 16:21:33 -08:00
f0c2fb62df Select all link when clicked 2019-11-07 00:13:00 +09:00
24d6532dac Add onion link to login/register 2019-11-06 23:58:04 +09:00
fee1fe22a7 Use better svg version of the logo 2019-11-06 23:25:56 +09:00
d8103f7293 Fix webfont 2019-11-06 21:57:43 +09:00
3d3446e46a Improve design of register/login on mobile 2019-11-06 21:51:10 +09:00
22af4d2836 Because links are not reusable in LightningWalletService, it should not open in a new tab 2019-11-06 21:17:50 +09:00
06b2a3383d Merge pull request from NicolasDorier/fix/maintainence
Improve message in Maintainance page
2019-11-06 16:41:11 +09:00
06c3f01e41 Improve message in Maintainance page 2019-11-06 16:17:03 +09:00
d392880102 Merge pull request from NicolasDorier/ux/login-register
Add sponsor and new design to the login and registration page
2019-11-06 15:29:36 +09:00
55dd8da284 Redirect first run to register, redirect unlogged to login 2019-11-06 15:19:14 +09:00
e76f5b19b1 bump lightning package 2019-11-06 13:20:57 +09:00
5650b8560d Refactor the Header in its own partial view 2019-11-06 13:15:26 +09:00
2d80dbfa8f Custom logo and custom url for checkout page should accept any string (relative path) (Fix ) 2019-11-06 12:02:13 +09:00
c62aeb670a Merge pull request from rockstardev/cifixrefactor
Fixing CircleCi to run external test only in repo context, small refactor of LndServiceViewModel
2019-11-05 09:41:43 -06:00
1a407a2da3 Add sponsor and new design to the login and registration page 2019-11-05 18:01:43 +09:00
72d7e2dc5b Merge pull request from bolatovumar/issue-1111
Improve pay button display options section
2019-11-04 12:04:14 +09:00
a126ec1718 Renaming to LndServiceViewModel, used both by grpc and rest 2019-11-03 13:18:09 -06:00
bf59114a00 Run CircleCi external tests only in context of btcpayserver user & repo 2019-11-03 13:16:21 -06:00
6b587bfc31 Improve pay button display options section
address 
2019-11-03 09:53:09 -08:00
28a2017b65 Merge pull request from dennisreimann/paybutton
More pay button improvements
2019-11-03 20:26:55 +09:00
c3a6e9a799 Merge pull request from Kukks/fix-monero-qr
fix qr code amounts for monero
2019-11-03 20:26:35 +09:00
45c66a167b Merge pull request from Kukks/payment-request-fixes2
fix Payment request "Cancel invoice" button always showing
2019-11-03 20:25:46 +09:00
380629a961 Update BTCPayServer.Lightning 2019-11-03 16:34:14 +09:00
74fdd1358c Update translations 2019-11-03 16:31:01 +09:00
e9d63650b9 bump 2019-11-03 16:18:33 +09:00
9ecb27a9bd Fix and test /api-tokens (fix https://github.com/btcpayserver/woocommerce-plugin/issues/34) 2019-11-03 16:17:28 +09:00
b0ae878ef6 Merge pull request from NicolasDorier/ui/new-confirm
Redesign confirm forms
2019-11-03 15:37:33 +09:00
28cc4facd4 Redesign confirm form 2019-11-03 15:20:25 +09:00
749146ad3c fix Payment request "Cancel invoice" button always showing
The Cancel current invoice button always showed even when there was active invoice
2019-11-02 08:49:19 +01:00
a4ba93d249 fix qr code amounts for monero 2019-11-02 08:41:48 +01:00
7eae1f3b3c More pay button improvements 2019-10-31 11:31:30 +01:00
d66e8f2d13 Removing obsolete StatusMessage 2019-10-31 15:19:38 +09:00
058b768b0a update lightning charge in tests 2019-10-31 14:31:44 +09:00
3425f84507 Merge pull request from NicolasDorier/refactor/statusmessage
[WIP] Refactor StatusMessage and remove ExternalLogin
2019-10-31 14:12:05 +09:00
aad586232c Refactor StatusMessage and remove ExternalLogin 2019-10-31 14:11:33 +09:00
b514533814 Merge pull request from dennisreimann/paybutton
Improve pay button display
2019-10-31 14:01:38 +09:00
3b1f851f8a Improve pay button display
These changes should provide a more solid CSS approach to display the pay button in different scenarios. Also it fixes minor functionality issues like preselecting the merchant-chosen currency in the custom amount and slider dropdown.
2019-10-29 21:08:08 +01:00
99095f25d9 bump clightning 2019-10-29 16:46:22 +09:00
d79a28ac6f Merge pull request from rockstardev/lndseedless
Updating reference to new LND docker image and walletunlock.json path
2019-10-29 15:38:44 +09:00
120fe1ba85 Updating reference to new LND docker image and walletunlock.json path 2019-10-28 23:47:55 -05:00
ad8d8c31ab Merge pull request from Kukks/modal-close-fix
Fix: Close button for modal is broken
2019-10-28 14:26:20 +09:00
3e5ab70583 Fix: Close button for modal is broken
closes 
2019-10-27 08:13:30 +01:00
cd5b334a00 Make sure renci ssh does not prevent btcpay from closing 2019-10-26 23:40:35 +09:00
9a99b3fdc2 Fix bug: Could not delete store 2019-10-26 23:35:55 +09:00
2249ee195a Catch websockets exceptions 2019-10-23 16:11:20 +09:00
93cdbf7a1a Only push the released tag 2019-10-23 15:44:49 +09:00
22fa43f8d6 Version bump 2019-10-23 15:29:37 +09:00
39a6bd15d1 Update translations 2019-10-23 15:12:28 +09:00
1d8fe9fb93 Bump dbriize 2019-10-23 14:57:08 +09:00
565cac34b0 Update NBXplorer 2019-10-23 14:56:59 +09:00
1cb02b2913 Bump bundlerminifier 2019-10-23 14:56:48 +09:00
1174178771 Remove reliance on ambient routing values 2019-10-23 13:52:22 +09:00
f1a2cc2b65 Merge pull request from sam-sla/patch-2
Fix typo in SECURITY.md
2019-10-22 23:50:22 +09:00
36d97d1e74 Fix typo in SECURITY.md 2019-10-21 22:05:29 +02:00
12264d8e74 Make sure SSHClient Disconnect does not hang if a cancellationToken is passed 2019-10-21 18:43:53 +09:00
4d68b12080 Rewrite some EF queries to make EF3.0 happy 2019-10-21 18:38:57 +09:00
3c7137830e Make sure that the SSL connection does not prevent btcpayserver from restarting 2019-10-21 16:34:26 +09:00
4f1b4131cb Add more logs on hosted service exit 2019-10-21 14:03:55 +09:00
ccb45e3a99 Remove empty folder 2019-10-21 13:31:43 +09:00
f3461bfbe6 Show success message when derivation scheme is updated 2019-10-21 13:24:13 +09:00
22b05500f1 Reactivate ndax 2019-10-20 17:52:30 +09:00
66a2383ad1 Make CanHandleRefundEmailForm less capricious 2019-10-20 16:47:48 +09:00
7d6fb21a8c Fix test 2019-10-20 16:45:40 +09:00
5054e76d64 Fix build 2019-10-20 16:24:11 +09:00
9adb825c30 Do not ask for email in checkout by default (Fix ) 2019-10-20 15:46:34 +09:00
9a28dc5121 Pass cancellationToken around in the Kraken Provider 2019-10-20 15:24:07 +09:00
c82c67359c Merge pull request from reablaz/master
updated AppsUpdate view with correct GET request
2019-10-19 18:27:56 +09:00
59afc05661 Log hosted services exiting 2019-10-19 14:12:43 +09:00
c05820224e Log paytester dispose 2019-10-19 14:09:19 +09:00
fee106abef Remove possible NRE when app start 2019-10-19 13:50:52 +09:00
48fa11759f Missing files 2019-10-19 00:54:43 +09:00
eac4c91820 Move Bitpay authentication class in BTCPayServer.Security 2019-10-19 00:54:20 +09:00
037fcf93f5 Merge branch 'refactor/remove-scopes' 2019-10-18 23:58:43 +09:00
dabe805602 Remove dead link 2019-10-18 23:58:25 +09:00
dacf5c1e16 Go back to .net 7.3 2019-10-18 23:50:18 +09:00
da2e8665a1 Remove unused scope, assert policy on store listing 2019-10-18 23:42:06 +09:00
8643c04a39 Additional fixes for 3.0 2019-10-18 21:46:34 +09:00
c5ba063edf Move OpenId folder 2019-10-18 21:36:32 +09:00
9648836e2d Merge pull request from NicolasDorier/migration/openiddict30
Update to OpenIddict3.0
2019-10-18 21:30:27 +09:00
3c9b58916b Update to OpenIddict3.0 2019-10-18 19:02:23 +09:00
d56a5ad86e Merge pull request from bolatovumar/feat-1036
Add option to show recommeded fee on checkout invoice
2019-10-18 12:13:39 +09:00
cd5cc6435c make lightning scheme lowercase (Fix ) 2019-10-17 00:52:19 +09:00
c908301b84 Add option to show recommeded fee on checkout invoice
Address 
2019-10-14 10:09:26 -07:00
e68d76b56d Add timeout to tests 2019-10-14 23:50:51 +09:00
8339ec59b7 Merge pull request from bolatovumar/issue-1089
Make UI checkboxes inline with their labels
2019-10-14 22:47:29 +09:00
c5cfd7921a Merge pull request from NicolasDorier/refactor/authorization
Refactor authorizations
2019-10-14 22:46:26 +09:00
e584004b23 Make UI checkboxes inline with their labels
address 
2019-10-13 20:07:41 -07:00
281a2461ad Refactor authorizations 2019-10-14 00:24:41 +09:00
bd94b5f84e Temporarily remove docker image cache for circleci 2019-10-12 20:38:41 +09:00
2b040b3465 Merge pull request from Eskyee/patch-1
Update launchSettings.json
2019-10-12 12:28:28 +09:00
0e452c7cdf Update launchSettings.json
I`m  the Removing Docker-Regtest-https-monero as this loads as a default, which I didn't ask for, it  default in my builds config, launchSettings json, also I think since this json was changed, it gave my Mac VS a indent bug somehow, ?? But i may be wrong there, 
can Nicolas please review ?? this is the correct way I would remove Docker-Regtest-https-monero from my folk ?? thanks
2019-10-12 03:43:30 +01:00
2acdc77289 Update lang 2019-10-10 19:46:29 +09:00
fda6a1a77b Use ClaimTransformer instead of Authentication's JWT 2019-10-10 19:46:29 +09:00
7e5c593e09 Merge pull request from bolatovumar/fix-1078
[PoS app] Show card scrollbar only when necessary
2019-10-10 15:22:29 +09:00
40b191ef49 Skip HeadersOverrideMiddleware if on onion 2019-10-10 14:10:01 +09:00
a92f0fe289 [PoS app] Show card scrollbar only when necessary
fix 
2019-10-09 20:41:24 -07:00
ca17efbc29 Add missing file 2019-10-10 09:49:03 +09:00
5025e0dd4d Allow xforwardedproto to be override via configuration 2019-10-09 22:26:54 +09:00
1325c5d441 Add TestTimeout to some tests 2019-10-08 16:32:22 +09:00
30585d2cc1 Merge pull request from rockstardev/master
Replacing donation widget with link new donate page
2019-10-08 12:19:42 +09:00
98468f4eb0 Replacing donation widget with link new donate page
Resolves 

Co-authored-by: vswee <vswee@users.noreply.github.com>
2019-10-07 17:30:20 -05:00
39876dea07 Use random ports in container tests 2019-10-07 16:25:27 +09:00
03917ec806 Remove possible crash at shutdown 2019-10-07 16:06:36 +09:00
1c9a91140b Asyncify tests 2019-10-07 16:04:25 +09:00
3417556f5c Update pomelo on .netcore3.0 2019-10-07 15:12:22 +09:00
0cc2fa962d Prepare Startup.cs for netcoreapp30 2019-10-07 13:03:50 +09:00
8ba1303968 Move BitpayMiddleware up the stack 2019-10-07 12:43:17 +09:00
ae2b055fb5 Fix build 2019-10-06 23:41:27 +09:00
a919d3ddec Move TryGetSolutionDirectoryInfo in test utils 2019-10-06 23:38:57 +09:00
102b38b5a8 Make test CanUsePaymentMethodDropdown more reliable 2019-10-06 23:13:42 +09:00
56a363adf9 Add more test timeout 2019-10-06 22:51:01 +09:00
5c8dcb0292 Add test timeout 2019-10-06 22:49:28 +09:00
0fd5c722f6 Add test timeout for some selenium tests 2019-10-06 22:24:28 +09:00
b86befbdaf Merge pull request from pavlenex/security-md
Add Security.md
2019-10-06 22:20:26 +09:00
53310dee8a Add Security.md 2019-10-06 12:25:40 +02:00
78b86ce0ea Fix build in netcoreapp21 2019-10-06 18:47:49 +09:00
3bdc7c102a Fix Startup in netcoreapp3.0 2019-10-06 16:00:38 +09:00
f9714f0be0 Fix build 2019-10-06 15:54:19 +09:00
536f98b566 Fix entity framework queries to work in netcoreapp3.0 2019-10-06 15:48:12 +09:00
f4977e7f9f Prepare AuthenticationTests for .netcoreapp3.0 2019-10-05 20:45:09 +09:00
68807bae37 Do not use AsAsyncEnumerable() 2019-10-04 22:55:38 +09:00
ccc2d0e13c Exclude Google Cloud Storage for .netcoreapp3.0, it depends on System.Interactive.Linq which create namespace conflict with the new AsyncEnumerable 2019-10-04 17:56:08 +09:00
c2032ee15b Prepare the Authentication controller for .netcoreapp3.0 2019-10-04 17:21:53 +09:00
724a5b5460 Prepare code to move to netcoreapp3.0 2019-10-04 17:17:11 +09:00
c9ec0f9d3c Prepare startup.cs for netcoreapp3.0 2019-10-03 18:46:09 +09:00
411fe90b8c Can compile tests in netcoreapp3.0 2019-10-03 18:25:07 +09:00
a56004fbef Remove a warning on .netcoreapp3.0 2019-10-03 18:15:08 +09:00
e75edac3c1 Make .netcoreapp 3.0 build happy 2019-10-03 18:00:07 +09:00
aaa05eb5ec Fix build 2019-10-03 17:37:10 +09:00
8d0d80e086 Fix build 2019-10-03 17:14:07 +09:00
4d84343a80 Prepare BTCPayServer for .netcore 3.0 2019-10-03 17:06:49 +09:00
275fbc81e7 Prepare BTCPayServer.Data for .netcore 3.0 2019-10-03 16:36:02 +09:00
d23adfbd78 Prepare BTCPayServer.Common and BTCPayServer.Rating for .netcore 3.0 2019-10-03 16:13:12 +09:00
f7b85babfe Merge pull request from rockstardev/master
Cleanup U2F namespace to correspond to folder path
2019-10-03 12:57:53 +09:00
56e85b68d9 Csproj cleanup, reorganizing namespaces, fixing tests 2019-10-02 22:41:53 -05:00
755a6bf8e6 Cleaning up references to old U2F\Services folder 2019-10-02 12:38:06 -05:00
7282199c31 Cleanup U2F namespace to correspond to folder path 2019-10-02 12:32:41 -05:00
639f5d2fc4 Make sure calling monero related controllers can't be done if the shitcoin is not supported 2019-10-01 15:30:27 +09:00
8c8ef9d3ca Rename shitcoins to altcoins 2019-09-30 20:43:15 +09:00
2c5c6d28e3 Fix broken getting started link in readme () 2019-09-30 18:42:35 +09:00
fd78d02576 Moving Monero classes into BTCPayServer.Common 2019-09-30 17:58:41 +09:00
3a0328d0be Moving shitcoin code in shitcoin folder 2019-09-30 17:51:47 +09:00
d66b111121 xmr () 2019-09-30 17:32:43 +09:00
8cbc58ea2f updated AppsUpdate view with correct GET request
So user can request invoice data by invoice id from btcpayserver, to verify callback
2019-09-29 15:12:35 +03:00
3366c86b16 Authorize granular permissions ()
* granular scope permissions for api

* final fixes and styling

* prettify code

* fix missing policy
2019-09-29 16:23:31 +09:00
c7e3241a85 Update info link in ListTokens 2019-09-29 16:21:25 +09:00
1c2c3ede80 Update help link 2019-09-29 16:12:03 +09:00
0f46da2e6b Update c-lightning 2019-09-29 13:53:18 +09:00
514386ecdd Remove NDax support 2019-09-29 11:58:16 +09:00
2257b95732 bump 2019-09-24 15:22:26 +09:00
7a5cfcf50f Fix docker-entrypoint for raspberry 2019-09-24 15:21:50 +09:00
929b5c7951 Add display attributes. Fix 2019-08-24 15:39:43 +10:00
458 changed files with 18284 additions and 21080 deletions
.circleci
BTCPayServer.Common
BTCPayServer.Data
BTCPayServer.Rating
BTCPayServer.Tests
BTCPayServer
Authentication/OpenId
BTCPayServer.csproj
Configuration
Controllers
CurrencyValue.cs
Data
DerivationSchemeSettings.csExtensions.cs
Extensions
Filters
HostedServices
Hosting
HwiWebSocketTransport.csMigrationStartupTask.cs
ModelBinders
Models
PaymentRequest
Payments
Program.cs
Properties
Security
Services
U2F
Views
Account
Apps
AppsPublic
Authorization
Home
Invoice
Manage
MoneroLikeStore
PaymentRequest
PublicLightningNodeInfo
Server
Shared
Stores
UserStores
Wallets
_ViewImports.cshtml
WebSocketHelper.csWellKnownTempData.csbundleconfig.json
wwwroot
Build
Nuget.ConfigREADME.mdSECURITY.mdamd64.Dockerfilearm32v7.Dockerfilebtcpayserver.slndocker-entrypoint.shnuget.configpublish-docker.ps1

@ -2,7 +2,7 @@ version: 2
jobs:
fast_tests:
machine:
docker_layer_caching: true
enabled: true
steps:
- checkout
- run:
@ -10,7 +10,7 @@ jobs:
cd .circleci && ./run-tests.sh "Fast=Fast"
selenium_tests:
machine:
docker_layer_caching: true
enabled: true
steps:
- checkout
- run:
@ -18,7 +18,7 @@ jobs:
cd .circleci && ./run-tests.sh "Selenium=Selenium"
integration_tests:
machine:
docker_layer_caching: true
enabled: true
steps:
- checkout
- run:
@ -26,18 +26,22 @@ jobs:
cd .circleci && ./run-tests.sh "Integration=Integration"
external_tests:
machine:
docker_layer_caching: true
enabled: true
steps:
- checkout
- run:
command: |
cd .circleci && ./run-tests.sh "ExternalIntegration=ExternalIntegration"
if [ "$CIRCLE_PROJECT_USERNAME" == "btcpayserver" ] && [ "$CIRCLE_PROJECT_REPONAME" == "btcpayserver" ]; then
cd .circleci && ./run-tests.sh "ExternalIntegration=ExternalIntegration"
else
echo "Skipping running ExternalIntegration tests outside of context of main user and repository that have access to secrets"
fi
# publish jobs require $DOCKERHUB_REPO, $DOCKERHUB_USER, $DOCKERHUB_PASS defined
amd64:
machine:
docker_layer_caching: true
enabled: true
steps:
- checkout
- run:
@ -50,7 +54,7 @@ jobs:
arm32v7:
machine:
docker_layer_caching: true
enabled: true
steps:
- checkout
- run:
@ -100,15 +104,16 @@ workflows:
# ignore any commit on any branch by default
branches:
ignore: /.*/
# only act on version tags
# only act on version tags v1.0.0.88
# OR feature tags like vlndseedbackup
tags:
only: /v[1-9]+(\.[0-9]+)*/
only: /(v[1-9]+(\.[0-9]+)*)|(v[a-z]+)/
- arm32v7:
filters:
branches:
ignore: /.*/
tags:
only: /v[1-9]+(\.[0-9]+)*/
only: /(v[1-9]+(\.[0-9]+)*)|(v[a-z]+)/
- multiarch:
requires:
- amd64
@ -117,4 +122,4 @@ workflows:
branches:
ignore: /.*/
tags:
only: /v[1-9]+(\.[0-9]+)*/
only: /(v[1-9]+(\.[0-9]+)*)|(v[a-z]+)/

@ -20,7 +20,7 @@ namespace BTCPayServer
NBitcoinNetwork = nbxplorerNetwork.NBitcoinNetwork,
NBXplorerNetwork = nbxplorerNetwork,
UriScheme = "bitcoinplus",
DefaultRateRules = new[]
DefaultRateRules = new[]
{
"XBC_X = XBC_BTC * BTC_X",
"XBC_BTC = cryptopia(XBC_BTC)"

@ -56,6 +56,8 @@ namespace BTCPayServer
InitFeathercoin();
InitGroestlcoin();
InitViacoin();
InitMonero();
// Assume that electrum mappings are same as BTC if not specified
foreach (var network in _Networks.Values.OfType<BTCPayNetwork>())
{

@ -0,0 +1,21 @@
using NBitcoin;
namespace BTCPayServer
{
public partial class BTCPayNetworkProvider
{
public void InitMonero()
{
Add(new MoneroLikeSpecificBtcPayNetwork()
{
CryptoCode = "XMR",
DisplayName = "Monero",
BlockExplorerLink =
NetworkType == NetworkType.Mainnet
? "https://www.exploremonero.com/transaction/{0}"
: "https://testnet.xmrchain.net/tx/{0}",
CryptoImagePath = "/imlegacy/monero.svg"
});
}
}
}

@ -0,0 +1,7 @@
namespace BTCPayServer
{
public class MoneroLikeSpecificBtcPayNetwork : BTCPayNetworkBase
{
public int MaxTrackedConfirmation = 10;
}
}

@ -0,0 +1,121 @@
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace BTCPayServer.Services.Altcoins.Monero.RPC
{
public class JsonRpcClient
{
private readonly Uri _address;
private readonly string _username;
private readonly string _password;
private readonly HttpClient _httpClient;
public JsonRpcClient(Uri address, string username, string password, HttpClient client = null)
{
_address = address;
_username = username;
_password = password;
_httpClient = client ?? new HttpClient();
}
public async Task<TResponse> SendCommandAsync<TRequest, TResponse>(string method, TRequest data,
CancellationToken cts = default(CancellationToken))
{
var jsonSerializer = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
var httpRequest = new HttpRequestMessage()
{
Method = HttpMethod.Post,
RequestUri = new Uri(_address, "json_rpc"),
Content = new StringContent(
JsonConvert.SerializeObject(new JsonRpcCommand<TRequest>(method, data), jsonSerializer),
Encoding.UTF8, "application/json")
};
httpRequest.Headers.Accept.Clear();
httpRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpRequest.Headers.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(Encoding.Default.GetBytes($"{_username}:{_password}")));
var rawResult = await _httpClient.SendAsync(httpRequest, cts);
var rawJson = await rawResult.Content.ReadAsStringAsync();
rawResult.EnsureSuccessStatusCode();
JsonRpcResult<TResponse> response;
try
{
response = JsonConvert.DeserializeObject<JsonRpcResult<TResponse>>(rawJson, jsonSerializer);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(rawJson);
throw;
}
if (response.Error != null)
{
throw new JsonRpcApiException()
{
Error = response.Error
};
}
return response.Result;
}
public class NoRequestModel
{
public static NoRequestModel Instance = new NoRequestModel();
}
internal class JsonRpcApiException : Exception
{
public JsonRpcResultError Error { get; set; }
public override string Message => Error?.Message;
}
public class JsonRpcResultError
{
[JsonProperty("code")] public int Code { get; set; }
[JsonProperty("message")] public string Message { get; set; }
[JsonProperty("data")] dynamic Data { get; set; }
}
internal class JsonRpcResult<T>
{
[JsonProperty("result")] public T Result { get; set; }
[JsonProperty("error")] public JsonRpcResultError Error { get; set; }
[JsonProperty("id")] public string Id { get; set; }
}
internal class JsonRpcCommand<T>
{
[JsonProperty("jsonRpc")] public string JsonRpc { get; set; } = "2.0";
[JsonProperty("id")] public string Id { get; set; } = Guid.NewGuid().ToString();
[JsonProperty("method")] public string Method { get; set; }
[JsonProperty("params")] public T Parameters { get; set; }
public JsonRpcCommand()
{
}
public JsonRpcCommand(string method, T parameters)
{
Method = method;
Parameters = parameters;
}
}
}
}

@ -0,0 +1,9 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class CreateAccountRequest
{
[JsonProperty("label")] public string Label { get; set; }
}
}

@ -0,0 +1,10 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class CreateAccountResponse
{
[JsonProperty("account_index")] public long AccountIndex { get; set; }
[JsonProperty("address")] public string Address { get; set; }
}
}

@ -0,0 +1,10 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class CreateAddressRequest
{
[JsonProperty("account_index")] public long AccountIndex { get; set; }
[JsonProperty("label")] public string Label { get; set; }
}
}

@ -0,0 +1,10 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class CreateAddressResponse
{
[JsonProperty("address")] public string Address { get; set; }
[JsonProperty("address_index")] public long AddressIndex { get; set; }
}
}

@ -0,0 +1,9 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class GetAccountsRequest
{
[JsonProperty("tag")] public string Tag { get; set; }
}
}

@ -0,0 +1,14 @@
using System.Collections.Generic;
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class GetAccountsResponse
{
[JsonProperty("subaddress_accounts")] public List<SubaddressAccount> SubaddressAccounts { get; set; }
[JsonProperty("total_balance")] public decimal TotalBalance { get; set; }
[JsonProperty("total_unlocked_balance")]
public decimal TotalUnlockedBalance { get; set; }
}
}

@ -0,0 +1,9 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public class GetFeeEstimateRequest
{
[JsonProperty("grace_blocks")] public int? GraceBlocks { get; set; }
}
}

@ -0,0 +1,11 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public class GetFeeEstimateResponse
{
[JsonProperty("fee")] public long Fee { get; set; }
[JsonProperty("status")] public string Status { get; set; }
[JsonProperty("untrusted")] public bool Untrusted { get; set; }
}
}

@ -0,0 +1,9 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class GetHeightResponse
{
[JsonProperty("height")] public long Height { get; set; }
}
}

@ -0,0 +1,11 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public class GetTransferByTransactionIdRequest
{
[JsonProperty("txid")] public string TransactionId { get; set; }
[JsonProperty("account_index")] public long AccountIndex { get; set; }
}
}

@ -0,0 +1,32 @@
using System.Collections.Generic;
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class GetTransferByTransactionIdResponse
{
[JsonProperty("transfer")] public TransferItem Transfer { get; set; }
[JsonProperty("transfers")] public IEnumerable<TransferItem> Transfers { get; set; }
public partial class TransferItem
{
[JsonProperty("address")] public string Address { get; set; }
[JsonProperty("amount")] public long Amount { get; set; }
[JsonProperty("confirmations")] public long Confirmations { get; set; }
[JsonProperty("double_spend_seen")] public bool DoubleSpendSeen { get; set; }
[JsonProperty("fee")] public long Fee { get; set; }
[JsonProperty("height")] public long Height { get; set; }
[JsonProperty("note")] public string Note { get; set; }
[JsonProperty("payment_id")] public string PaymentId { get; set; }
[JsonProperty("subaddr_index")] public SubaddrIndex SubaddrIndex { get; set; }
[JsonProperty("suggested_confirmations_threshold")]
public long SuggestedConfirmationsThreshold { get; set; }
[JsonProperty("timestamp")] public long Timestamp { get; set; }
[JsonProperty("txid")] public string Txid { get; set; }
[JsonProperty("type")] public string Type { get; set; }
[JsonProperty("unlock_time")] public long UnlockTime { get; set; }
}
}
}

@ -0,0 +1,19 @@
using System.Collections.Generic;
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class GetTransfersRequest
{
[JsonProperty("in")] public bool In { get; set; }
[JsonProperty("out")] public bool Out { get; set; }
[JsonProperty("pending")] public bool Pending { get; set; }
[JsonProperty("failed")] public bool Failed { get; set; }
[JsonProperty("pool")] public bool Pool { get; set; }
[JsonProperty("filter_by_height ")] public bool FilterByHeight { get; set; }
[JsonProperty("min_height")] public long MinHeight { get; set; }
[JsonProperty("max_height")] public long MaxHeight { get; set; }
[JsonProperty("account_index")] public long AccountIndex { get; set; }
[JsonProperty("subaddr_indices")] public List<long> SubaddrIndices { get; set; }
}
}

@ -0,0 +1,36 @@
using System.Collections.Generic;
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class GetTransfersResponse
{
[JsonProperty("in")] public List<GetTransfersResponseItem> In { get; set; }
[JsonProperty("out")] public List<GetTransfersResponseItem> Out { get; set; }
[JsonProperty("pending")] public List<GetTransfersResponseItem> Pending { get; set; }
[JsonProperty("failed")] public List<GetTransfersResponseItem> Failed { get; set; }
[JsonProperty("pool")] public List<GetTransfersResponseItem> Pool { get; set; }
public partial class GetTransfersResponseItem
{
[JsonProperty("address")] public string Address { get; set; }
[JsonProperty("amount")] public long Amount { get; set; }
[JsonProperty("confirmations")] public long Confirmations { get; set; }
[JsonProperty("double_spend_seen")] public bool DoubleSpendSeen { get; set; }
[JsonProperty("fee")] public long Fee { get; set; }
[JsonProperty("height")] public long Height { get; set; }
[JsonProperty("note")] public string Note { get; set; }
[JsonProperty("payment_id")] public string PaymentId { get; set; }
[JsonProperty("subaddr_index")] public SubaddrIndex SubaddrIndex { get; set; }
[JsonProperty("suggested_confirmations_threshold")]
public long SuggestedConfirmationsThreshold { get; set; }
[JsonProperty("timestamp")] public long Timestamp { get; set; }
[JsonProperty("txid")] public string Txid { get; set; }
[JsonProperty("type")] public string Type { get; set; }
[JsonProperty("unlock_time")] public long UnlockTime { get; set; }
}
}
}

@ -0,0 +1,33 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class Info
{
[JsonProperty("address")] public string Address { get; set; }
[JsonProperty("avg_download")] public long AvgDownload { get; set; }
[JsonProperty("avg_upload")] public long AvgUpload { get; set; }
[JsonProperty("connection_id")] public string ConnectionId { get; set; }
[JsonProperty("current_download")] public long CurrentDownload { get; set; }
[JsonProperty("current_upload")] public long CurrentUpload { get; set; }
[JsonProperty("height")] public long Height { get; set; }
[JsonProperty("host")] public string Host { get; set; }
[JsonProperty("incoming")] public bool Incoming { get; set; }
[JsonProperty("ip")] public string Ip { get; set; }
[JsonProperty("live_time")] public long LiveTime { get; set; }
[JsonProperty("local_ip")] public bool LocalIp { get; set; }
[JsonProperty("localhost")] public bool Localhost { get; set; }
[JsonProperty("peer_id")] public string PeerId { get; set; }
[JsonProperty("port")]
[JsonConverter(typeof(ParseStringConverter))]
public long Port { get; set; }
[JsonProperty("recv_count")] public long RecvCount { get; set; }
[JsonProperty("recv_idle_time")] public long RecvIdleTime { get; set; }
[JsonProperty("send_count")] public long SendCount { get; set; }
[JsonProperty("send_idle_time")] public long SendIdleTime { get; set; }
[JsonProperty("state")] public string State { get; set; }
[JsonProperty("support_flags")] public long SupportFlags { get; set; }
}
}

@ -0,0 +1,13 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class MakeUriRequest
{
[JsonProperty("address")] public string Address { get; set; }
[JsonProperty("amount")] public long Amount { get; set; }
[JsonProperty("payment_id")] public string PaymentId { get; set; }
[JsonProperty("tx_description")] public string TxDescription { get; set; }
[JsonProperty("recipient_name")] public string RecipientName { get; set; }
}
}

@ -0,0 +1,9 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class MakeUriResponse
{
[JsonProperty("uri")] public string Uri { get; set; }
}
}

@ -0,0 +1,39 @@
using System;
using System.Globalization;
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
internal class ParseStringConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(long) || t == typeof(long?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader);
long l;
if (Int64.TryParse(value, out l))
{
return l;
}
throw new Exception("Cannot unmarshal type long");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (long)untypedValue;
serializer.Serialize(writer, value.ToString(CultureInfo.InvariantCulture));
return;
}
public static readonly ParseStringConverter Singleton = new ParseStringConverter();
}
}

@ -0,0 +1,9 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class Peer
{
[JsonProperty("info")] public Info Info { get; set; }
}
}

@ -0,0 +1,10 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class SubaddrIndex
{
[JsonProperty("major")] public long Major { get; set; }
[JsonProperty("minor")] public long Minor { get; set; }
}
}

@ -0,0 +1,14 @@
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class SubaddressAccount
{
[JsonProperty("account_index")] public long AccountIndex { get; set; }
[JsonProperty("balance")] public decimal Balance { get; set; }
[JsonProperty("base_address")] public string BaseAddress { get; set; }
[JsonProperty("label")] public string Label { get; set; }
[JsonProperty("tag")] public string Tag { get; set; }
[JsonProperty("unlocked_balance")] public decimal UnlockedBalance { get; set; }
}
}

@ -0,0 +1,13 @@
using System.Collections.Generic;
using Newtonsoft.Json;
namespace BTCPayServer.Services.Altcoins.Monero.RPC.Models
{
public partial class SyncInfoResponse
{
[JsonProperty("height")] public long Height { get; set; }
[JsonProperty("peers")] public List<Peer> Peers { get; set; }
[JsonProperty("status")] public string Status { get; set; }
[JsonProperty("target_height")] public long? TargetHeight { get; set; }
}
}

@ -0,0 +1,20 @@
using System.Globalization;
namespace BTCPayServer.Services.Altcoins.Monero.Utils
{
public class MoneroMoney
{
public static decimal Convert(long piconero)
{
var amt = piconero.ToString(CultureInfo.InvariantCulture).PadLeft(12, '0');
amt = amt.Length == 12 ? $"0.{amt}" : amt.Insert(amt.Length - 12, ".");
return decimal.Parse(amt, CultureInfo.InvariantCulture);
}
public static long Convert(decimal monero)
{
return System.Convert.ToInt64(monero * 1000000000000);
}
}
}

@ -52,6 +52,7 @@ namespace BTCPayServer
public string LightningImagePath { get; set; }
public BTCPayDefaultSettings DefaultSettings { get; set; }
public KeyPath CoinType { get; internal set; }
public Dictionary<uint, DerivationType> ElectrumMapping = new Dictionary<uint, DerivationType>();
public int MaxTrackedConfirmation { get; internal set; } = 6;
@ -103,7 +104,6 @@ namespace BTCPayServer
public abstract class BTCPayNetworkBase
{
public string CryptoCode { get; internal set; }
public string BlockExplorerLink { get; internal set; }
public string DisplayName { get; set; }
@ -126,12 +126,12 @@ namespace BTCPayServer
public virtual T ToObject<T>(string json)
{
return JsonConvert.DeserializeObject<T>(json);
return NBitcoin.JsonConverters.Serializer.ToObject<T>(json, null);
}
public virtual string ToString<T>(T obj)
{
return JsonConvert.SerializeObject(obj);
return NBitcoin.JsonConverters.Serializer.ToString(obj, null);
}
}
}

@ -3,8 +3,8 @@
<Import Project="../Build/Common.csproj" />
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.9" />
<PackageReference Include="NBitcoin" Version="4.2.4" />
<PackageReference Include="NBXplorer.Client" Version="2.0.0.19" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.9" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
<FrameworkReference Include="Microsoft.AspNetCore.App" Condition="'$(TargetFramework)' != 'netcoreapp2.1'" />
<PackageReference Include="NBXplorer.Client" Version="2.0.0.26" />
</ItemGroup>
</Project>

@ -4,7 +4,6 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions.Internal;
using Microsoft.Extensions.Logging.Console;

@ -0,0 +1,259 @@
#if !NETCOREAPP21
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Microsoft.Extensions.Logging.Console.Internal
{
/// <summary>
/// For non-Windows platform consoles which understand the ANSI escape code sequences to represent color
/// </summary>
internal class AnsiLogConsole : IConsole
{
private readonly StringBuilder _outputBuilder;
private readonly IAnsiSystemConsole _systemConsole;
public AnsiLogConsole(IAnsiSystemConsole systemConsole)
{
_outputBuilder = new StringBuilder();
_systemConsole = systemConsole;
}
public void Write(string message, ConsoleColor? background, ConsoleColor? foreground)
{
// Order: backgroundcolor, foregroundcolor, Message, reset foregroundcolor, reset backgroundcolor
if (background.HasValue)
{
_outputBuilder.Append(GetBackgroundColorEscapeCode(background.Value));
}
if (foreground.HasValue)
{
_outputBuilder.Append(GetForegroundColorEscapeCode(foreground.Value));
}
_outputBuilder.Append(message);
if (foreground.HasValue)
{
_outputBuilder.Append("\x1B[39m\x1B[22m"); // reset to default foreground color
}
if (background.HasValue)
{
_outputBuilder.Append("\x1B[49m"); // reset to the background color
}
}
public void WriteLine(string message, ConsoleColor? background, ConsoleColor? foreground)
{
Write(message, background, foreground);
_outputBuilder.AppendLine();
}
public void Flush()
{
_systemConsole.Write(_outputBuilder.ToString());
_outputBuilder.Clear();
}
private static string GetForegroundColorEscapeCode(ConsoleColor color)
{
switch (color)
{
case ConsoleColor.Black:
return "\x1B[30m";
case ConsoleColor.DarkRed:
return "\x1B[31m";
case ConsoleColor.DarkGreen:
return "\x1B[32m";
case ConsoleColor.DarkYellow:
return "\x1B[33m";
case ConsoleColor.DarkBlue:
return "\x1B[34m";
case ConsoleColor.DarkMagenta:
return "\x1B[35m";
case ConsoleColor.DarkCyan:
return "\x1B[36m";
case ConsoleColor.Gray:
return "\x1B[37m";
case ConsoleColor.Red:
return "\x1B[1m\x1B[31m";
case ConsoleColor.Green:
return "\x1B[1m\x1B[32m";
case ConsoleColor.Yellow:
return "\x1B[1m\x1B[33m";
case ConsoleColor.Blue:
return "\x1B[1m\x1B[34m";
case ConsoleColor.Magenta:
return "\x1B[1m\x1B[35m";
case ConsoleColor.Cyan:
return "\x1B[1m\x1B[36m";
case ConsoleColor.White:
return "\x1B[1m\x1B[37m";
default:
return "\x1B[39m\x1B[22m"; // default foreground color
}
}
private static string GetBackgroundColorEscapeCode(ConsoleColor color)
{
switch (color)
{
case ConsoleColor.Black:
return "\x1B[40m";
case ConsoleColor.Red:
return "\x1B[41m";
case ConsoleColor.Green:
return "\x1B[42m";
case ConsoleColor.Yellow:
return "\x1B[43m";
case ConsoleColor.Blue:
return "\x1B[44m";
case ConsoleColor.Magenta:
return "\x1B[45m";
case ConsoleColor.Cyan:
return "\x1B[46m";
case ConsoleColor.White:
return "\x1B[47m";
default:
return "\x1B[49m"; // Use default background color
}
}
}
internal class AnsiSystemConsole : IAnsiSystemConsole
{
private readonly TextWriter _textWriter;
/// <inheritdoc />
public AnsiSystemConsole(bool stdErr = false)
{
_textWriter = stdErr ? System.Console.Error : System.Console.Out;
}
public void Write(string message)
{
_textWriter.Write(message);
}
}
}
namespace Microsoft.Extensions.Logging.Console
{
internal interface IAnsiSystemConsole
{
void Write(string message);
}
public interface IConsole
{
void Write(string message, ConsoleColor? background, ConsoleColor? foreground);
void WriteLine(string message, ConsoleColor? background, ConsoleColor? foreground);
void Flush();
}
internal class WindowsLogConsole : IConsole
{
private readonly TextWriter _textWriter;
/// <inheritdoc />
public WindowsLogConsole(bool stdErr = false)
{
_textWriter = stdErr ? System.Console.Error : System.Console.Out;
}
private bool SetColor(ConsoleColor? background, ConsoleColor? foreground)
{
if (background.HasValue)
{
System.Console.BackgroundColor = background.Value;
}
if (foreground.HasValue)
{
System.Console.ForegroundColor = foreground.Value;
}
return background.HasValue || foreground.HasValue;
}
private void ResetColor()
{
System.Console.ResetColor();
}
public void Write(string message, ConsoleColor? background, ConsoleColor? foreground)
{
var colorChanged = SetColor(background, foreground);
_textWriter.Write(message);
if (colorChanged)
{
ResetColor();
}
}
public void WriteLine(string message, ConsoleColor? background, ConsoleColor? foreground)
{
var colorChanged = SetColor(background, foreground);
_textWriter.WriteLine(message);
if (colorChanged)
{
ResetColor();
}
}
public void Flush()
{
// No action required as for every write, data is sent directly to the console
// output stream
}
}
}
namespace Microsoft.Extensions.Logging.Abstractions.Internal
{
/// <summary>
/// An empty scope without any logic
/// </summary>
internal class NullScope : IDisposable
{
public static NullScope Instance { get; } = new NullScope();
private NullScope()
{
}
/// <inheritdoc />
public void Dispose()
{
}
}
}
#else
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
namespace Microsoft.AspNetCore.Mvc
{
/// <summary>
/// Provides programmatic configuration for JSON formatters using Newtonsoft.JSON.
/// </summary>
public class MvcNewtonsoftJsonOptions
{
IOptions<MvcJsonOptions> jsonOptions;
public MvcNewtonsoftJsonOptions(IOptions<MvcJsonOptions> jsonOptions)
{
this.jsonOptions = jsonOptions;
}
public JsonSerializerSettings SerializerSettings => this.jsonOptions.Value.SerializerSettings;
}
}
#endif

@ -1,11 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../Build/Version.csproj" Condition="Exists('../Build/Version.csproj')" />
<Import Project="../Build/Common.csproj" />
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.9" />
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.AspNetCore.App" AllowExplicitVersion="true" Version="2.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.2" />
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="3.0.0-alpha1.19515.63" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp2.1'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.0.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.0.0-rc1.final" />
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="3.0.0-alpha1.19515.63" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
</ItemGroup>
</Project>

@ -45,7 +45,11 @@ namespace BTCPayServer.Data
class CustomNpgsqlMigrationsSqlGenerator : NpgsqlMigrationsSqlGenerator
{
#if NETCOREAPP21
public CustomNpgsqlMigrationsSqlGenerator(MigrationsSqlGeneratorDependencies dependencies) : base(dependencies)
#else
public CustomNpgsqlMigrationsSqlGenerator(MigrationsSqlGeneratorDependencies dependencies, IMigrationsAnnotationProvider annotations, Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal.INpgsqlOptions opts) : base(dependencies, annotations, opts)
#endif
{
}

@ -73,7 +73,6 @@ namespace BTCPayServer.Data
}
[NotMapped]
[Obsolete]
public string Role
{
get; set;
@ -88,9 +87,6 @@ namespace BTCPayServer.Data
public string DefaultCrypto { get; set; }
public List<PairedSINData> PairedSINs { get; set; }
public IEnumerable<APIKeyData> APIKeys { get; set; }
[NotMapped]
public List<Claim> AdditionalClaims { get; set; } = new List<Claim>();
}
public enum NetworkFeeMode

@ -1,19 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../Build/Version.csproj" Condition="Exists('../Build/Version.csproj')" />
<Import Project="../Build/Common.csproj" />
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup>
<Folder Include="Providers\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.9" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.9" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
<FrameworkReference Include="Microsoft.AspNetCore.App" Condition="'$(TargetFramework)' != 'netcoreapp2.1'" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" Condition="'$(TargetFramework)' != 'netcoreapp2.1'" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" Condition="'$(TargetFramework)' != 'netcoreapp2.1'" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="DigitalRuby.ExchangeSharp" Version="0.5.3" />
<PackageReference Include="DigitalRuby.ExchangeSharp" Version="0.6.3" />
</ItemGroup>
<ItemGroup>

@ -36,27 +36,27 @@ namespace BTCPayServer.Services.Rates
{
await new SynchronizationContextRemover();
var rates = await _ExchangeAPI.GetTickersAsync();
lock (notFoundSymbols)
{
var exchangeRates =
rates
var exchangeRateTasks = rates
.Where(t => t.Value.Ask != 0m && t.Value.Bid != 0m)
.Select(t => CreateExchangeRate(t))
.Where(t => t != null)
.ToArray();
return new ExchangeRates(exchangeRates);
}
.Select(t => CreateExchangeRate(t));
var exchangeRates = await Task.WhenAll(exchangeRateTasks);
return new ExchangeRates(exchangeRates
.Where(t => t != null)
.ToArray());
}
// ExchangeSymbolToGlobalSymbol throws exception which would kill perf
ConcurrentDictionary<string, string> notFoundSymbols = new ConcurrentDictionary<string, string>();
private ExchangeRate CreateExchangeRate(KeyValuePair<string, ExchangeTicker> ticker)
private async Task<ExchangeRate> CreateExchangeRate(KeyValuePair<string, ExchangeTicker> ticker)
{
if (notFoundSymbols.ContainsKey(ticker.Key))
if (notFoundSymbols.TryGetValue(ticker.Key, out _))
return null;
try
{
var tickerName = _ExchangeAPI.ExchangeSymbolToGlobalSymbol(ticker.Key);
var tickerName = await _ExchangeAPI.ExchangeMarketSymbolToGlobalMarketSymbolAsync(ticker.Key);
if (!CurrencyPair.TryParse(tickerName, out var pair))
{
notFoundSymbols.TryAdd(ticker.Key, ticker.Key);

@ -90,10 +90,10 @@ namespace BTCPayServer.Services.Rates
public async Task<ExchangeRates> GetRatesAsync(CancellationToken cancellationToken)
{
var result = new ExchangeRates();
var symbols = await GetSymbolsAsync();
var normalizedPairsList = symbols.Where(s => !notFoundSymbols.ContainsKey(s)).Select(s => _Helper.NormalizeSymbol(s)).ToList();
var symbols = await GetSymbolsAsync(cancellationToken);
var normalizedPairsList = symbols.Where(s => !notFoundSymbols.ContainsKey(s)).Select(s => _Helper.NormalizeMarketSymbol(s)).ToList();
var csvPairsList = string.Join(",", normalizedPairsList);
JToken apiTickers = await MakeJsonRequestAsync<JToken>("/0/public/Ticker", null, new Dictionary<string, object> { { "pair", csvPairsList } });
JToken apiTickers = await MakeJsonRequestAsync<JToken>("/0/public/Ticker", null, new Dictionary<string, object> { { "pair", csvPairsList } }, cancellationToken: cancellationToken);
var tickers = new List<KeyValuePair<string, ExchangeTicker>>();
foreach (string symbol in symbols)
{
@ -114,7 +114,7 @@ namespace BTCPayServer.Services.Rates
}
else
{
global = _Helper.ExchangeSymbolToGlobalSymbol(symbol);
global = await _Helper.ExchangeMarketSymbolToGlobalMarketSymbolAsync(symbol);
}
if (CurrencyPair.TryParse(global, out var pair))
result.Add(new ExchangeRate("kraken", pair.Inverse(), new BidAsk(ticker.Bid, ticker.Ask)));
@ -142,16 +142,16 @@ namespace BTCPayServer.Services.Rates
Last = last,
Volume = new ExchangeVolume
{
BaseVolume = ticker["v"][1].ConvertInvariant<decimal>(),
BaseSymbol = symbol,
ConvertedVolume = ticker["v"][1].ConvertInvariant<decimal>() * last,
ConvertedSymbol = symbol,
BaseCurrencyVolume = ticker["v"][1].ConvertInvariant<decimal>(),
BaseCurrency = symbol,
QuoteCurrencyVolume = ticker["v"][1].ConvertInvariant<decimal>() * last,
QuoteCurrency = symbol,
Timestamp = DateTime.UtcNow
}
};
}
private async Task<string[]> GetSymbolsAsync()
private async Task<string[]> GetSymbolsAsync(CancellationToken cancellationToken)
{
if (_LastSymbolUpdate != null && DateTimeOffset.UtcNow - _LastSymbolUpdate.Value < TimeSpan.FromDays(0.5))
{
@ -159,7 +159,7 @@ namespace BTCPayServer.Services.Rates
}
else
{
JToken json = await MakeJsonRequestAsync<JToken>("/0/public/AssetPairs");
JToken json = await MakeJsonRequestAsync<JToken>("/0/public/AssetPairs", cancellationToken: cancellationToken);
var symbols = (from prop in json.Children<JProperty>() where !prop.Name.Contains(".d", StringComparison.OrdinalIgnoreCase) select prop.Name).ToArray();
_Symbols = symbols;
_LastSymbolUpdate = DateTimeOffset.UtcNow;

@ -1,36 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Rating;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Services.Rates
{
public class NdaxRateProvider : IRateProvider, IHasExchangeName
{
private readonly HttpClient _httpClient;
public NdaxRateProvider(HttpClient httpClient)
{
_httpClient = httpClient ?? new HttpClient();
}
public string ExchangeName => "ndax";
public async Task<ExchangeRates> GetRatesAsync(CancellationToken cancellationToken)
{
var response = await _httpClient.GetAsync("https://ndax.io/api/returnTicker", cancellationToken);
var jobj = await response.Content.ReadAsAsync<Dictionary<string, JObject>>(cancellationToken);
return new ExchangeRates(jobj.Select(pair => new ExchangeRate(ExchangeName, CurrencyPair.Parse(pair.Key),
new BidAsk(GetValue(pair.Value["highestBid"]), GetValue(pair.Value["lowestAsk"])))));
}
private static decimal GetValue(JToken jobj)
{
return string.IsNullOrEmpty(jobj.ToString()) ? 0 : jobj.Value<decimal>();
}
}
}

@ -9,6 +9,7 @@ using ExchangeSharp;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using MemoryCache = Microsoft.Extensions.Caching.Memory.MemoryCache;
namespace BTCPayServer.Services.Rates
{
@ -103,7 +104,8 @@ namespace BTCPayServer.Services.Rates
Providers.Add("binance", new ExchangeSharpRateProvider("binance", new ExchangeBinanceAPI(), true));
Providers.Add("bittrex", new ExchangeSharpRateProvider("bittrex", new ExchangeBittrexAPI(), true));
Providers.Add("poloniex", new ExchangeSharpRateProvider("poloniex", new ExchangePoloniexAPI(), true));
Providers.Add("hitbtc", new ExchangeSharpRateProvider("hitbtc", new ExchangeHitbtcAPI(), false));
Providers.Add("hitbtc", new ExchangeSharpRateProvider("hitbtc", new ExchangeHitBTCAPI(), true));
Providers.Add("ndax", new ExchangeSharpRateProvider("ndax", new ExchangeNDAXAPI(), true));
// Cryptopia is often not available
// Disabled because of https://twitter.com/Cryptopia_NZ/status/1085084168852291586
@ -113,7 +115,6 @@ namespace BTCPayServer.Services.Rates
Providers.Add(CoinAverageRateProvider.CoinAverageName, new CoinAverageRateProvider() { Exchange = CoinAverageRateProvider.CoinAverageName, HttpClient = _httpClientFactory?.CreateClient("EXCHANGE_COINAVERAGE"), Authenticator = _CoinAverageSettings });
Providers.Add("kraken", new KrakenExchangeRateProvider() { HttpClient = _httpClientFactory?.CreateClient("EXCHANGE_KRAKEN") });
Providers.Add("bylls", new ByllsRateProvider(_httpClientFactory?.CreateClient("EXCHANGE_BYLLS")));
Providers.Add("ndax", new NdaxRateProvider(_httpClientFactory?.CreateClient("EXCHANGE_NDAX")));
Providers.Add("bitbank", new BitbankRateProvider(_httpClientFactory?.CreateClient("EXCHANGE_BITBANK")));
Providers.Add("bitpay", new BitpayRateProvider(_httpClientFactory?.CreateClient("EXCHANGE_BITPAY")));

@ -4,8 +4,9 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using AspNet.Security.OpenIdConnect.Primitives;
using System.Security.Claims;
using BTCPayServer.Tests.Logging;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Xunit;
using Xunit.Abstractions;
@ -16,24 +17,26 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenIddict.Abstractions;
using OpenQA.Selenium;
using Microsoft.AspNetCore.Identity;
namespace BTCPayServer.Tests
{
public class AuthenticationTests
{
public const int TestTimeout = TestUtils.TestTimeout;
public AuthenticationTests(ITestOutputHelper helper)
{
Logs.Tester = new XUnitLog(helper) {Name = "Tests"};
Logs.LogProvider = new XUnitLogProvider(helper);
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async Task GetRedirectedToLoginPathOnChallenge()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var client = tester.PayTester.HttpClient;
//Wallets endpoint is protected
var response = await client.GetAsync("wallets");
@ -49,13 +52,13 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async Task CanGetOpenIdConfiguration()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
using (var response =
await tester.PayTester.HttpClient.GetAsync("/.well-known/openid-configuration"))
{
@ -70,16 +73,17 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async Task CanUseNonInteractiveFlows()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
await user.MakeAdmin();
var token = await RegisterPasswordClientAndGetAccessToken(user, null, tester);
await TestApiAgainstAccessToken(token, tester, user);
token = await RegisterPasswordClientAndGetAccessToken(user, "secret", tester);
@ -89,17 +93,18 @@ namespace BTCPayServer.Tests
}
}
[Fact(Timeout = TestTimeout)]
[Trait("Selenium", "Selenium")]
[Fact]
public async Task CanUseImplicitFlow()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
var tester = s.Server;
var user = tester.NewAccount();
user.GrantAccess();
await user.MakeAdmin();
var id = Guid.NewGuid().ToString();
var redirecturi = new Uri("http://127.0.0.1/oidc-callback");
var openIdClient = await user.RegisterOpenIdClient(
@ -108,10 +113,11 @@ namespace BTCPayServer.Tests
ClientId = id,
DisplayName = id,
Permissions = {OpenIddictConstants.Permissions.GrantTypes.Implicit},
RedirectUris = {redirecturi}
RedirectUris = {redirecturi},
});
var implicitAuthorizeUrl = new Uri(tester.PayTester.ServerUri,
$"connect/authorize?response_type=token&client_id={id}&redirect_uri={redirecturi.AbsoluteUri}&scope=openid&nonce={Guid.NewGuid().ToString()}");
$"connect/authorize?response_type=token&client_id={id}&redirect_uri={redirecturi.AbsoluteUri}&scope=openid server_management store_management&nonce={Guid.NewGuid().ToString()}");
s.Driver.Navigate().GoToUrl(implicitAuthorizeUrl);
s.Login(user.RegisterDetails.Email, user.RegisterDetails.Password);
s.Driver.FindElement(By.Id("consent-yes")).Click();
@ -126,15 +132,52 @@ namespace BTCPayServer.Tests
results = url.Split("#").Last().Split("&").ToDictionary(s1 => s1.Split("=")[0], s1 => s1.Split("=")[1]);
await TestApiAgainstAccessToken(results["access_token"], tester, user);
var stores = await TestApiAgainstAccessToken<StoreData[]>(results["access_token"],
$"api/test/me/stores",
tester.PayTester.HttpClient);
Assert.NotEmpty(stores);
Assert.True(await TestApiAgainstAccessToken<bool>(results["access_token"],
$"api/test/me/stores/{stores[0].Id}/can-edit",
tester.PayTester.HttpClient));
//we dont ask for consent after acquiring it the first time for the same scopes.
LogoutFlow(tester, id, s);
s.Driver.Navigate().GoToUrl(implicitAuthorizeUrl);
s.Login(user.RegisterDetails.Email, user.RegisterDetails.Password);
Assert.Throws<NoSuchElementException>(() => s.Driver.FindElement(By.Id("consent-yes")));
results = url.Split("#").Last().Split("&")
s.Driver.AssertElementNotFound(By.Id("consent-yes"));
// Let's asks without scopes
LogoutFlow(tester, id, s);
id = Guid.NewGuid().ToString();
openIdClient = await user.RegisterOpenIdClient(
new OpenIddictApplicationDescriptor()
{
ClientId = id,
DisplayName = id,
Permissions = { OpenIddictConstants.Permissions.GrantTypes.Implicit },
RedirectUris = { redirecturi },
});
implicitAuthorizeUrl = new Uri(tester.PayTester.ServerUri,
$"connect/authorize?response_type=token&client_id={id}&redirect_uri={redirecturi.AbsoluteUri}&scope=openid&nonce={Guid.NewGuid().ToString()}");
s.Driver.Navigate().GoToUrl(implicitAuthorizeUrl);
s.Login(user.RegisterDetails.Email, user.RegisterDetails.Password);
s.Driver.FindElement(By.Id("consent-yes")).Click();
results = s.Driver.Url.Split("#").Last().Split("&")
.ToDictionary(s1 => s1.Split("=")[0], s1 => s1.Split("=")[1]);
await TestApiAgainstAccessToken(results["access_token"], tester, user);
await Assert.ThrowsAnyAsync<HttpRequestException>(async () =>
{
await TestApiAgainstAccessToken<StoreData[]>(results["access_token"],
$"api/test/me/stores",
tester.PayTester.HttpClient);
});
await Assert.ThrowsAnyAsync<HttpRequestException>(async () =>
{
await TestApiAgainstAccessToken<bool>(results["access_token"],
$"api/test/me/stores/{stores[0].Id}/can-edit",
tester.PayTester.HttpClient);
});
}
}
@ -148,17 +191,18 @@ namespace BTCPayServer.Tests
}
[Fact(Timeout = TestTimeout)]
[Trait("Selenium", "Selenium")]
[Fact]
public async Task CanUseCodeFlow()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
var tester = s.Server;
var user = tester.NewAccount();
user.GrantAccess();
await user.MakeAdmin();
var id = Guid.NewGuid().ToString();
var redirecturi = new Uri("http://127.0.0.1/oidc-callback");
var secret = "secret";
@ -175,7 +219,7 @@ namespace BTCPayServer.Tests
RedirectUris = {redirecturi}
}, secret);
var authorizeUrl = new Uri(tester.PayTester.ServerUri,
$"connect/authorize?response_type=code&client_id={id}&redirect_uri={redirecturi.AbsoluteUri}&scope=openid offline_access&state={Guid.NewGuid().ToString()}");
$"connect/authorize?response_type=code&client_id={id}&redirect_uri={redirecturi.AbsoluteUri}&scope=openid offline_access server_management store_management&state={Guid.NewGuid().ToString()}");
s.Driver.Navigate().GoToUrl(authorizeUrl);
s.Login(user.RegisterDetails.Email, user.RegisterDetails.Password);
s.Driver.FindElement(By.Id("consent-yes")).Click();
@ -205,7 +249,7 @@ namespace BTCPayServer.Tests
Assert.True(response.IsSuccessStatusCode);
string content = await response.Content.ReadAsStringAsync();
var result = JObject.Parse(content).ToObject<OpenIdConnectResponse>();
var result = JObject.Parse(content).ToObject<OpenIddictResponse>();
await TestApiAgainstAccessToken(result.AccessToken, tester, user);
@ -245,7 +289,7 @@ namespace BTCPayServer.Tests
Assert.True(response.IsSuccessStatusCode);
string content = await response.Content.ReadAsStringAsync();
var result = JObject.Parse(content).ToObject<OpenIdConnectResponse>();
var result = JObject.Parse(content).ToObject<OpenIddictResponse>();
Assert.NotEmpty(result.AccessToken);
Assert.Null(result.Error);
return result.AccessToken;
@ -275,7 +319,8 @@ namespace BTCPayServer.Tests
new KeyValuePair<string, string>("grant_type",
OpenIddictConstants.GrantTypes.ClientCredentials),
new KeyValuePair<string, string>("client_id", openIdClient.ClientId),
new KeyValuePair<string, string>("client_secret", secret)
new KeyValuePair<string, string>("client_secret", secret),
new KeyValuePair<string, string>("scope", "server_management store_management")
})
};
@ -285,7 +330,7 @@ namespace BTCPayServer.Tests
Assert.True(response.IsSuccessStatusCode);
string content = await response.Content.ReadAsStringAsync();
var result = JObject.Parse(content).ToObject<OpenIdConnectResponse>();
var result = JObject.Parse(content).ToObject<OpenIddictResponse>();
Assert.NotEmpty(result.AccessToken);
Assert.Null(result.Error);
return result.AccessToken;
@ -315,7 +360,8 @@ namespace BTCPayServer.Tests
new KeyValuePair<string, string>("username", user.RegisterDetails.Email),
new KeyValuePair<string, string>("password", user.RegisterDetails.Password),
new KeyValuePair<string, string>("client_id", openIdClient.ClientId),
new KeyValuePair<string, string>("client_secret", secret)
new KeyValuePair<string, string>("client_secret", secret),
new KeyValuePair<string, string>("scope", "server_management store_management")
})
};
@ -325,7 +371,7 @@ namespace BTCPayServer.Tests
Assert.True(response.IsSuccessStatusCode);
string content = await response.Content.ReadAsStringAsync();
var result = JObject.Parse(content).ToObject<OpenIdConnectResponse>();
var result = JObject.Parse(content).ToObject<OpenIddictResponse>();
Assert.NotEmpty(result.AccessToken);
Assert.Null(result.Error);
return result.AccessToken;
@ -353,8 +399,7 @@ namespace BTCPayServer.Tests
$"api/test/me/stores/{testAccount.StoreId}/can-edit",
tester.PayTester.HttpClient));
Assert.Equal(testAccount.RegisterDetails.IsAdmin, await TestApiAgainstAccessToken<bool>(accessToken,
Assert.True(await TestApiAgainstAccessToken<bool>(accessToken,
$"api/test/me/is-admin",
tester.PayTester.HttpClient));

@ -2,17 +2,25 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">$(TargetFrameworkOverride)</TargetFramework>
<IsPackable>false</IsPackable>
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
<LangVersion>7.2</LangVersion>
<UserSecretsId>AB0AC1DD-9D26-485B-9416-56A33F268117</UserSecretsId>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<DefineConstants>$(DefineConstants);NETCOREAPP21</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(CI_TESTS)' == 'true'">
<DefineConstants>$(DefineConstants);SHORT_TIMEOUT</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="76.0.3809.6801" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="78.0.3904.7000" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>

@ -1,4 +1,4 @@
using BTCPayServer.Configuration;
using BTCPayServer.Configuration;
using System.Linq;
using BTCPayServer.HostedServices;
using BTCPayServer.Hosting;
@ -13,7 +13,6 @@ using BTCPayServer.Tests.Logging;
using BTCPayServer.Tests.Mocks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Routing;
@ -33,12 +32,13 @@ using System.Security.Claims;
using System.Security.Principal;
using System.Text;
using System.Threading;
using AspNet.Security.OpenIdConnect.Primitives;
using OpenIddict.Abstractions;
using Xunit;
using BTCPayServer.Services;
using System.Net.Http;
using Microsoft.AspNetCore.Hosting.Server.Features;
using System.Threading.Tasks;
using AuthenticationSchemes = BTCPayServer.Security.AuthenticationSchemes;
namespace BTCPayServer.Tests
{
@ -93,7 +93,7 @@ namespace BTCPayServer.Tests
public bool MockRates { get; set; } = true;
public void Start()
public async Task StartAsync()
{
if (!Directory.Exists(_Directory))
Directory.CreateDirectory(_Directory);
@ -102,7 +102,6 @@ namespace BTCPayServer.Tests
if (!Directory.Exists(chainDirectory))
Directory.CreateDirectory(chainDirectory);
StringBuilder config = new StringBuilder();
config.AppendLine($"{chain.ToLowerInvariant()}=1");
if (InContainer)
@ -118,6 +117,12 @@ namespace BTCPayServer.Tests
config.AppendLine($"ltc.explorer.url={LTCNBXplorerUri.AbsoluteUri}");
config.AppendLine($"ltc.explorer.cookiefile=0");
config.AppendLine($"btc.lightning={IntegratedLightning.AbsoluteUri}");
config.AppendLine($"torrcfile={TestUtils.GetTestDataFullPath("Tor/torrc")}");
config.AppendLine($"debuglog=debug.log");
var localLndBackupFile = Path.Combine(_Directory, "walletunlock.json");
File.Copy(TestUtils.GetTestDataFullPath("LndSeedBackup/walletunlock.json"), localLndBackupFile, true);
config.AppendLine($"btc.external.lndseedbackup={localLndBackupFile}");
if (!string.IsNullOrEmpty(SSHPassword) && string.IsNullOrEmpty(SSHKeyFile))
config.AppendLine($"sshpassword={SSHPassword}");
if (!string.IsNullOrEmpty(SSHKeyFile))
@ -130,7 +135,7 @@ namespace BTCPayServer.Tests
else if (!String.IsNullOrEmpty(Postgres))
config.AppendLine($"postgres=" + Postgres);
var confPath = Path.Combine(chainDirectory, "settings.config");
File.WriteAllText(confPath, config.ToString());
await File.WriteAllTextAsync(confPath, config.ToString());
ServerUri = new Uri("http://" + HostName + ":" + Port + "/");
HttpClient = new HttpClient();
@ -140,6 +145,7 @@ namespace BTCPayServer.Tests
_Host = new WebHostBuilder()
.UseConfiguration(conf)
.UseContentRoot(FindBTCPayServerDirectory())
.UseWebRoot(Path.Combine(FindBTCPayServerDirectory(), "wwwroot"))
.ConfigureServices(s =>
{
s.AddLogging(l =>
@ -154,7 +160,7 @@ namespace BTCPayServer.Tests
.UseKestrel()
.UseStartup<Startup>()
.Build();
_Host.StartWithTasksAsync().GetAwaiter().GetResult();
await _Host.StartWithTasksAsync();
var urls = _Host.ServerFeatures.Get<IServerAddressesFeature>().Addresses;
foreach (var url in urls)
@ -227,14 +233,15 @@ namespace BTCPayServer.Tests
rateProvider.Providers.Add("bittrex", bittrex);
}
WaitSiteIsOperational().GetAwaiter().GetResult();
Logs.Tester.LogInformation("Waiting site is operational...");
await WaitSiteIsOperational();
Logs.Tester.LogInformation("Site is now operational");
}
private async Task WaitSiteIsOperational()
{
using (var cts = new CancellationTokenSource(10_000))
using (var cts = new CancellationTokenSource(20_000))
{
var synching = WaitIsFullySynched(cts.Token);
var accessingHomepage = WaitCanAccessHomepage(cts.Token);
@ -264,7 +271,7 @@ namespace BTCPayServer.Tests
private string FindBTCPayServerDirectory()
{
var solutionDirectory = LanguageService.TryGetSolutionDirectoryInfo(Directory.GetCurrentDirectory());
var solutionDirectory = TestUtils.TryGetSolutionDirectoryInfo(Directory.GetCurrentDirectory());
return Path.Combine(solutionDirectory.FullName, "BTCPayServer");
}
@ -291,7 +298,7 @@ namespace BTCPayServer.Tests
public string SSHPassword { get; internal set; }
public string SSHKeyFile { get; internal set; }
public string SSHConnection { get; set; }
public T GetController<T>(string userId = null, string storeId = null, Claim[] additionalClaims = null) where T : Controller
public T GetController<T>(string userId = null, string storeId = null, bool isAdmin = false) where T : Controller
{
var context = new DefaultHttpContext();
context.Request.Host = new HostString("127.0.0.1", Port);
@ -300,10 +307,10 @@ namespace BTCPayServer.Tests
if (userId != null)
{
List<Claim> claims = new List<Claim>();
claims.Add(new Claim(OpenIdConnectConstants.Claims.Subject, userId));
if (additionalClaims != null)
claims.AddRange(additionalClaims);
context.User = new ClaimsPrincipal(new ClaimsIdentity(claims.ToArray(), Policies.CookieAuthentication));
claims.Add(new Claim(OpenIddictConstants.Claims.Subject, userId));
if (isAdmin)
claims.Add(new Claim(ClaimTypes.Role, Roles.ServerAdmin));
context.User = new ClaimsPrincipal(new ClaimsIdentity(claims.ToArray(), AuthenticationSchemes.Cookie));
}
if (storeId != null)
{

@ -21,25 +21,26 @@ namespace BTCPayServer.Tests
{
public class ChangellyTests
{
public const int TestTimeout = 60_000;
public ChangellyTests(ITestOutputHelper helper)
{
Logs.Tester = new XUnitLog(helper) {Name = "Tests"};
Logs.LogProvider = new XUnitLogProvider(helper);
}
[Fact(Timeout = 60000)]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async void CanSetChangellyPaymentMethod()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
var controller = tester.PayTester.GetController<StoresController>(user.UserId, user.StoreId);
var storeBlob = controller.StoreData.GetStoreBlob();
var storeBlob = controller.CurrentStore.GetStoreBlob();
Assert.Null(storeBlob.ChangellySettings);
var updateModel = new UpdateChangellySettingsViewModel()
@ -54,7 +55,7 @@ namespace BTCPayServer.Tests
await controller.UpdateChangellySettings(user.StoreId, updateModel, "save")).ActionName);
var store = await tester.PayTester.StoreRepository.FindStore(user.StoreId);
storeBlob = controller.StoreData.GetStoreBlob();
storeBlob = controller.CurrentStore.GetStoreBlob();
Assert.NotNull(storeBlob.ChangellySettings);
Assert.NotNull(storeBlob.ChangellySettings);
Assert.IsType<ChangellySettings>(storeBlob.ChangellySettings);
@ -68,13 +69,13 @@ namespace BTCPayServer.Tests
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async void CanToggleChangellyPaymentMethod()
public async Task CanToggleChangellyPaymentMethod()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
var controller = tester.PayTester.GetController<StoresController>(user.UserId, user.StoreId);
@ -106,13 +107,13 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async void CannotUseChangellyApiWithoutChangellyPaymentMethodSet()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
var changellyController =
@ -161,13 +162,13 @@ namespace BTCPayServer.Tests
};
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async void CanGetCurrencyListFromChangelly()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
@ -194,13 +195,13 @@ namespace BTCPayServer.Tests
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async void CanCalculateToAmountForChangelly()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
@ -224,7 +225,7 @@ namespace BTCPayServer.Tests
}
[Fact]
[Trait("Integration", "Integration")]
[Trait("Fast", "Fast")]
public void CanComputeBaseAmount()
{
Assert.Equal(1, ChangellyCalculationHelper.ComputeBaseAmount(1, 1));
@ -234,7 +235,7 @@ namespace BTCPayServer.Tests
}
[Fact]
[Trait("Integration", "Integration")]
[Trait("Fast", "Fast")]
public void CanComputeCorrectAmount()
{
Assert.Equal(1, ChangellyCalculationHelper.ComputeCorrectAmount(0.5m, 1, 2));

@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Lightning;
using BTCPayServer.Tests.Logging;
@ -17,79 +18,70 @@ namespace BTCPayServer.Tests
[Trait("Selenium", "Selenium")]
public class CheckoutUITests
{
public const int TestTimeout = TestUtils.TestTimeout;
public CheckoutUITests(ITestOutputHelper helper)
{
Logs.Tester = new XUnitLog(helper) {Name = "Tests"};
Logs.Tester = new XUnitLog(helper) { Name = "Tests" };
Logs.LogProvider = new XUnitLogProvider(helper);
}
[Fact]
public void CanCreateInvoice()
{
using (var s = SeleniumTester.Create())
{
s.Start();
s.RegisterNewUser();
var store = s.CreateNewStore().storeName;
s.AddDerivationScheme();
s.CreateInvoice(store);
s.Driver.FindElement(By.ClassName("invoice-details-link")).Click();
s.Driver.AssertNoError();
s.Driver.Navigate().Back();
s.Driver.FindElement(By.ClassName("invoice-checkout-link")).Click();
Assert.NotEmpty(s.Driver.FindElements(By.Id("checkoutCtrl")));
s.Driver.Quit();
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
public async Task CanHandleRefundEmailForm()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
s.GoToRegister();
s.RegisterNewUser();
var store = s.CreateNewStore();
s.AddDerivationScheme("BTC");
s.GoToStore(store.storeId, StoreNavPages.Checkout);
s.Driver.FindElement(By.Id("RequiresRefundEmail")).Click();
s.Driver.FindElement(By.Name("command")).ForceClick();
var emailAlreadyThereInvoiceId =s.CreateInvoice(store.storeName, 100, "USD", "a@g.com");
var emailAlreadyThereInvoiceId = s.CreateInvoice(store.storeName, 100, "USD", "a@g.com");
s.GoToInvoiceCheckout(emailAlreadyThereInvoiceId);
s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
s.GoToHome();
var invoiceId = s.CreateInvoice(store.storeName);
s.GoToInvoiceCheckout(invoiceId);
s.Driver.FindElement(By.ClassName("invoice-details-link")).Click();
s.Driver.AssertNoError();
s.Driver.Navigate().Back();
s.Driver.FindElement(By.ClassName("invoice-checkout-link")).Click();
Assert.NotEmpty(s.Driver.FindElements(By.Id("checkoutCtrl")));
Assert.True(s.Driver.FindElement(By.Id("emailAddressFormInput")).Displayed);
s.Driver.FindElement(By.Id("emailAddressFormInput")).SendKeys("xxx");
s.Driver.FindElement(By.Id("emailAddressForm")).FindElement(By.CssSelector("button.action-button"))
.Click();
var formInput = s.Driver.FindElement(By.Id("emailAddressFormInput"));
Assert.True(formInput.Displayed);
Assert.Contains("form-input-invalid", formInput.GetAttribute("class"));
formInput = s.Driver.FindElement(By.Id("emailAddressFormInput"));
formInput.SendKeys("@g.com");
s.Driver.FindElement(By.Id("emailAddressForm")).FindElement(By.CssSelector("button.action-button"))
.Click();
await Task.Delay(1000);
s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
s.Driver.Navigate().Refresh();
var actionButton = s.Driver.FindElement(By.Id("emailAddressForm")).FindElement(By.CssSelector("button.action-button"));
actionButton.Click();
try // Sometimes the click only take the focus, without actually really clicking on it...
{
actionButton.Click();
}
catch { }
s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
s.Driver.Navigate().Refresh();
s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput"));
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
public async Task CanUseLanguageDropdown()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
s.GoToRegister();
s.RegisterNewUser();
var store = s.CreateNewStore();
s.AddDerivationScheme("BTC");
@ -113,12 +105,13 @@ namespace BTCPayServer.Tests
}
}
[Fact]
public void CanUsePaymentMethodDropdown()
[Fact(Timeout = TestTimeout)]
public async Task CanUsePaymentMethodDropdown()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
s.GoToRegister();
s.RegisterNewUser();
var store = s.CreateNewStore();
s.AddDerivationScheme("BTC");
@ -138,30 +131,31 @@ namespace BTCPayServer.Tests
Assert.Contains("BTC", currencyDropdownButton.Text);
currencyDropdownButton.Click();
var elements = s.Driver.FindElement(By.ClassName("vex-content"))
.FindElements(By.ClassName("vexmenuitem"));
var elements = s.Driver.FindElement(By.ClassName("vex-content")).FindElements(By.ClassName("vexmenuitem"));
Assert.Equal(3, elements.Count);
elements.Single(element => element.Text.Contains("LTC")).Click();
Thread.Sleep(1000);
currencyDropdownButton = s.Driver.FindElement(By.ClassName("payment__currencies"));
Assert.Contains("LTC", currencyDropdownButton.Text);
elements = s.Driver.FindElement(By.ClassName("vex-content"))
.FindElements(By.ClassName("vexmenuitem"));
currencyDropdownButton.Click();
elements = s.Driver.FindElement(By.ClassName("vex-content")).FindElements(By.ClassName("vexmenuitem"));
elements.Single(element => element.Text.Contains("Lightning")).Click();
currencyDropdownButton = s.Driver.FindElement(By.ClassName("payment__currencies"));
Assert.Contains("Lightning", currencyDropdownButton.Text);
s.Driver.Quit();
}
}
[Fact]
public void CanUseLightningSatsFeature()
[Fact(Timeout = TestTimeout)]
public async Task CanUseLightningSatsFeature()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
s.GoToRegister();
s.RegisterNewUser();
var store = s.CreateNewStore();
s.AddInternalLightningNode("BTC");

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
using Xunit;
using Xunit.Abstractions;
using BTCPayServer.Data;
using System.Threading.Tasks;
namespace BTCPayServer.Tests
{
@ -19,17 +20,17 @@ namespace BTCPayServer.Tests
[Fact]
[Trait("Integration", "Integration")]
public async void CanSetCoinSwitchPaymentMethod()
public async Task CanSetCoinSwitchPaymentMethod()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
var controller = tester.PayTester.GetController<StoresController>(user.UserId, user.StoreId);
var storeBlob = controller.StoreData.GetStoreBlob();
var storeBlob = controller.CurrentStore.GetStoreBlob();
Assert.Null(storeBlob.CoinSwitchSettings);
var updateModel = new UpdateCoinSwitchSettingsViewModel()
@ -41,7 +42,7 @@ namespace BTCPayServer.Tests
await controller.UpdateCoinSwitchSettings(user.StoreId, updateModel, "save")).ActionName);
var store = await tester.PayTester.StoreRepository.FindStore(user.StoreId);
storeBlob = controller.StoreData.GetStoreBlob();
storeBlob = controller.CurrentStore.GetStoreBlob();
Assert.NotNull(storeBlob.CoinSwitchSettings);
Assert.NotNull(storeBlob.CoinSwitchSettings);
Assert.IsType<CoinSwitchSettings>(storeBlob.CoinSwitchSettings);
@ -53,11 +54,11 @@ namespace BTCPayServer.Tests
[Fact]
[Trait("Integration", "Integration")]
public async void CanToggleCoinSwitchPaymentMethod()
public async Task CanToggleCoinSwitchPaymentMethod()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
var controller = tester.PayTester.GetController<StoresController>(user.UserId, user.StoreId);

@ -35,13 +35,13 @@ namespace BTCPayServer.Tests
Logs.LogProvider = new XUnitLogProvider(helper);
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanCreateAndDeleteCrowdfundApp()
public async Task CanCreateAndDeleteCrowdfundApp()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
var user2 = tester.NewAccount();
@ -75,13 +75,13 @@ namespace BTCPayServer.Tests
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async Task CanContributeOnlyWhenAllowed()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -100,7 +100,7 @@ namespace BTCPayServer.Tests
crowdfundViewModel.Enabled = false;
crowdfundViewModel.EndDate = null;
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel).Result);
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel, "save").Result);
var anonAppPubsController = tester.PayTester.GetController<AppsPublicController>();
var publicApps = user.GetController<AppsPublicController>();
@ -126,7 +126,7 @@ namespace BTCPayServer.Tests
crowdfundViewModel.StartDate= DateTime.Today.AddDays(2);
crowdfundViewModel.Enabled = true;
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel).Result);
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel, "save").Result);
Assert.IsType<NotFoundObjectResult>(await anonAppPubsController.ContributeToCrowdfund(appId, new ContributeToCrowdfund()
{
Amount = new decimal(0.01)
@ -138,7 +138,7 @@ namespace BTCPayServer.Tests
crowdfundViewModel.EndDate= DateTime.Today.AddDays(-1);
crowdfundViewModel.Enabled = true;
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel).Result);
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel, "save").Result);
Assert.IsType<NotFoundObjectResult>(await anonAppPubsController.ContributeToCrowdfund(appId, new ContributeToCrowdfund()
{
Amount = new decimal(0.01)
@ -152,7 +152,7 @@ namespace BTCPayServer.Tests
crowdfundViewModel.TargetAmount = 1;
crowdfundViewModel.TargetCurrency = "BTC";
crowdfundViewModel.EnforceTargetAmount = true;
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel).Result);
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel, "save").Result);
Assert.IsType<NotFoundObjectResult>(await anonAppPubsController.ContributeToCrowdfund(appId, new ContributeToCrowdfund()
{
Amount = new decimal(1.01)
@ -167,13 +167,13 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanComputeCrowdfundModel()
public async Task CanComputeCrowdfundModel()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -195,7 +195,7 @@ namespace BTCPayServer.Tests
crowdfundViewModel.TargetCurrency = "BTC";
crowdfundViewModel.UseAllStoreInvoices = true;
crowdfundViewModel.EnforceTargetAmount = true;
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel).Result);
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel, "save").Result);
var anonAppPubsController = tester.PayTester.GetController<AppsPublicController>();
var publicApps = user.GetController<AppsPublicController>();
@ -253,7 +253,7 @@ namespace BTCPayServer.Tests
Assert.Contains(AppService.GetAppInternalTag(appId), invoiceEntity.InternalTags);
crowdfundViewModel.UseAllStoreInvoices = false;
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel).Result);
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel, "save").Result);
Logs.Tester.LogInformation("Because UseAllStoreInvoices is false, let's make sure the invoice is not tagged");
invoice = user.BitPay.CreateInvoice(new Invoice()
@ -272,7 +272,7 @@ namespace BTCPayServer.Tests
Logs.Tester.LogInformation("After turning setting a softcap, let's check that only actual payments are counted");
crowdfundViewModel.EnforceTargetAmount = false;
crowdfundViewModel.UseAllStoreInvoices = true;
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel).Result);
Assert.IsType<RedirectToActionResult>(apps.UpdateCrowdfund(appId, crowdfundViewModel, "save").Result);
invoice = user.BitPay.CreateInvoice(new Invoice()
{
Buyer = new Buyer() { email = "test@fwf.com" },

@ -26,11 +26,10 @@ namespace BTCPayServer.Tests
_Host = new WebHostBuilder()
.Configure(app =>
{
app.Run(req =>
app.Run(async req =>
{
_Requests.Writer.WriteAsync(JsonConvert.DeserializeObject<JObject>(new StreamReader(req.Request.Body).ReadToEnd()), _Closed.Token);
await _Requests.Writer.WriteAsync(JsonConvert.DeserializeObject<JObject>(await new StreamReader(req.Request.Body).ReadToEndAsync()), _Closed.Token);
req.Response.StatusCode = 200;
return Task.CompletedTask;
});
})
.UseKestrel()

@ -5,10 +5,12 @@ ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
WORKDIR /source
COPY nuget.config nuget.config
COPY Build/Common.csproj Build/Common.csproj
COPY BTCPayServer/BTCPayServer.csproj BTCPayServer/BTCPayServer.csproj
COPY BTCPayServer.Common/BTCPayServer.Common.csproj BTCPayServer.Common/BTCPayServer.Common.csproj
COPY BTCPayServer.Rating/BTCPayServer.Rating.csproj BTCPayServer.Rating/BTCPayServer.Rating.csproj
COPY BTCPayServer.Data/BTCPayServer.Data.csproj BTCPayServer.Data/BTCPayServer.Data.csproj
COPY BTCPayServer.Tests/BTCPayServer.Tests.csproj BTCPayServer.Tests/BTCPayServer.Tests.csproj
RUN dotnet restore BTCPayServer.Tests/BTCPayServer.Tests.csproj
@ -23,6 +25,6 @@ ENV SCREEN_HEIGHT 600 \
SCREEN_WIDTH 1200
COPY . .
RUN cd BTCPayServer.Tests && dotnet build
RUN cd BTCPayServer.Tests && dotnet build /p:CI_TESTS=true
WORKDIR /source/BTCPayServer.Tests
ENTRYPOINT ["./docker-entrypoint.sh"]

@ -1,4 +1,6 @@
using System.Text;
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Tests.Logging;
using Microsoft.AspNetCore.Mvc;
@ -26,6 +28,11 @@ namespace BTCPayServer.Tests
try
{
Assert.NotEmpty(driver.FindElements(By.ClassName("navbar-brand")));
if (driver.PageSource.Contains("alert-danger"))
{
foreach (var dangerAlert in driver.FindElements(By.ClassName("alert-danger")))
Assert.False(dangerAlert.Displayed, "No alert should be displayed");
}
}
catch
{
@ -68,20 +75,26 @@ namespace BTCPayServer.Tests
return Assert.IsType<T>(vr.Model);
}
public static IWebElement AssertElementNotFound(this IWebDriver driver, By by)
public static void AssertElementNotFound(this IWebDriver driver, By by)
{
try
{
var webElement = driver.FindElement(by);
Assert.False(webElement.Displayed);
return webElement;
}
catch (NoSuchElementException)
{
}
DateTimeOffset now = DateTimeOffset.Now;
var wait = SeleniumTester.ImplicitWait;
return null;
while (DateTimeOffset.UtcNow - now < wait)
{
try
{
var webElement = driver.FindElement(by);
if (!webElement.Displayed)
return;
}
catch (NoSuchElementException)
{
return;
}
Thread.Sleep(50);
}
Assert.False(true, "Elements was found");
}
}
}

@ -1,4 +1,4 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;

@ -11,6 +11,7 @@ using NBitcoin;
using NBitpayClient;
using Xunit;
using Xunit.Abstractions;
using BTCPayServer.Models;
namespace BTCPayServer.Tests
{
@ -27,7 +28,7 @@ namespace BTCPayServer.Tests
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -49,7 +50,7 @@ namespace BTCPayServer.Tests
Assert.Equal("paid", invoice.Status);
});
var walletController = tester.PayTester.GetController<WalletsController>(user.UserId);
var walletController = user.GetController<WalletsController>();
var walletId = new WalletId(user.StoreId, "BTC");
var sendDestination = new Key().PubKey.Hash.GetAddress(user.SupportedNetwork.NBitcoinNetwork).ToString();
var sendModel = new WalletSendModel()
@ -68,10 +69,9 @@ namespace BTCPayServer.Tests
var vmLedger = await walletController.WalletSend(walletId, sendModel, command: "ledger").AssertViewModelAsync<WalletSendLedgerModel>();
PSBT.Parse(vmLedger.PSBT, user.SupportedNetwork.NBitcoinNetwork);
BitcoinAddress.Create(vmLedger.HintChange, user.SupportedNetwork.NBitcoinNetwork);
Assert.NotNull(vmLedger.SuccessPath);
Assert.NotNull(vmLedger.WebsocketPath);
var redirectedPSBT = (string)Assert.IsType<RedirectToActionResult>(await walletController.WalletSend(walletId, sendModel, command: "analyze-psbt")).RouteValues["psbt"];
string redirectedPSBT = AssertRedirectedPSBT(await walletController.WalletSend(walletId, sendModel, command: "analyze-psbt"));
var vmPSBT = await walletController.WalletPSBT(walletId, new WalletPSBTViewModel() { PSBT = redirectedPSBT }).AssertViewModelAsync<WalletPSBTViewModel>();
var unsignedPSBT = PSBT.Parse(vmPSBT.PSBT, user.SupportedNetwork.NBitcoinNetwork);
Assert.NotNull(vmPSBT.Decoded);
@ -98,9 +98,9 @@ namespace BTCPayServer.Tests
var combineVM = await walletController.WalletPSBT(walletId, vmPSBT, "combine").AssertViewModelAsync<WalletPSBTCombineViewModel>();
Assert.Equal(vmPSBT.PSBT, combineVM.OtherPSBT);
combineVM.PSBT = signedPSBT.ToBase64();
vmPSBT = await walletController.WalletPSBTCombine(walletId, combineVM).AssertViewModelAsync<WalletPSBTViewModel>();
var psbt = AssertRedirectedPSBT(await walletController.WalletPSBTCombine(walletId, combineVM));
var signedPSBT2 = PSBT.Parse(vmPSBT.PSBT, user.SupportedNetwork.NBitcoinNetwork);
var signedPSBT2 = PSBT.Parse(psbt, user.SupportedNetwork.NBitcoinNetwork);
Assert.True(signedPSBT.TryFinalize(out _));
Assert.True(signedPSBT2.TryFinalize(out _));
Assert.Equal(signedPSBT, signedPSBT2);
@ -108,19 +108,27 @@ namespace BTCPayServer.Tests
// Can use uploaded file?
combineVM.PSBT = null;
combineVM.UploadedPSBTFile = TestUtils.GetFormFile("signedPSBT", signedPSBT.ToBytes());
vmPSBT = await walletController.WalletPSBTCombine(walletId, combineVM).AssertViewModelAsync<WalletPSBTViewModel>();
signedPSBT2 = PSBT.Parse(vmPSBT.PSBT, user.SupportedNetwork.NBitcoinNetwork);
psbt = AssertRedirectedPSBT(await walletController.WalletPSBTCombine(walletId, combineVM));
signedPSBT2 = PSBT.Parse(psbt, user.SupportedNetwork.NBitcoinNetwork);
Assert.True(signedPSBT.TryFinalize(out _));
Assert.True(signedPSBT2.TryFinalize(out _));
Assert.Equal(signedPSBT, signedPSBT2);
var ready = (await walletController.WalletPSBTReady(walletId, signedPSBT.ToBase64())).AssertViewModel<WalletPSBTReadyViewModel>();
Assert.Equal(signedPSBT.ToBase64(), ready.PSBT);
redirect = Assert.IsType<RedirectToActionResult>(await walletController.WalletPSBTReady(walletId, ready, command: "analyze-psbt"));
Assert.Equal(signedPSBT.ToBase64(), (string)redirect.RouteValues["psbt"]);
psbt = AssertRedirectedPSBT(await walletController.WalletPSBTReady(walletId, ready, command: "analyze-psbt"));
Assert.Equal(signedPSBT.ToBase64(), psbt);
redirect = Assert.IsType<RedirectToActionResult>(await walletController.WalletPSBTReady(walletId, ready, command: "broadcast"));
Assert.Equal(nameof(walletController.WalletTransactions), redirect.ActionName);
}
}
private static string AssertRedirectedPSBT(IActionResult view)
{
var postRedirectView = Assert.IsType<ViewResult>(view);
var postRedirectViewModel = Assert.IsType<PostRedirectViewModel>(postRedirectView.Model);
var redirectedPSBT = postRedirectViewModel.Parameters.Single(p => p.Key == "psbt").Value;
return redirectedPSBT;
}
}
}

@ -37,11 +37,11 @@ namespace BTCPayServer.Tests
[Fact]
[Trait("Integration", "Integration")]
public void CanCreateViewUpdateAndDeletePaymentRequest()
public async Task CanCreateViewUpdateAndDeletePaymentRequest()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -98,7 +98,7 @@ namespace BTCPayServer.Tests
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -160,7 +160,7 @@ namespace BTCPayServer.Tests
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");

@ -40,9 +40,9 @@ namespace BTCPayServer.Tests
}
public void Start()
public async Task StartAsync()
{
Server.Start();
await Server.StartAsync();
ChromeOptions options = new ChromeOptions();
var isDebug = !Server.PayTester.InContainer;
@ -65,20 +65,29 @@ namespace BTCPayServer.Tests
Logs.Tester.LogInformation("Selenium: Using chrome driver");
Logs.Tester.LogInformation("Selenium: Browsing to " + Server.PayTester.ServerUri);
Logs.Tester.LogInformation($"Selenium: Resolution {Driver.Manage().Window.Size}");
Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
Driver.Navigate().GoToUrl(Server.PayTester.ServerUri);
Driver.Manage().Timeouts().ImplicitWait = ImplicitWait;
GoToRegister();
Driver.AssertNoError();
}
internal void AssertHappyMessage()
{
Assert.Single(Driver.FindElements(By.ClassName("alert-success")).Where(el => el.Displayed));
}
public static readonly TimeSpan ImplicitWait = TimeSpan.FromSeconds(10);
public string Link(string relativeLink)
{
return Server.PayTester.ServerUri.AbsoluteUri.WithoutEndingSlash() + relativeLink.WithStartingSlash();
}
public void GoToRegister()
{
Driver.Navigate().GoToUrl(this.Link("/Account/Register"));
}
public string RegisterNewUser(bool isAdmin = false)
{
var usr = RandomUtils.GetUInt256().ToString().Substring(64 - 20) + "@a.com";
Driver.FindElement(By.Id("Register")).Click();
Driver.FindElement(By.Id("Email")).SendKeys(usr);
Driver.FindElement(By.Id("Password")).SendKeys("123456");
Driver.FindElement(By.Id("ConfirmPassword")).SendKeys("123456");
@ -106,8 +115,7 @@ namespace BTCPayServer.Tests
Driver.FindElement(By.ClassName("store-derivation-scheme")).SendKeys(derivationScheme);
Driver.FindElement(By.Id("Continue")).ForceClick();
Driver.FindElement(By.Id("Confirm")).ForceClick();
Driver.FindElement(By.Id("Save")).ForceClick();
return;
AssertHappyMessage();
}
public void AddLightningNode(string cryptoCode, LightningConnectionType connectionType)
@ -141,6 +149,7 @@ namespace BTCPayServer.Tests
Assert.NotEmpty(links);
foreach (var l in links)
{
Logs.Tester.LogInformation($"Checking no error on {l}");
Driver.Navigate().GoToUrl(l);
Driver.AssertNoError();
}

@ -8,44 +8,69 @@ using OpenQA.Selenium.Interactions;
using System.Linq;
using NBitcoin;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace BTCPayServer.Tests
{
[Trait("Selenium", "Selenium")]
public class ChromeTests
{
public const int TestTimeout = TestUtils.TestTimeout;
public ChromeTests(ITestOutputHelper helper)
{
Logs.Tester = new XUnitLog(helper) { Name = "Tests" };
Logs.LogProvider = new XUnitLogProvider(helper);
}
[Fact]
public void CanNavigateServerSettings()
[Fact(Timeout = TestTimeout)]
public async Task CanNavigateServerSettings()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
s.RegisterNewUser(true);
s.Driver.FindElement(By.Id("ServerSettings")).Click();
s.Driver.AssertNoError();
s.ClickOnAllSideMenus();
s.Driver.FindElement(By.LinkText("Services")).Click();
Logs.Tester.LogInformation("Let's if we can access LND's seed");
Assert.Contains("server/services/lndseedbackup/BTC", s.Driver.PageSource);
s.Driver.Navigate().GoToUrl(s.Link("/server/services/lndseedbackup/BTC"));
s.Driver.FindElement(By.Id("details")).Click();
var seedEl = s.Driver.FindElement(By.Id("SeedTextArea"));
Assert.True(seedEl.Displayed);
Assert.Contains("about over million", seedEl.Text, StringComparison.OrdinalIgnoreCase);
var passEl = s.Driver.FindElement(By.Id("PasswordInput"));
Assert.True(passEl.Displayed);
Assert.Contains(passEl.Text, "hellorockstar", StringComparison.OrdinalIgnoreCase);
s.Driver.FindElement(By.Id("delete")).Click();
s.Driver.FindElement(By.Id("continue")).Click();
s.AssertHappyMessage();
seedEl = s.Driver.FindElement(By.Id("SeedTextArea"));
Assert.Contains("Seed removed", seedEl.Text, StringComparison.OrdinalIgnoreCase);
Logs.Tester.LogInformation("Let's check if we can access the logs");
s.Driver.FindElement(By.LinkText("Logs")).Click();
s.Driver.FindElement(By.PartialLinkText(".log")).Click();
Assert.Contains("Starting listening NBXplorer", s.Driver.PageSource);
s.Driver.Quit();
}
}
[Fact]
public void NewUserLogin()
[Fact(Timeout = TestTimeout)]
public async Task NewUserLogin()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
//Register & Log Out
var email = s.RegisterNewUser();
s.Driver.FindElement(By.Id("Logout")).Click();
s.Driver.AssertNoError();
s.Driver.FindElement(By.Id("Login")).Click();
s.Driver.AssertNoError();
Assert.Contains("Account/Login", s.Driver.Url);
// Should show the Tor address
Assert.Contains("wsaxew3qa5ljfuenfebmaf3m5ykgatct3p6zjrqwoouj3foererde3id.onion", s.Driver.PageSource);
s.Driver.Navigate().GoToUrl(s.Link("/invoices"));
Assert.Contains("ReturnUrl=%2Finvoices", s.Driver.Url);
@ -74,7 +99,6 @@ namespace BTCPayServer.Tests
s.Driver.AssertNoError();
//Log In With New Password
s.Driver.FindElement(By.Id("Login")).Click();
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
s.Driver.FindElement(By.Id("Password")).SendKeys("abc???");
s.Driver.FindElement(By.Id("LoginButton")).Click();
@ -89,18 +113,17 @@ namespace BTCPayServer.Tests
static void LogIn(SeleniumTester s, string email)
{
s.Driver.FindElement(By.Id("Login")).Click();
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
s.Driver.FindElement(By.Id("Password")).SendKeys("123456");
s.Driver.FindElement(By.Id("LoginButton")).Click();
s.Driver.AssertNoError();
}
[Fact]
[Fact(Timeout = TestTimeout)]
public async Task CanUseSSHService()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
var alice = s.RegisterNewUser(isAdmin: true);
s.Driver.Navigate().GoToUrl(s.Link("/server/services"));
Assert.Contains("server/services/ssh", s.Driver.PageSource);
@ -132,12 +155,12 @@ namespace BTCPayServer.Tests
}
}
[Fact]
public void CanUseDynamicDns()
[Fact(Timeout = TestTimeout)]
public async Task CanUseDynamicDns()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
var alice = s.RegisterNewUser(isAdmin: true);
s.Driver.Navigate().GoToUrl(s.Link("/server/services"));
Assert.Contains("Dynamic DNS", s.Driver.PageSource);
@ -182,12 +205,12 @@ namespace BTCPayServer.Tests
}
}
[Fact]
public void CanCreateStores()
[Fact(Timeout = TestTimeout)]
public async Task CanCreateStores()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
var alice = s.RegisterNewUser();
var store = s.CreateNewStore().storeName;
s.AddDerivationScheme();
@ -197,6 +220,7 @@ namespace BTCPayServer.Tests
s.ClickOnAllSideMenus();
s.GoToInvoices();
s.CreateInvoice(store);
s.AssertHappyMessage();
s.Driver.FindElement(By.ClassName("invoice-details-link")).Click();
var invoiceUrl = s.Driver.Url;
@ -206,7 +230,7 @@ namespace BTCPayServer.Tests
Assert.Contains("ReturnUrl", s.Driver.Url);
s.Driver.Navigate().GoToUrl(invoiceUrl);
Assert.Contains("ReturnUrl", s.Driver.Url);
s.GoToRegister();
// When logged we should not be able to access store and invoice details
var bob = s.RegisterNewUser();
s.Driver.Navigate().GoToUrl(storeUrl);
@ -229,17 +253,85 @@ namespace BTCPayServer.Tests
Assert.Contains("ReturnUrl", s.Driver.Url);
s.Driver.Navigate().GoToUrl(invoiceUrl);
s.Driver.AssertNoError();
// Alice should be able to delete the store
s.Logout();
LogIn(s, alice);
s.Driver.FindElement(By.Id("Stores")).Click();
s.Driver.FindElement(By.LinkText("Remove")).Click();
s.Driver.FindElement(By.Id("continue")).Click();
s.Driver.FindElement(By.Id("Stores")).Click();
s.Driver.Navigate().GoToUrl(storeUrl);
Assert.Contains("ReturnUrl", s.Driver.Url);
}
}
[Fact]
public void CanCreateAppPoS()
[Fact(Timeout = TestTimeout)]
public async Task CanUsePairing()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
s.Driver.Navigate().GoToUrl(s.Link("/api-access-request"));
Assert.Contains("ReturnUrl", s.Driver.Url);
s.GoToRegister();
var alice = s.RegisterNewUser();
var store = s.CreateNewStore().storeName;
s.AddDerivationScheme();
s.Driver.FindElement(By.Id("Tokens")).Click();
s.Driver.FindElement(By.Id("CreateNewToken")).Click();
s.Driver.FindElement(By.Id("RequestPairing")).Click();
string pairingCode = AssertUrlHasPairingCode(s);
s.Driver.FindElement(By.Id("ApprovePairing")).Click();
s.AssertHappyMessage();
Assert.Contains(pairingCode, s.Driver.PageSource);
var client = new NBitpayClient.Bitpay(new Key(), s.Server.PayTester.ServerUri);
await client.AuthorizeClient(new NBitpayClient.PairingCode(pairingCode));
await client.CreateInvoiceAsync(new NBitpayClient.Invoice()
{
Price = 0.000000012m,
Currency = "USD",
FullNotifications = true
}, NBitpayClient.Facade.Merchant);
client = new NBitpayClient.Bitpay(new Key(), s.Server.PayTester.ServerUri);
var code = await client.RequestClientAuthorizationAsync("hehe", NBitpayClient.Facade.Merchant);
s.Driver.Navigate().GoToUrl(code.CreateLink(s.Server.PayTester.ServerUri));
s.Driver.FindElement(By.Id("ApprovePairing")).Click();
await client.CreateInvoiceAsync(new NBitpayClient.Invoice()
{
Price = 0.000000012m,
Currency = "USD",
FullNotifications = true
}, NBitpayClient.Facade.Merchant);
s.Driver.Navigate().GoToUrl(s.Link("/api-tokens"));
s.Driver.FindElement(By.Id("RequestPairing")).Click();
s.Driver.FindElement(By.Id("ApprovePairing")).Click();
AssertUrlHasPairingCode(s);
}
}
private static string AssertUrlHasPairingCode(SeleniumTester s)
{
var regex = Regex.Match(new Uri(s.Driver.Url, UriKind.Absolute).Query, "pairingCode=([^&]*)");
Assert.True(regex.Success, $"{s.Driver.Url} does not match expected regex");
var pairingCode = regex.Groups[1].Value;
return pairingCode;
}
[Fact(Timeout = TestTimeout)]
public async Task CanCreateAppPoS()
{
using (var s = SeleniumTester.Create())
{
await s.StartAsync();
s.RegisterNewUser();
var store = s.CreateNewStore();
@ -258,12 +350,12 @@ namespace BTCPayServer.Tests
}
}
[Fact]
public void CanCreateAppCF()
[Fact(Timeout = TestTimeout)]
public async Task CanCreateAppCF()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
s.RegisterNewUser();
var store = s.CreateNewStore();
s.AddDerivationScheme();
@ -286,12 +378,12 @@ namespace BTCPayServer.Tests
}
}
[Fact]
public void CanCreatePayRequest()
[Fact(Timeout = TestTimeout)]
public async Task CanCreatePayRequest()
{
using (var s = SeleniumTester.Create())
{
s.Start();
await s.StartAsync();
s.RegisterNewUser();
s.CreateNewStore();
s.AddDerivationScheme();
@ -309,13 +401,13 @@ namespace BTCPayServer.Tests
}
}
[Fact]
public void CanManageWallet()
[Fact(Timeout = TestTimeout)]
public async Task CanManageWallet()
{
using (var s = SeleniumTester.Create())
{
s.Start();
s.RegisterNewUser();
await s.StartAsync();
s.RegisterNewUser(true);
s.CreateNewStore();
// In this test, we try to spend from a manual seed. We import the xpub 49'/0'/0', then try to use the seed
@ -331,6 +423,10 @@ namespace BTCPayServer.Tests
s.ClickOnAllSideMenus();
// Make sure we can rescan, because we are admin!
s.Driver.FindElement(By.Id("WalletRescan")).ForceClick();
Assert.Contains("The batch size make sure", s.Driver.PageSource);
// We setup the fingerprint and the account key path
s.Driver.FindElement(By.Id("WalletSettings")).ForceClick();
s.Driver.FindElement(By.Id("AccountKeys_0__MasterFingerprint")).SendKeys("8bafd160");

@ -82,9 +82,9 @@ namespace BTCPayServer.Tests
get; set;
}
public void Start()
public Task StartAsync()
{
PayTester.Start();
return PayTester.StartAsync();
}
/// <summary>
@ -166,12 +166,14 @@ namespace BTCPayServer.Tests
public void Dispose()
{
Logs.Tester.LogInformation("Disposing the BTCPayTester...");
foreach (var store in Stores)
{
Xunit.Assert.True(PayTester.StoreRepository.DeleteStore(store).GetAwaiter().GetResult());
}
if (PayTester != null)
PayTester.Dispose();
Logs.Tester.LogInformation("BTCPayTester disposed");
}
}
}

@ -12,7 +12,6 @@ using BTCPayServer.Storage.ViewModels;
using BTCPayServer.Tests.Logging;
using DBriize.Utils;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources;
@ -29,13 +28,13 @@ namespace BTCPayServer.Tests
Logs.LogProvider = new XUnitLogProvider(helper);
}
[Fact]
[Fact(Timeout = TestUtils.TestTimeout)]
[Trait("Integration", "Integration")]
public async void CanConfigureStorage()
public async Task CanConfigureStorage()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
var controller = tester.PayTester.GetController<ServerController>(user.UserId, user.StoreId);
@ -118,7 +117,7 @@ namespace BTCPayServer.Tests
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
var controller = tester.PayTester.GetController<ServerController>(user.UserId, user.StoreId);
@ -140,13 +139,13 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestUtils.TestTimeout)]
[Trait("ExternalIntegration", "ExternalIntegration")]
public async Task CanUseAzureBlobStorage()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
var controller = tester.PayTester.GetController<ServerController>(user.UserId, user.StoreId);
@ -211,8 +210,8 @@ namespace BTCPayServer.Tests
TimeAmount = 1,
TimeType = ServerController.CreateTemporaryFileUrlViewModel.TmpFileTimeType.Minutes
}));
Assert.True(tmpLinkGenerate.RouteValues.ContainsKey("StatusMessage"));
var statusMessageModel = new StatusMessageModel(tmpLinkGenerate.RouteValues["StatusMessage"].ToString());
var statusMessageModel = controller.TempData.GetStatusMessageModel();
Assert.NotNull(statusMessageModel);
Assert.Equal(StatusMessageModel.StatusSeverity.Success, statusMessageModel.Severity);
var index = statusMessageModel.Html.IndexOf("target='_blank'>");
var url = statusMessageModel.Html.Substring(index).ReplaceMultiple(new Dictionary<string, string>()
@ -222,12 +221,14 @@ namespace BTCPayServer.Tests
//verify tmpfile is available and the same
data = await net.DownloadStringTaskAsync(new Uri(url));
Assert.Equal(fileContent, data);
//delete file
Assert.Equal(StatusMessageModel.StatusSeverity.Success, new StatusMessageModel(Assert
.IsType<RedirectToActionResult>(await controller.DeleteFile(fileId))
.RouteValues["statusMessage"].ToString()).Severity);
Assert.IsType<RedirectToActionResult>(await controller.DeleteFile(fileId));
controller.TempData.GetStatusMessageModel();
Assert.NotNull(statusMessageModel);
Assert.Equal(StatusMessageModel.StatusSeverity.Success, statusMessageModel.Severity);
//attempt to fetch deleted file
viewFilesViewModel =

@ -20,6 +20,7 @@ using BTCPayServer.Lightning.CLightning;
using BTCPayServer.Data;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using Microsoft.AspNetCore.Identity;
namespace BTCPayServer.Tests
{
@ -37,6 +38,13 @@ namespace BTCPayServer.Tests
GrantAccessAsync().GetAwaiter().GetResult();
}
public async Task MakeAdmin()
{
var userManager = parent.PayTester.GetService<UserManager<ApplicationUser>>();
var u = await userManager.FindByIdAsync(UserId);
await userManager.AddToRoleAsync(u, Roles.ServerAdmin);
}
public void Register()
{
RegisterAsync().GetAwaiter().GetResult();
@ -78,7 +86,8 @@ namespace BTCPayServer.Tests
public T GetController<T>(bool setImplicitStore = true) where T : Controller
{
return parent.PayTester.GetController<T>(UserId, setImplicitStore ? StoreId : null);
var controller = parent.PayTester.GetController<T>(UserId, setImplicitStore ? StoreId : null, IsAdmin);
return controller;
}
public async Task CreateStoreAsync()
@ -140,6 +149,7 @@ namespace BTCPayServer.Tests
{
get; set;
}
public bool IsAdmin { get; internal set; }
public void RegisterLightningNode(string cryptoCode, LightningConnectionType connectionType)
{
@ -172,7 +182,7 @@ namespace BTCPayServer.Tests
public async Task<BTCPayOpenIdClient> RegisterOpenIdClient(OpenIddictApplicationDescriptor descriptor, string secret = null)
{
var openIddictApplicationManager = parent.PayTester.GetService<OpenIddictApplicationManager<BTCPayOpenIdClient>>();
var client = new BTCPayOpenIdClient {ApplicationUserId = UserId};
var client = new BTCPayOpenIdClient { Id = Guid.NewGuid().ToString(), ApplicationUserId = UserId};
await openIddictApplicationManager.PopulateAsync(client, descriptor);
await openIddictApplicationManager.CreateAsync(client, secret);
return client;

@ -0,0 +1 @@
{"wallet_password":"hellorockstar", "cipher_seed_mnemonic":["about","over","million","coast","nature","gold","fabric","aware","adult","salute","sock","envelope","oblige","shed","basic","need","analyst","spot","worth","garbage","planet","genre","leave","cereal"]}

@ -0,0 +1 @@
rhrk7ncuqfcbkt7deaysn7st32hrf2tzztoumkj2vp3cqzy2d2arvdad.onion

@ -0,0 +1 @@
r32tqfpchpiptrfltyd4ku7q3ir4yidyfe4em63iz2g5wjcauyvyj4id.onion

@ -0,0 +1 @@
wsaxew3qa5ljfuenfebmaf3m5ykgatct3p6zjrqwoouj3foererde3id.onion

@ -0,0 +1 @@
wzaq2ek6a5g6jyhr7giqsz2gbr6qdtcuwywcyvfplvrk7ugup3virvad.onion

@ -0,0 +1 @@
jzebv74oaugje6aeykzcypzxs6pvt27wdmrcpe4pkjfprxgem2vyi7qd.onion

@ -0,0 +1 @@
aeyn6mou5himgmog4tlnbjlgx5bwtwsqttd7sn7hay6lksvlfwmtkqyd.onion

@ -0,0 +1 @@
uewlcjmuuwcgs43lpcc7d64k2pf4xs7yyer7ztsq6cblyjxue3bc35qd.onion

@ -0,0 +1 @@
4iz3q7dp5xn5isqxsslrvbjrltqoqqocq25zmjgzvvxm5yp57jj4buid.onion

@ -0,0 +1 @@
ii3kqeayarsxr2jqkmr2l5np2f4vn6lznk55upd3udfbfskbjdzoq4yd.onion

@ -0,0 +1,24 @@
# For the hidden service BTC-P2P
HiddenServiceDir hidden_services/BTC-P2P
# Redirecting to btcpayserver_bitcoind
HiddenServicePort 8333 172.19.0.2:39388
# For the hidden service BTC-RPC
HiddenServiceDir hidden_services/BTC-RPC
# Redirecting to btcpayserver_bitcoind
HiddenServicePort 8332 172.19.0.2:43782
# For the hidden service BTCPayServer
HiddenServiceDir hidden_services/BTCPayServer
# Redirecting to nginx
HiddenServicePort 80 172.19.0.13:80
# For the hidden service BTCTransmuter
HiddenServiceDir hidden_services/BTCTransmuter
# Redirecting to nginx
HiddenServicePort 80 172.19.0.13:80
# For the hidden service WooCommerce
HiddenServiceDir hidden_services/WooCommerce
# Redirecting to generated_woocommerce_1
HiddenServicePort 80 172.19.0.15:80
# For the hidden service c-lightning
HiddenServiceDir hidden_services/c-lightning
# Redirecting to btcpayserver_clightning_bitcoin
HiddenServicePort 9735 172.19.0.10:9735

@ -5,13 +5,43 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
#if NETCOREAPP21
using Microsoft.AspNetCore.Http.Internal;
#endif
using Xunit.Sdk;
using System.Linq;
namespace BTCPayServer.Tests
{
public static class TestUtils
{
#if DEBUG && !SHORT_TIMEOUT
public const int TestTimeout = 600_000;
#else
public const int TestTimeout = 60_000;
#endif
public static DirectoryInfo TryGetSolutionDirectoryInfo(string currentPath = null)
{
var directory = new DirectoryInfo(
currentPath ?? Directory.GetCurrentDirectory());
while (directory != null && !directory.GetFiles("*.sln").Any())
{
directory = directory.Parent;
}
return directory;
}
public static string GetTestDataFullPath(string relativeFilePath)
{
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
while (directory != null && !directory.GetFiles("*.csproj").Any())
{
directory = directory.Parent;
}
return Path.Combine(directory.FullName, "TestData", relativeFilePath);
}
public static FormFile GetFormFile(string filename, string content)
{
File.WriteAllText(filename, content);
@ -44,7 +74,7 @@ namespace BTCPayServer.Tests
formFile.ContentDisposition = $"form-data; name=\"file\"; filename=\"{fileInfo.Name}\"";
return formFile;
}
public static void Eventually(Action act, int ms = 200000)
public static void Eventually(Action act, int ms = 20_000)
{
CancellationTokenSource cts = new CancellationTokenSource(ms);
while (true)

@ -15,9 +15,7 @@ using System.IO;
using Newtonsoft.Json.Linq;
using BTCPayServer.Controllers;
using Microsoft.AspNetCore.Mvc;
using BTCPayServer.Authentication;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.Extensions;
using BTCPayServer.Data;
using Microsoft.EntityFrameworkCore;
using BTCPayServer.Services.Rates;
@ -57,16 +55,18 @@ using System.Security;
using System.Runtime.CompilerServices;
using System.Net;
using BTCPayServer.Models.AccountViewModels;
using BTCPayServer.Services.U2F.Models;
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using NBXplorer.DerivationStrategy;
using BTCPayServer.U2F.Models;
using BTCPayServer.Security.Bitpay;
using MemoryCache = Microsoft.Extensions.Caching.Memory.MemoryCache;
namespace BTCPayServer.Tests
{
public class UnitTest1
{
public const int TestTimeout = 60_000;
public UnitTest1(ITestOutputHelper helper)
{
Logs.Tester = new XUnitLog(helper) { Name = "Tests" };
@ -77,7 +77,7 @@ namespace BTCPayServer.Tests
[Trait("Fast", "Fast")]
public async Task CheckNoDeadLink()
{
var views = Path.Combine(LanguageService.TryGetSolutionDirectoryInfo().FullName, "BTCPayServer", "Views");
var views = Path.Combine(TestUtils.TryGetSolutionDirectoryInfo().FullName, "BTCPayServer", "Views");
var viewFiles = Directory.EnumerateFiles(views, "*.cshtml", SearchOption.AllDirectories).ToArray();
Assert.NotEmpty(viewFiles);
Regex regex = new Regex("href=\"(http.*?)[\"#]");
@ -428,7 +428,7 @@ namespace BTCPayServer.Tests
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var response = await tester.PayTester.HttpClient.GetAsync("");
Assert.True(response.IsSuccessStatusCode);
}
@ -473,11 +473,11 @@ namespace BTCPayServer.Tests
[Fact]
[Trait("Integration", "Integration")]
public void CanAcceptInvoiceWithTolerance2()
public async Task CanAcceptInvoiceWithTolerance2()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -533,13 +533,29 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Trait("Fast", "Fast")]
public async Task CanEnumerateTorServices()
{
var tor = new TorServices(new BTCPayNetworkProvider(NetworkType.Regtest), new BTCPayServerOptions()
{
TorrcFile = TestUtils.GetTestDataFullPath("Tor/torrc")
});
await tor.Refresh();
Assert.Single(tor.Services.Where(t => t.ServiceType == TorServiceType.BTCPayServer));
Assert.Single(tor.Services.Where(t => t.ServiceType == TorServiceType.P2P));
Assert.Single(tor.Services.Where(t => t.ServiceType == TorServiceType.RPC));
Assert.True(tor.Services.Where(t => t.ServiceType == TorServiceType.Other).Count() > 1);
}
[Fact(Timeout = 60 * 2 * 1000)]
[Trait("Integration", "Integration")]
public async Task CanSetLightningServer()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
await tester.EnsureChannelsSetup();
var user = tester.NewAccount();
user.GrantAccess();
@ -552,7 +568,8 @@ namespace BTCPayServer.Tests
ConnectionString = "type=charge;server=" + tester.MerchantCharge.Client.Uri.AbsoluteUri,
SkipPortTest = true // We can't test this as the IP can't be resolved by the test host :(
}, "test", "BTC").GetAwaiter().GetResult();
Assert.DoesNotContain("Error", ((LightningNodeViewModel)Assert.IsType<ViewResult>(testResult).Model).StatusMessage, StringComparison.OrdinalIgnoreCase);
Assert.False(storeController.TempData.ContainsKey(WellKnownTempData.ErrorMessage));
storeController.TempData.Clear();
Assert.True(storeController.ModelState.IsValid);
Assert.IsType<RedirectToActionResult>(storeController.AddLightningNode(user.StoreId, new LightningNodeViewModel()
@ -599,7 +616,7 @@ namespace BTCPayServer.Tests
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
await tester.EnsureChannelsSetup();
var user = tester.NewAccount();
user.GrantAccess();
@ -636,23 +653,24 @@ namespace BTCPayServer.Tests
});
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanUseServerInitiatedPairingCode()
public async Task CanUseServerInitiatedPairingCode()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var acc = tester.NewAccount();
acc.Register();
acc.CreateStore();
var controller = acc.GetController<StoresController>();
var token = (RedirectToActionResult)controller.CreateToken(new Models.StoreViewModels.CreateTokenViewModel()
var token = (RedirectToActionResult)await controller.CreateToken2(new Models.StoreViewModels.CreateTokenViewModel()
{
Label = "bla",
PublicKey = null
}).GetAwaiter().GetResult();
PublicKey = null,
StoreId = acc.StoreId
});
var pairingCode = (string)token.RouteValues["pairingCode"];
@ -661,7 +679,7 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async Task CanSendIPN()
{
@ -669,7 +687,7 @@ namespace BTCPayServer.Tests
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var acc = tester.NewAccount();
acc.GrantAccess();
acc.RegisterDerivationScheme("BTC");
@ -685,7 +703,7 @@ namespace BTCPayServer.Tests
FullNotifications = true,
ExtendedNotifications = true
});
BitcoinUrlBuilder url = new BitcoinUrlBuilder(invoice.PaymentUrls.BIP21);
BitcoinUrlBuilder url = new BitcoinUrlBuilder(invoice.PaymentUrls.BIP21, tester.NetworkProvider.BTC.NBitcoinNetwork);
bool receivedPayment = false;
bool paid = false;
bool confirmed = false;
@ -729,13 +747,13 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CantPairTwiceWithSamePubkey()
public async Task CantPairTwiceWithSamePubkey()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var acc = tester.NewAccount();
acc.Register();
acc.CreateStore();
@ -746,12 +764,12 @@ namespace BTCPayServer.Tests
pairingCode = acc.BitPay.RequestClientAuthorization("test1", Facade.Merchant);
acc.CreateStore();
var store2 = acc.GetController<StoresController>();
store2.Pair(pairingCode.ToString(), store2.StoreData.Id).GetAwaiter().GetResult();
Assert.Contains(nameof(PairingResult.ReusedKey), store2.StatusMessage, StringComparison.CurrentCultureIgnoreCase);
await store2.Pair(pairingCode.ToString(), store2.CurrentStore.Id);
Assert.Contains(nameof(PairingResult.ReusedKey), (string)store2.TempData[WellKnownTempData.ErrorMessage], StringComparison.CurrentCultureIgnoreCase);
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanSolveTheDogesRatesOnKraken()
{
@ -768,20 +786,20 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async Task CanRescanWallet()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var acc = tester.NewAccount();
acc.GrantAccess();
acc.RegisterDerivationScheme("BTC", true);
var btcDerivationScheme = acc.DerivationScheme;
acc.RegisterDerivationScheme("LTC", true);
var walletController = tester.PayTester.GetController<WalletsController>(acc.UserId);
var walletController = acc.GetController<WalletsController>();
WalletId walletId = new WalletId(acc.StoreId, "LTC");
var rescan = Assert.IsType<RescanWalletModel>(Assert.IsType<ViewResult>(walletController.WalletRescan(walletId).Result).Model);
Assert.False(rescan.Ok);
@ -790,8 +808,9 @@ namespace BTCPayServer.Tests
Assert.False(rescan.IsServerAdmin);
walletId = new WalletId(acc.StoreId, "BTC");
var serverAdminClaim = new[] { new Claim(Policies.CanModifyServerSettings.Key, "true") };
walletController = tester.PayTester.GetController<WalletsController>(acc.UserId, additionalClaims: serverAdminClaim);
acc.IsAdmin = true;
walletController = acc.GetController<WalletsController>();
rescan = Assert.IsType<RescanWalletModel>(Assert.IsType<ViewResult>(walletController.WalletRescan(walletId).Result).Model);
Assert.True(rescan.Ok);
Assert.True(rescan.IsFullySync);
@ -861,13 +880,13 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanListInvoices()
public async Task CanListInvoices()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var acc = tester.NewAccount();
acc.GrantAccess();
acc.RegisterDerivationScheme("BTC");
@ -911,43 +930,43 @@ namespace BTCPayServer.Tests
[Fact]
[Trait("Integration", "Integration")]
public void CanGetRates()
public async Task CanGetRates()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var acc = tester.NewAccount();
acc.GrantAccess();
acc.RegisterDerivationScheme("BTC");
acc.RegisterDerivationScheme("LTC");
var rateController = acc.GetController<RateController>();
var GetBaseCurrencyRatesResult = JObject.Parse(((JsonResult)rateController.GetBaseCurrencyRates("BTC", acc.StoreId, default)
var GetBaseCurrencyRatesResult = JObject.Parse(((JsonResult)rateController.GetBaseCurrencyRates("BTC", default)
.GetAwaiter().GetResult()).Value.ToJson()).ToObject<DataWrapper<Rate[]>>();
Assert.NotNull(GetBaseCurrencyRatesResult);
Assert.NotNull(GetBaseCurrencyRatesResult.Data);
Assert.Equal(2, GetBaseCurrencyRatesResult.Data.Length);
Assert.Single(GetBaseCurrencyRatesResult.Data.Where(o => o.Code == "LTC"));
var GetRatesResult = JObject.Parse(((JsonResult)rateController.GetRates(null, acc.StoreId, default)
var GetRatesResult = JObject.Parse(((JsonResult)rateController.GetRates(null, default)
.GetAwaiter().GetResult()).Value.ToJson()).ToObject<DataWrapper<Rate[]>>();
// We don't have any default currencies, so this should be failing
Assert.Null(GetRatesResult?.Data);
var store = acc.GetController<StoresController>();
var ratesVM = (RatesViewModel)(Assert.IsType<ViewResult>(store.Rates(acc.StoreId)).Model);
var ratesVM = (RatesViewModel)(Assert.IsType<ViewResult>(store.Rates()).Model);
ratesVM.DefaultCurrencyPairs = "BTC_USD,LTC_USD";
store.Rates(ratesVM).Wait();
store = acc.GetController<StoresController>();
rateController = acc.GetController<RateController>();
GetRatesResult = JObject.Parse(((JsonResult)rateController.GetRates(null, acc.StoreId, default)
GetRatesResult = JObject.Parse(((JsonResult)rateController.GetRates(null, default)
.GetAwaiter().GetResult()).Value.ToJson()).ToObject<DataWrapper<Rate[]>>();
// Now we should have a result
Assert.NotNull(GetRatesResult);
Assert.NotNull(GetRatesResult.Data);
Assert.Equal(2, GetRatesResult.Data.Length);
var GetCurrencyPairRateResult = JObject.Parse(((JsonResult)rateController.GetCurrencyPairRate("BTC", "LTC", acc.StoreId, default)
var GetCurrencyPairRateResult = JObject.Parse(((JsonResult)rateController.GetCurrencyPairRate("BTC", "LTC", default)
.GetAwaiter().GetResult()).Value.ToJson()).ToObject<DataWrapper<Rate>>();
Assert.NotNull(GetCurrencyPairRateResult);
@ -958,7 +977,9 @@ namespace BTCPayServer.Tests
var rates = acc.BitPay.GetRates();
HttpClient client = new HttpClient();
// Unauthentified requests should also be ok
var response = client.GetAsync($"http://127.0.0.1:{tester.PayTester.Port}/api/rates?storeId={acc.StoreId}").GetAwaiter().GetResult();
var response = await client.GetAsync($"http://127.0.0.1:{tester.PayTester.Port}/api/rates?storeId={acc.StoreId}");
response.EnsureSuccessStatusCode();
response = await client.GetAsync($"http://127.0.0.1:{tester.PayTester.Port}/rates?storeId={acc.StoreId}");
response.EnsureSuccessStatusCode();
}
}
@ -969,13 +990,13 @@ namespace BTCPayServer.Tests
Assert.Equal(expected, result.Invoices.Any(i => i.InvoiceId == invoiceId));
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanRBFPayment()
public async Task CanRBFPayment()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -1039,7 +1060,7 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Fast", "Fast")]
public void CanParseFilter()
{
@ -1067,7 +1088,7 @@ namespace BTCPayServer.Tests
Assert.Equal("hekki", search.TextSearch);
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Fast", "Fast")]
public void CanParseFingerprint()
{
@ -1084,13 +1105,13 @@ namespace BTCPayServer.Tests
Assert.Equal(f1.ToString(), f2.ToString());
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async void CheckCORSSetOnBitpayAPI()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
foreach (var req in new[]
{
"invoices/",
@ -1122,13 +1143,13 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void TestAccessBitpayAPI()
public async Task TestAccessBitpayAPI()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
Assert.False(user.BitPay.TestAccess(Facade.Merchant));
user.GrantAccess();
@ -1138,7 +1159,7 @@ namespace BTCPayServer.Tests
// Test request pairing code client side
var storeController = user.GetController<StoresController>();
storeController.CreateToken(new CreateTokenViewModel()
storeController.CreateToken(user.StoreId, new CreateTokenViewModel()
{
Label = "test2",
StoreId = user.StoreId
@ -1199,14 +1220,14 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanUseExchangeSpecificRate()
public async Task CanUseExchangeSpecificRate()
{
using (var tester = ServerTester.Create())
{
tester.PayTester.MockRates = false;
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -1227,7 +1248,7 @@ namespace BTCPayServer.Tests
private static decimal CreateInvoice(ServerTester tester, TestAccount user, string exchange, string currency = "USD")
{
var storeController = user.GetController<StoresController>();
var vm = (RatesViewModel)((ViewResult)storeController.Rates(user.StoreId)).Model;
var vm = (RatesViewModel)((ViewResult)storeController.Rates()).Model;
vm.PreferredExchange = exchange;
storeController.Rates(vm).Wait();
var invoice2 = user.BitPay.CreateInvoice(new Invoice()
@ -1242,23 +1263,23 @@ namespace BTCPayServer.Tests
return invoice2.CryptoInfo[0].Rate;
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async Task CanUseAnyoneCanCreateInvoice()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
Logs.Tester.LogInformation("StoreId without anyone can create invoice = 401");
Logs.Tester.LogInformation("StoreId without anyone can create invoice = 403");
var response = await tester.PayTester.HttpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, $"invoices?storeId={user.StoreId}")
{
Content = new StringContent("{\"Price\": 5000, \"currency\": \"USD\"}", Encoding.UTF8, "application/json"),
});
Assert.Equal(401, (int)response.StatusCode);
Assert.Equal(403, (int)response.StatusCode);
Logs.Tester.LogInformation("No store without anyone can create invoice = 404 because the bitpay API can't know the storeid");
response = await tester.PayTester.HttpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, $"invoices")
@ -1269,12 +1290,12 @@ namespace BTCPayServer.Tests
user.ModifyStore(s => s.AnyoneCanCreateInvoice = true);
Logs.Tester.LogInformation("Bad store with anyone can create invoice = 401");
Logs.Tester.LogInformation("Bad store with anyone can create invoice = 403");
response = await tester.PayTester.HttpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, $"invoices?storeId=badid")
{
Content = new StringContent("{\"Price\": 5000, \"currency\": \"USD\"}", Encoding.UTF8, "application/json"),
});
Assert.Equal(401, (int)response.StatusCode);
Assert.Equal(403, (int)response.StatusCode);
Logs.Tester.LogInformation("Good store with anyone can create invoice = 200");
response = await tester.PayTester.HttpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, $"invoices?storeId={user.StoreId}")
@ -1285,13 +1306,13 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanTweakRate()
public async Task CanTweakRate()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -1308,7 +1329,7 @@ namespace BTCPayServer.Tests
Assert.Equal(Money.Coins(1.0m), invoice1.BtcPrice);
var storeController = user.GetController<StoresController>();
var vm = (RatesViewModel)((ViewResult)storeController.Rates(user.StoreId)).Model;
var vm = (RatesViewModel)((ViewResult)storeController.Rates()).Model;
Assert.Equal(0.0, vm.Spread);
vm.Spread = 40;
storeController.Rates(vm).Wait();
@ -1330,13 +1351,13 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanHaveLTCOnlyStore()
public async Task CanHaveLTCOnlyStore()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("LTC");
@ -1395,19 +1416,19 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanModifyRates()
public async Task CanModifyRates()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
var store = user.GetController<StoresController>();
var rateVm = Assert.IsType<RatesViewModel>(Assert.IsType<ViewResult>(store.Rates(user.StoreId)).Model);
var rateVm = Assert.IsType<RatesViewModel>(Assert.IsType<ViewResult>(store.Rates()).Model);
Assert.False(rateVm.ShowScripting);
Assert.Equal("coinaverage", rateVm.PreferredExchange);
Assert.Equal(0.0, rateVm.Spread);
@ -1415,7 +1436,7 @@ namespace BTCPayServer.Tests
rateVm.PreferredExchange = "bitflyer";
Assert.IsType<RedirectToActionResult>(store.Rates(rateVm, "Save").Result);
rateVm = Assert.IsType<RatesViewModel>(Assert.IsType<ViewResult>(store.Rates(user.StoreId)).Model);
rateVm = Assert.IsType<RatesViewModel>(Assert.IsType<ViewResult>(store.Rates()).Model);
Assert.Equal("bitflyer", rateVm.PreferredExchange);
rateVm.ScriptTest = "BTC_JPY,BTC_CAD";
@ -1432,7 +1453,7 @@ namespace BTCPayServer.Tests
Assert.IsType<RedirectToActionResult>(store.ShowRateRulesPost(true).Result);
Assert.IsType<RedirectToActionResult>(store.Rates(rateVm, "Save").Result);
store = user.GetController<StoresController>();
rateVm = Assert.IsType<RatesViewModel>(Assert.IsType<ViewResult>(store.Rates(user.StoreId)).Model);
rateVm = Assert.IsType<RatesViewModel>(Assert.IsType<ViewResult>(store.Rates()).Model);
Assert.Equal(rateVm.StoreId, user.StoreId);
Assert.Equal(rateVm.DefaultScript, rateVm.Script);
Assert.True(rateVm.ShowScripting);
@ -1450,20 +1471,20 @@ namespace BTCPayServer.Tests
Assert.True(rateVm.TestRateRules.All(t => !t.Error));
Assert.IsType<RedirectToActionResult>(store.Rates(rateVm, "Save").Result);
store = user.GetController<StoresController>();
rateVm = Assert.IsType<RatesViewModel>(Assert.IsType<ViewResult>(store.Rates(user.StoreId)).Model);
rateVm = Assert.IsType<RatesViewModel>(Assert.IsType<ViewResult>(store.Rates()).Model);
Assert.Equal(50, rateVm.Spread);
Assert.True(rateVm.ShowScripting);
Assert.Contains("DOGE_X", rateVm.Script, StringComparison.OrdinalIgnoreCase);
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanPayWithTwoCurrencies()
public async Task CanPayWithTwoCurrencies()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -1676,11 +1697,11 @@ namespace BTCPayServer.Tests
[Fact]
[Trait("Integration", "Integration")]
public void CanAddDerivationSchemes()
public async Task CanAddDerivationSchemes()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -1820,7 +1841,7 @@ namespace BTCPayServer.Tests
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
await tester.EnsureChannelsSetup();
var user = tester.NewAccount();
user.GrantAccess();
@ -1865,7 +1886,7 @@ namespace BTCPayServer.Tests
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -2000,7 +2021,7 @@ noninventoryitem:
//verify invoices where created
invoices = user.BitPay.GetInvoices();
Assert.Equal(2, invoices.Count(invoice => invoice.ItemCode.Equals("noninventoryitem")));
var inventoryItemInvoice = invoices.SingleOrDefault(invoice => invoice.ItemCode.Equals("inventoryitem"));
var inventoryItemInvoice = Assert.Single(invoices.Where(invoice => invoice.ItemCode.Equals("inventoryitem")));
Assert.NotNull(inventoryItemInvoice);
//let's mark the inventoryitem invoice as invalid, thsi should return the item to back in stock
@ -2092,7 +2113,7 @@ noninventoryitem:
Assert.True(client.WaitAllRunning(default).Wait(100));
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Fast", "Fast")]
public void PosDataParser_ParsesCorrectly()
{
@ -2115,13 +2136,13 @@ noninventoryitem:
});
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async Task PosDataParser_ParsesCorrectly_Slower()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -2161,9 +2182,9 @@ noninventoryitem:
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanExportInvoicesJson()
public async Task CanExportInvoicesJson()
{
decimal GetFieldValue(string input, string fieldName)
{
@ -2173,7 +2194,7 @@ noninventoryitem:
}
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -2236,13 +2257,13 @@ noninventoryitem:
});
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanChangeNetworkFeeMode()
public async Task CanChangeNetworkFeeMode()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -2317,13 +2338,13 @@ noninventoryitem:
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanExportInvoicesCsv()
public async Task CanExportInvoicesCsv()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -2357,13 +2378,13 @@ noninventoryitem:
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanCreateAndDeleteApps()
public async Task CanCreateAndDeleteApps()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
var user2 = tester.NewAccount();
@ -2394,13 +2415,13 @@ noninventoryitem:
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanCreateStrangeInvoice()
public async Task CanCreateStrangeInvoice()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -2455,13 +2476,13 @@ noninventoryitem:
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void InvoiceFlowThroughDifferentStatesCorrectly()
public async Task InvoiceFlowThroughDifferentStatesCorrectly()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -2622,22 +2643,7 @@ noninventoryitem:
}
}
//[Fact]
//[Trait("Integration", "Integration")]
// 29 january, the exchange is down
//public void CheckQuadrigacxRateProvider()
//{
// var quadri = new QuadrigacxRateProvider();
// var rates = quadri.GetRatesAsync().GetAwaiter().GetResult();
// Assert.NotEmpty(rates);
// Assert.NotEqual(0.0m, rates.First().BidAsk.Bid);
// Assert.NotEqual(0.0m, rates.GetRate(QuadrigacxRateProvider.QuadrigacxName, CurrencyPair.Parse("BTC_CAD")).Bid);
// Assert.NotEqual(0.0m, rates.GetRate(QuadrigacxRateProvider.QuadrigacxName, CurrencyPair.Parse("BTC_USD")).Bid);
// Assert.NotEqual(0.0m, rates.GetRate(QuadrigacxRateProvider.QuadrigacxName, CurrencyPair.Parse("LTC_CAD")).Bid);
// Assert.Null(rates.GetRate(QuadrigacxRateProvider.QuadrigacxName, CurrencyPair.Parse("LTC_USD")));
//}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanQueryDirectProviders()
{
@ -2679,7 +2685,7 @@ noninventoryitem:
factory.Providers["kraken"].GetRatesAsync(default).GetAwaiter().GetResult();
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public void CanGetRateCryptoCurrenciesByDefault()
{
@ -2734,13 +2740,13 @@ noninventoryitem:
}
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async Task CheckLogsRoute()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");
@ -2807,7 +2813,7 @@ noninventoryitem:
return name;
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Fast", "Fast")]
public void CheckRatesProvider()
{
@ -2893,50 +2899,14 @@ noninventoryitem:
Assert.True(DerivationSchemeSettings.TryParseFromColdcard("{\"keystore\": {\"ckcc_xpub\": \"tpubD6NzVbkrYhZ4YHNiuTdTmHRmbcPRLfqgyneZFCL1mkzkUBjXriQShxTh9HL34FK2mhieasJVk9EzJrUfkFqRNQBjiXgx3n5BhPkxKBoFmaS\", \"xpub\": \"vpub5YjYxTemJ39tFRnuAhwduyxG2tKGjoEpmvqVQRPqdYrqa6YGoeSzBtHXaJUYB19zDbXs3JjbEcVWERjQBPf9bEfUUMZNMv1QnMyHV8JPqyf\", \"label\": \"Coldcard Import 0x60d1af8b\", \"ckcc_xfp\": 1624354699, \"type\": \"hardware\", \"hw_type\": \"coldcard\", \"derivation\": \"m/84'/1'/0'\"}, \"wallet_type\": \"standard\", \"use_encryption\": false, \"seed_version\": 17}", testnet, out settings));
Assert.True(settings.AccountDerivation is DirectDerivationStrategy s3 && s3.Segwit);
}
[Fact]
[Trait("Fast", "Fast")]
public void CheckParseStatusMessageModel()
{
var legacyStatus = "Error: some bad shit happened";
var parsed = new StatusMessageModel(legacyStatus);
Assert.Equal(legacyStatus, parsed.Message);
Assert.Equal(StatusMessageModel.StatusSeverity.Error, parsed.Severity);
var legacyStatus2 = "Some normal shit happened";
parsed = new StatusMessageModel(legacyStatus2);
Assert.Equal(legacyStatus2, parsed.Message);
Assert.Equal(StatusMessageModel.StatusSeverity.Success, parsed.Severity);
var newStatus = new StatusMessageModel()
{
Html = "<a href='xxx'>something new</a>",
Severity = StatusMessageModel.StatusSeverity.Info
};
parsed = new StatusMessageModel(newStatus.ToString());
Assert.Null(parsed.Message);
Assert.Equal(newStatus.Html, parsed.Html);
Assert.Equal(StatusMessageModel.StatusSeverity.Info, parsed.Severity);
var newStatus2 = new StatusMessageModel()
{
Message = "something new",
Severity = StatusMessageModel.StatusSeverity.Success
};
parsed = new StatusMessageModel(newStatus2.ToString());
Assert.Null(parsed.Html);
Assert.Equal(newStatus2.Message, parsed.Message);
Assert.Equal(StatusMessageModel.StatusSeverity.Success, parsed.Severity);
}
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async Task CanCreateInvoiceWithSpecificPaymentMethods()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
await tester.EnsureChannelsSetup();
var user = tester.NewAccount();
user.GrantAccess();
@ -2965,13 +2935,13 @@ noninventoryitem:
[Fact]
[Fact(Timeout = TestTimeout)]
[Trait("Integration", "Integration")]
public async Task CanLoginWithNoSecondaryAuthSystemsOrRequestItWhenAdded()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.StartAsync();
var user = tester.NewAccount();
user.GrantAccess();
@ -2991,13 +2961,11 @@ noninventoryitem:
var addRequest = Assert.IsType<AddU2FDeviceViewModel>(Assert.IsType<ViewResult>(manageController.AddU2FDevice("label")).Model);
//name should match the one provided in beginning
Assert.Equal("label",addRequest.Name);
//sending an invalid response model back to server, should error out
var statusMessage = Assert
.IsType<RedirectToActionResult>(await manageController.AddU2FDevice(addRequest))
.RouteValues["StatusMessage"].ToString();
Assert.NotNull(statusMessage);
Assert.Equal(StatusMessageModel.StatusSeverity.Error, new StatusMessageModel(statusMessage).Severity);
//sending an invalid response model back to server, should error out
Assert.IsType<RedirectToActionResult>(await manageController.AddU2FDevice(addRequest));
var statusModel = manageController.TempData.GetStatusMessageModel();
Assert.Equal(StatusMessageModel.StatusSeverity.Error, statusModel.Severity);
var contextFactory = tester.PayTester.GetService<ApplicationDbContextFactory>();
@ -3006,6 +2974,7 @@ noninventoryitem:
{
var newDevice = new U2FDevice()
{
Id = Guid.NewGuid().ToString(),
Name = "fake",
Counter = 0,
KeyHandle = UTF8Encoding.UTF8.GetBytes("fake"),
@ -3039,7 +3008,8 @@ noninventoryitem:
private static bool IsMapped(Invoice invoice, ApplicationDbContext ctx)
{
var h = BitcoinAddress.Create(invoice.BitcoinAddress, Network.RegTest).ScriptPubKey.Hash.ToString();
return ctx.AddressInvoices.FirstOrDefault(i => i.InvoiceDataId == invoice.Id && i.GetAddress() == h) != null;
return (ctx.AddressInvoices.Where(i => i.InvoiceDataId == invoice.Id).ToArrayAsync().GetAwaiter().GetResult())
.Where(i => i.GetAddress() == h).Any();
}
}
}

@ -31,7 +31,7 @@ namespace BTCPayServer.Tests
var json = await client.GetTransifexAsync("https://api.transifex.com/organizations/btcpayserver/projects/btcpayserver/resources/enjson/");
var langs = new[] { "en" }.Concat(((JObject)json["stats"]).Properties().Select(n => n.Name)).ToArray();
var langsDir = Path.Combine(Services.LanguageService.TryGetSolutionDirectoryInfo().FullName, "BTCPayServer", "wwwroot", "locales");
var langsDir = Path.Combine(TestUtils.TryGetSolutionDirectoryInfo().FullName, "BTCPayServer", "wwwroot", "locales");
JObject sourceLang = null;
Task.WaitAll(langs.Select(async l =>

@ -0,0 +1,28 @@
version: "3"
services:
monerod:
image: kukks/docker-monero:test
restart: unless-stopped
container_name: xmr_monerod
entrypoint: monerod --fixed-difficulty 100 --rpc-bind-ip=0.0.0.0 --confirm-external-bind --rpc-bind-port=18081 --non-interactive --block-notify="/scripts/notifier.sh https://127.0.0.1:14142/monerolikedaemoncallback/block?cryptoCode=xmr&hash=%s" --testnet --no-igd --hide-my-port --no-sync --offline
volumes:
- "monero_data:/home/monero/.bitmonero"
ports:
- "18081:18081"
monero_wallet:
image: kukks/docker-monero:test
restart: unless-stopped
container_name: xmr_wallet_rpc
entrypoint: monero-wallet-rpc --testnet --rpc-bind-ip=0.0.0.0 --disable-rpc-login --confirm-external-bind --rpc-bind-port=18082 --non-interactive --trusted-daemon --daemon-address=127.0.0.1:18081 --wallet-file=/wallet/wallet.keys --tx-notify="/scripts/notifier.sh https://127.0.0.1:14142/monerolikedaemoncallback/tx?cryptoCode=xmr&hash=%s"
ports:
- "18082:18082"
volumes:
- "monero_wallet:/wallet"
depends_on:
- monerod
volumes:
monero_data:
monero_wallet:

@ -16,7 +16,6 @@ services:
TESTS_LTCNBXPLORERURL: http://nbxplorer:32838/
TESTS_DB: "Postgres"
TESTS_POSTGRES: User ID=postgres;Host=postgres;Port=5432;Database=btcpayserver
TESTS_PORT: 80
TESTS_HOSTNAME: tests
TESTS_RUN_EXTERNAL_INTEGRATION: ${TESTS_RUN_EXTERNAL_INTEGRATION:-false}
TESTS_AzureBlobStorageConnectionString: ${TESTS_AzureBlobStorageConnectionString:-none}
@ -77,7 +76,7 @@ services:
- customer_lnd
- merchant_lnd
nbxplorer:
image: nicolasdorier/nbxplorer:2.0.0.57
image: nicolasdorier/nbxplorer:2.0.0.66
restart: unless-stopped
ports:
- "32838:32838"
@ -128,7 +127,7 @@ services:
- "bitcoin_datadir:/data"
customer_lightningd:
image: btcpayserver/lightning:v0.7.1-dev
image: btcpayserver/lightning:v0.7.3-dev
stop_signal: SIGKILL
restart: unless-stopped
environment:
@ -141,7 +140,7 @@ services:
announce-addr=customer_lightningd
log-level=debug
funding-confirms=1
dev-broadcast-interval=1000
dev-fast-gossip
dev-bitcoind-poll=1
ports:
- "30992:9835" # api port
@ -155,7 +154,7 @@ services:
- bitcoind
lightning-charged:
image: shesek/lightning-charge:0.4.6-standalone
image: shesek/lightning-charge:0.4.11-standalone
restart: unless-stopped
environment:
NETWORK: regtest
@ -175,7 +174,7 @@ services:
- merchant_lightningd
merchant_lightningd:
image: btcpayserver/lightning:v0.7.1-dev
image: btcpayserver/lightning:v0.7.3-dev
stop_signal: SIGKILL
environment:
EXPOSE_TCP: "true"
@ -187,7 +186,8 @@ services:
announce-addr=merchant_lightningd
funding-confirms=1
log-level=debug
dev-broadcast-interval=1000
dev-fast-gossip
dev-bitcoind-poll=1
ports:
- "30993:9835" # api port
expose:
@ -224,7 +224,7 @@ services:
- "5432"
merchant_lnd:
image: btcpayserver/lnd:v0.7.0-beta
image: btcpayserver/lnd:v0.7.1-beta-withseed
restart: unless-stopped
environment:
LND_CHAIN: "btc"
@ -242,7 +242,6 @@ services:
bitcoin.defaultchanconfs=1
no-macaroons=1
debuglevel=debug
noseedbackup=1
trickledelay=1000
ports:
- "53280:8080"
@ -255,7 +254,7 @@ services:
- bitcoind
customer_lnd:
image: btcpayserver/lnd:v0.7.0-beta
image: btcpayserver/lnd:v0.7.1-beta-withseed
restart: unless-stopped
environment:
LND_CHAIN: "btc"
@ -273,7 +272,6 @@ services:
bitcoin.defaultchanconfs=1
no-macaroons=1
debuglevel=debug
noseedbackup=1
trickledelay=1000
ports:
- "53281:8080"

@ -1,27 +0,0 @@
using AspNet.Security.OpenIdConnect.Primitives;
using BTCPayServer.Data;
using BTCPayServer.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using OpenIddict.Core;
namespace BTCPayServer.Authentication.OpenId
{
public class AuthorizationCodeGrantTypeEventHandler : OpenIdGrantHandlerCheckCanSignIn
{
public AuthorizationCodeGrantTypeEventHandler(
OpenIddictApplicationManager<BTCPayOpenIdClient> applicationManager,
OpenIddictAuthorizationManager<BTCPayOpenIdAuthorization> authorizationManager,
SignInManager<ApplicationUser> signInManager,
IOptions<IdentityOptions> identityOptions,
UserManager<ApplicationUser> userManager) : base(applicationManager, authorizationManager, signInManager,
identityOptions, userManager)
{
}
protected override bool IsValid(OpenIdConnectRequest request)
{
return request.IsAuthorizationCodeGrantType();
}
}
}

@ -1,39 +0,0 @@
using System;
using System.Threading.Tasks;
using BTCPayServer.Data;
using BTCPayServer.Models;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using OpenIddict.Core;
using OpenIddict.Server;
namespace BTCPayServer.Authentication.OpenId
{
public class LogoutEventHandler : BaseOpenIdGrantHandler<OpenIddictServerEvents.HandleLogoutRequest>
{
public LogoutEventHandler(
OpenIddictApplicationManager<BTCPayOpenIdClient> applicationManager,
OpenIddictAuthorizationManager<BTCPayOpenIdAuthorization> authorizationManager,
SignInManager<ApplicationUser> signInManager, IOptions<IdentityOptions> identityOptions) : base(
applicationManager, authorizationManager,
signInManager, identityOptions)
{
}
public override async Task<OpenIddictServerEventState> HandleAsync(
OpenIddictServerEvents.HandleLogoutRequest notification)
{
// Ask ASP.NET Core Identity to delete the local and external cookies created
// when the user agent is redirected from the external identity provider
// after a successful authentication flow (e.g Google or Facebook).
await _signInManager.SignOutAsync();
// Returning a SignOutResult will ask OpenIddict to redirect the user agent
// to the post_logout_redirect_uri specified by the client application.
await notification.Context.HttpContext.SignOutAsync(OpenIddictServerDefaults.AuthenticationScheme);
notification.Context.HandleResponse();
return OpenIddictServerEventState.Handled;
}
}
}

@ -1,139 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using AspNet.Security.OpenIdConnect.Extensions;
using AspNet.Security.OpenIdConnect.Primitives;
using BTCPayServer.Data;
using BTCPayServer.Models;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Identity;
using OpenIddict.Abstractions;
using OpenIddict.Core;
using OpenIddict.Server;
namespace BTCPayServer.Authentication.OpenId
{
public static class OpenIdExtensions
{
public static async Task<AuthenticationTicket> CreateAuthenticationTicket(
OpenIddictApplicationManager<BTCPayOpenIdClient> applicationManager,
OpenIddictAuthorizationManager<BTCPayOpenIdAuthorization> authorizationManager,
IdentityOptions identityOptions,
SignInManager<ApplicationUser> signInManager,
OpenIdConnectRequest request,
ApplicationUser user,
AuthenticationProperties properties = null)
{
// Create a new ClaimsPrincipal containing the claims that
// will be used to create an id_token, a token or a code.
var principal = await signInManager.CreateUserPrincipalAsync(user);
// Create a new authentication ticket holding the user identity.
var ticket = new AuthenticationTicket(principal, properties,
OpenIddictServerDefaults.AuthenticationScheme);
if (!request.IsAuthorizationCodeGrantType() && !request.IsRefreshTokenGrantType())
{
ticket.SetScopes(request.GetScopes());
}
else if (request.IsAuthorizationCodeGrantType() &&
string.IsNullOrEmpty(ticket.GetInternalAuthorizationId()))
{
var app = await applicationManager.FindByClientIdAsync(request.ClientId);
var authorizationId = await IsUserAuthorized(authorizationManager, request, user.Id, app.Id);
if (!string.IsNullOrEmpty(authorizationId))
{
ticket.SetInternalAuthorizationId(authorizationId);
}
}
foreach (var claim in ticket.Principal.Claims)
{
claim.SetDestinations(GetDestinations(identityOptions, claim, ticket));
}
return ticket;
}
private static IEnumerable<string> GetDestinations(IdentityOptions identityOptions, Claim claim,
AuthenticationTicket ticket)
{
// Note: by default, claims are NOT automatically included in the access and identity tokens.
// To allow OpenIddict to serialize them, you must attach them a destination, that specifies
// whether they should be included in access tokens, in identity tokens or in both.
switch (claim.Type)
{
case OpenIddictConstants.Claims.Name:
yield return OpenIddictConstants.Destinations.AccessToken;
if (ticket.HasScope(OpenIddictConstants.Scopes.Profile))
yield return OpenIddictConstants.Destinations.IdentityToken;
yield break;
case OpenIddictConstants.Claims.Email:
yield return OpenIddictConstants.Destinations.AccessToken;
if (ticket.HasScope(OpenIddictConstants.Scopes.Email))
yield return OpenIddictConstants.Destinations.IdentityToken;
yield break;
case OpenIddictConstants.Claims.Role:
yield return OpenIddictConstants.Destinations.AccessToken;
if (ticket.HasScope(OpenIddictConstants.Scopes.Roles))
yield return OpenIddictConstants.Destinations.IdentityToken;
yield break;
default:
if (claim.Type == identityOptions.ClaimsIdentity.SecurityStampClaimType)
{
// Never include the security stamp in the access and identity tokens, as it's a secret value.
yield break;
}
else
{
yield return OpenIddictConstants.Destinations.AccessToken;
yield break;
}
}
}
public static async Task<string> IsUserAuthorized(
OpenIddictAuthorizationManager<BTCPayOpenIdAuthorization> authorizationManager,
OpenIdConnectRequest request, string userId, string applicationId)
{
var authorizations =
await authorizationManager.ListAsync(queryable =>
queryable.Where(authorization =>
authorization.Subject.Equals(userId, StringComparison.OrdinalIgnoreCase) &&
applicationId.Equals(authorization.Application.Id, StringComparison.OrdinalIgnoreCase) &&
authorization.Status.Equals(OpenIddictConstants.Statuses.Valid,
StringComparison.OrdinalIgnoreCase)));
if (authorizations.Length > 0)
{
var scopeTasks = authorizations.Select(authorization =>
(authorizationManager.GetScopesAsync(authorization).AsTask(), authorization.Id));
await Task.WhenAll(scopeTasks.Select((tuple) => tuple.Item1));
var authorizationsWithSufficientScopes = scopeTasks
.Select((tuple) => (tuple.Id, Scopes: tuple.Item1.Result))
.Where((tuple) => !request.GetScopes().Except(tuple.Scopes).Any());
if (authorizationsWithSufficientScopes.Any())
{
return authorizationsWithSufficientScopes.First().Id;
}
}
return null;
}
}
}

@ -1,27 +0,0 @@
using AspNet.Security.OpenIdConnect.Primitives;
using BTCPayServer.Data;
using BTCPayServer.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using OpenIddict.Core;
namespace BTCPayServer.Authentication.OpenId
{
public class RefreshTokenGrantTypeEventHandler : OpenIdGrantHandlerCheckCanSignIn
{
public RefreshTokenGrantTypeEventHandler(
OpenIddictApplicationManager<BTCPayOpenIdClient> applicationManager,
OpenIddictAuthorizationManager<BTCPayOpenIdAuthorization> authorizationManager,
SignInManager<ApplicationUser> signInManager,
IOptions<IdentityOptions> identityOptions, UserManager<ApplicationUser> userManager) : base(
applicationManager, authorizationManager, signInManager,
identityOptions, userManager)
{
}
protected override bool IsValid(OpenIdConnectRequest request)
{
return request.IsRefreshTokenGrantType();
}
}
}

@ -5,21 +5,18 @@
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Build\dockerfiles\**" />
<Compile Remove="Build\**" />
<Compile Remove="Storage\Services\Providers\GoogleCloudStorage\**" Condition="'$(TargetFramework)' != 'netcoreapp2.1'" />
<Compile Remove="wwwroot\bundles\jqueryvalidate\**" />
<Compile Remove="wwwroot\css\**" />
<Compile Remove="wwwroot\vendor\jquery-nice-select\**" />
<Content Remove="Build\dockerfiles\**" />
<Content Remove="Build\**" />
<Content Remove="wwwroot\bundles\jqueryvalidate\**" />
<Content Remove="wwwroot\css\**" />
<Content Remove="wwwroot\vendor\jquery-nice-select\**" />
<EmbeddedResource Remove="Build\dockerfiles\**" />
<EmbeddedResource Remove="Build\**" />
<EmbeddedResource Remove="wwwroot\bundles\jqueryvalidate\**" />
<EmbeddedResource Remove="wwwroot\css\**" />
<EmbeddedResource Remove="wwwroot\vendor\jquery-nice-select\**" />
<None Remove="Build\dockerfiles\**" />
<None Remove="Build\**" />
<None Remove="wwwroot\bundles\jqueryvalidate\**" />
<None Remove="wwwroot\css\**" />
<None Remove="wwwroot\vendor\jquery-nice-select\**" />
</ItemGroup>
<ItemGroup>
@ -30,25 +27,25 @@
<EmbeddedResource Include="Currencies.txt" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BTCPayServer.Lightning.All" Version="1.1.1" />
<PackageReference Include="BuildBundlerMinifier" Version="3.0.415" />
<PackageReference Include="BundlerMinifier.Core" Version="3.0.415" />
<PackageReference Include="BundlerMinifier.TagHelpers" Version="3.0.415" />
<PackageReference Include="BTCPayServer.Hwi" Version="1.1.2" />
<PackageReference Include="BTCPayServer.Lightning.All" Version="1.1.5" />
<PackageReference Include="BuildBundlerMinifier" Version="3.1.430" />
<PackageReference Include="BundlerMinifier.Core" Version="3.1.430" />
<PackageReference Include="BundlerMinifier.TagHelpers" Version="3.1.430" />
<PackageReference Include="HtmlSanitizer" Version="4.0.217" />
<PackageReference Include="LedgerWallet" Version="2.0.0.3" />
<PackageReference Include="LedgerWallet" Version="2.0.0.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.2" />
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="2.6.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="NBitpayClient" Version="1.0.0.34" />
<PackageReference Include="DBriize" Version="1.0.0.4" />
<PackageReference Include="DBriize" Version="1.0.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NicolasDorier.CommandLine" Version="1.0.0.2" />
<PackageReference Include="NicolasDorier.CommandLine.Configuration" Version="1.0.0.3" />
<PackageReference Include="NicolasDorier.RateLimits" Version="1.0.0.9" />
<PackageReference Include="NicolasDorier.StandardConfiguration" Version="1.0.0.18" />
<PackageReference Include="OpenIddict" Version="2.0.0" />
<PackageReference Include="Serilog" Version="2.7.1" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
@ -60,22 +57,27 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.9" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.9" AllowExplicitVersion="true" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
<PackageReference Include="TwentyTwenty.Storage" Version="2.11.2" />
<PackageReference Include="TwentyTwenty.Storage.Amazon" Version="2.11.2" />
<PackageReference Include="TwentyTwenty.Storage.Azure" Version="2.11.2" />
<PackageReference Include="TwentyTwenty.Storage.Google" Version="2.11.2" />
<PackageReference Include="TwentyTwenty.Storage.Google" Version="2.11.2" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
<PackageReference Include="TwentyTwenty.Storage.Local" Version="2.11.2" />
<PackageReference Include="U2F.Core" Version="1.0.4" />
<PackageReference Include="YamlDotNet" Version="5.2.1" />
<PackageReference Include="OpenIddict" Version="3.0.0-alpha1.19515.63" />
<PackageReference Include="OpenIddict.Server.AspNetCore" Version="3.0.0-alpha1.19515.63"></PackageReference>
<PackageReference Include="OpenIddict.Validation.AspNetCore" Version="3.0.0-alpha1.19515.63"></PackageReference>
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp2.1'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.0"></PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<None Include="wwwroot\vendor\bootstrap4-creativestart\creative.js" />
<None Include="wwwroot\main\bootstrap4-creativestart\creative.js" />
<None Include="wwwroot\vendor\font-awesome\fonts\fontawesome-webfont.svg" />
<None Include="wwwroot\vendor\font-awesome\fonts\fontawesome-webfont.woff2" />
<None Include="wwwroot\vendor\font-awesome\less\animated.less" />
@ -120,9 +122,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Authentication\OpenId\Models\" />
<Folder Include="Build\" />
<Folder Include="U2F\Services" />
<Folder Include="wwwroot\vendor\clipboard.js\" />
<Folder Include="wwwroot\vendor\highlightjs\" />
<Folder Include="wwwroot\vendor\summernote" />
@ -152,6 +151,12 @@
<Content Update="Views\Server\LightningWalletServices.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Views\Server\LndSeedBackup.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Views\Server\RPCService.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Views\Server\P2PService.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
@ -197,12 +202,17 @@
<Content Update="Views\Wallets\WalletRescan.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Views\Wallets\WalletSendVault.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Views\Wallets\WalletSendLedger.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Views\Wallets\WalletTransactions.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Remove="Views\Server\EditGoogleCloudStorageStorageProvider.cshtml" Condition="'$(TargetFramework)' != 'netcoreapp2.1'">
</Content>
<Content Update="Views\Wallets\_Nav.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>

@ -58,7 +58,16 @@ namespace BTCPayServer.Configuration
public static string GetDebugLog(IConfiguration configuration)
{
return configuration.GetValue<string>("debuglog", null);
var logfile = configuration.GetValue<string>("debuglog", null);
if (!string.IsNullOrEmpty(logfile))
{
if (!Path.IsPathRooted(logfile))
{
var networkType = DefaultConfiguration.GetNetworkType(configuration);
logfile = Path.Combine(configuration.GetDataDir(networkType), logfile);
}
}
return logfile;
}
public static LogEventLevel GetDebugLogLevel(IConfiguration configuration)
{

@ -47,6 +47,7 @@ namespace BTCPayServer.Configuration
app.Option("--debuglog", "A rolling log file for debug messages.", CommandOptionType.SingleValue);
app.Option("--debugloglevel", "The severity you log (default:information)", CommandOptionType.SingleValue);
app.Option("--disable-registration", "Disables new user registrations (default:true)", CommandOptionType.SingleValue);
app.Option("--xforwardedproto", "If specified, set X-Forwarded-Proto to the specified value, this may be useful if your reverse proxy handle https but is not configured to add X-Forwarded-Proto (example: --xforwardedproto https)", CommandOptionType.SingleValue);
foreach (var network in provider.GetAll().OfType<BTCPayNetwork>())
{
var crypto = network.CryptoCode.ToLowerInvariant();

@ -142,6 +142,12 @@ namespace BTCPayServer.Configuration
Macaroons = Macaroons?.Clone()
};
}
public bool? IsOnion()
{
if (this.Server == null || !this.Server.IsAbsoluteUri)
return null;
return this.Server.DnsSafeHost.EndsWith(".onion", StringComparison.OrdinalIgnoreCase);
}
public static bool TryParse(string str, out ExternalConnectionString result, out string error)
{
if (str == null)

@ -24,6 +24,10 @@ namespace BTCPayServer.Configuration
"lnd server: 'server=https://lnd.example.com;macaroondirectorypath=/root/.lnd;certthumbprint=2abdf302...'" + Environment.NewLine +
"Error: {1}",
"LND (REST server)");
Load(configuration, cryptoCode, "lndseedbackup", ExternalServiceTypes.LNDSeedBackup, "Invalid setting {0}, " + Environment.NewLine +
"lnd seed backup: /etc/merchant_lnd/data/chain/bitcoin/regtest/walletunlock.json'" + Environment.NewLine +
"Error: {1}",
"LND Seed Backup");
Load(configuration, cryptoCode, "spark", ExternalServiceTypes.Spark, "Invalid setting {0}, " + Environment.NewLine +
$"Valid example: 'server=https://btcpay.example.com/spark/btc/;cookiefile=/etc/clightning_bitcoin_spark/.cookie'" + Environment.NewLine +
"Error: {1}",
@ -45,11 +49,17 @@ namespace BTCPayServer.Configuration
var connStr = configuration.GetOrDefault<string>(setting, string.Empty);
if (connStr.Length != 0)
{
if (!ExternalConnectionString.TryParse(connStr, out var connectionString, out var error))
ExternalConnectionString serviceConnection;
if (type == ExternalServiceTypes.LNDSeedBackup)
{
// just using CookieFilePath to hold variable instead of refactoring whole holder class to better conform
serviceConnection = new ExternalConnectionString { CookieFilePath = connStr };
}
else if (!ExternalConnectionString.TryParse(connStr, out serviceConnection, out var error))
{
throw new ConfigException(string.Format(CultureInfo.InvariantCulture, errorMessage, setting, error));
}
this.Add(new ExternalService() { Type = type, ConnectionString = connectionString, CryptoCode = cryptoCode, DisplayName = displayName, ServiceName = serviceName });
this.Add(new ExternalService() { Type = type, ConnectionString = serviceConnection, CryptoCode = cryptoCode, DisplayName = displayName, ServiceName = serviceName });
}
}
@ -73,9 +83,11 @@ namespace BTCPayServer.Configuration
{
LNDRest,
LNDGRPC,
LNDSeedBackup,
Spark,
RTL,
Charge,
P2P
P2P,
RPC
}
}

@ -1,6 +1,7 @@
using BTCPayServer.Authentication;
using BTCPayServer.Filters;
using BTCPayServer.Filters;
using BTCPayServer.Models;
using BTCPayServer.Security;
using BTCPayServer.Security.Bitpay;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
@ -13,7 +14,7 @@ using System.Threading.Tasks;
namespace BTCPayServer.Controllers
{
[Authorize(AuthenticationSchemes = Security.Policies.BitpayAuthentication)]
[Authorize(AuthenticationSchemes = Security.AuthenticationSchemes.Bitpay)]
[BitpayAPIConstraint()]
public class AccessTokenController : Controller
{

@ -18,15 +18,15 @@ using BTCPayServer.Services.Stores;
using BTCPayServer.Logging;
using BTCPayServer.Security;
using System.Globalization;
using BTCPayServer.Services.U2F;
using BTCPayServer.Services.U2F.Models;
using BTCPayServer.U2F;
using BTCPayServer.U2F.Models;
using Newtonsoft.Json;
using NicolasDorier.RateLimits;
using BTCPayServer.Data;
namespace BTCPayServer.Controllers
{
[Authorize(AuthenticationSchemes = Policies.CookieAuthentication)]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[Route("[controller]/[action]")]
public class AccountController : Controller
{
@ -74,21 +74,32 @@ namespace BTCPayServer.Controllers
[AllowAnonymous]
public async Task<IActionResult> Login(string returnUrl = null)
{
if (User.Identity.IsAuthenticated && string.IsNullOrEmpty(returnUrl))
return RedirectToLocal();
// Clear the existing external cookie to ensure a clean login process
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
if (!CanLoginOrRegister())
{
SetInsecureFlags();
}
ViewData["ReturnUrl"] = returnUrl;
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
[RateLimitsFilter(ZoneLimits.Login, Scope = RateLimitsScope.RemoteAddress)]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
{
if (!CanLoginOrRegister())
{
return RedirectToAction("Login");
}
ViewData["ReturnUrl"] = returnUrl;
if (ModelState.IsValid)
{
@ -199,6 +210,11 @@ namespace BTCPayServer.Controllers
[ValidateAntiForgeryToken]
public async Task<IActionResult> LoginWithU2F(LoginWithU2FViewModel viewModel, string returnUrl = null)
{
if (!CanLoginOrRegister())
{
return RedirectToAction("Login");
}
ViewData["ReturnUrl"] = returnUrl;
var user = await _userManager.FindByIdAsync(viewModel.UserId);
@ -242,6 +258,11 @@ namespace BTCPayServer.Controllers
[AllowAnonymous]
public async Task<IActionResult> LoginWith2fa(bool rememberMe, string returnUrl = null)
{
if (!CanLoginOrRegister())
{
return RedirectToAction("Login");
}
// Ensure the user has gone through the username & password screen first
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
@ -264,6 +285,11 @@ namespace BTCPayServer.Controllers
[ValidateAntiForgeryToken]
public async Task<IActionResult> LoginWith2fa(LoginWith2faViewModel model, bool rememberMe, string returnUrl = null)
{
if (!CanLoginOrRegister())
{
return RedirectToAction("Login");
}
if (!ModelState.IsValid)
{
return View(model);
@ -305,6 +331,11 @@ namespace BTCPayServer.Controllers
[AllowAnonymous]
public async Task<IActionResult> LoginWithRecoveryCode(string returnUrl = null)
{
if (!CanLoginOrRegister())
{
return RedirectToAction("Login");
}
// Ensure the user has gone through the username & password screen first
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
if (user == null)
@ -322,6 +353,11 @@ namespace BTCPayServer.Controllers
[ValidateAntiForgeryToken]
public async Task<IActionResult> LoginWithRecoveryCode(LoginWithRecoveryCodeViewModel model, string returnUrl = null)
{
if (!CanLoginOrRegister())
{
return RedirectToAction("Login");
}
if (!ModelState.IsValid)
{
return View(model);
@ -364,14 +400,19 @@ namespace BTCPayServer.Controllers
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> Register(string returnUrl = null, bool logon = true)
public async Task<IActionResult> Register(string returnUrl = null, bool logon = true, bool useBasicLayout = false)
{
if (!CanLoginOrRegister())
{
SetInsecureFlags();
}
var policies = await _SettingsRepository.GetSettingAsync<PoliciesSettings>() ?? new PoliciesSettings();
if (policies.LockSubscription && !User.IsInRole(Roles.ServerAdmin))
return RedirectToAction(nameof(HomeController.Index), "Home");
ViewData["ReturnUrl"] = returnUrl;
ViewData["Logon"] = logon.ToString(CultureInfo.InvariantCulture).ToLowerInvariant();
ViewData["AllowIsAdmin"] = _Options.AllowAdminRegistration;
ViewData["UseBasicLayout"] = useBasicLayout;
return View();
}
@ -380,6 +421,11 @@ namespace BTCPayServer.Controllers
[ValidateAntiForgeryToken]
public async Task<IActionResult> Register(RegisterViewModel model, string returnUrl = null, bool logon = true)
{
if (!CanLoginOrRegister())
{
return RedirectToAction("Register");
}
ViewData["ReturnUrl"] = returnUrl;
ViewData["Logon"] = logon.ToString(CultureInfo.InvariantCulture).ToLowerInvariant();
ViewData["AllowIsAdmin"] = _Options.AllowAdminRegistration;
@ -398,7 +444,9 @@ namespace BTCPayServer.Controllers
{
await _RoleManager.CreateAsync(new IdentityRole(Roles.ServerAdmin));
await _userManager.AddToRoleAsync(user, Roles.ServerAdmin);
var settings = await _SettingsRepository.GetSettingAsync<ThemeSettings>();
settings.FirstRun = false;
await _SettingsRepository.UpdateSetting<ThemeSettings>(settings);
if(_Options.DisableRegistration)
{
// Once the admin user has been created lock subsequent user registrations (needs to be disabled for unit tests that require multiple users).
@ -420,7 +468,7 @@ namespace BTCPayServer.Controllers
}
else
{
TempData["StatusMessage"] = "Account created, please confirm your email";
TempData[WellKnownTempData.SuccessMessage] = "Account created, please confirm your email";
return View();
}
}
@ -447,88 +495,6 @@ namespace BTCPayServer.Controllers
return RedirectToAction(nameof(HomeController.Index), "Home");
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public IActionResult ExternalLogin(string provider, string returnUrl = null)
{
// Request a redirect to the external login provider.
var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Account", new
{
returnUrl
});
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return Challenge(properties, provider);
}
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{
if (remoteError != null)
{
ErrorMessage = $"Error from external provider: {remoteError}";
return RedirectToAction(nameof(Login));
}
var info = await _signInManager.GetExternalLoginInfoAsync();
if (info == null)
{
return RedirectToAction(nameof(Login));
}
// Sign in the user with this external login provider if the user already has a login.
var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false, bypassTwoFactor: true);
if (result.Succeeded)
{
_logger.LogInformation("User logged in with {Name} provider.", info.LoginProvider);
return RedirectToLocal(returnUrl);
}
if (result.IsLockedOut)
{
return RedirectToAction(nameof(Lockout));
}
else
{
// If the user does not have an account, then ask the user to create an account.
ViewData["ReturnUrl"] = returnUrl;
ViewData["LoginProvider"] = info.LoginProvider;
var email = info.Principal.FindFirstValue(ClaimTypes.Email);
return View("ExternalLogin", new ExternalLoginViewModel { Email = email });
}
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginViewModel model, string returnUrl = null)
{
if (ModelState.IsValid)
{
// Get the information about the user from the external login provider
var info = await _signInManager.GetExternalLoginInfoAsync();
if (info == null)
{
throw new ApplicationException("Error loading external login information during confirmation.");
}
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await _userManager.CreateAsync(user);
if (result.Succeeded)
{
result = await _userManager.AddLoginAsync(user, info);
if (result.Succeeded)
{
await _signInManager.SignInAsync(user, isPersistent: false);
_logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
return RedirectToLocal(returnUrl);
}
}
AddErrors(result);
}
ViewData["ReturnUrl"] = returnUrl;
return View(nameof(ExternalLogin), model);
}
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ConfirmEmail(string userId, string code)
@ -659,6 +625,23 @@ namespace BTCPayServer.Controllers
return RedirectToAction(nameof(HomeController.Index), "Home");
}
}
private bool CanLoginOrRegister()
{
return _btcPayServerEnvironment.IsDevelopping || _btcPayServerEnvironment.IsSecure;
}
private void SetInsecureFlags()
{
TempData.SetStatusMessageModel(new StatusMessageModel()
{
Severity = StatusMessageModel.StatusSeverity.Error,
Message = "You cannot login over an insecure connection. Please use HTTPS or Tor."
});
ViewData["disabled"] = true;
}
#endregion
}

@ -68,7 +68,7 @@ namespace BTCPayServer.Controllers
}
[HttpPost]
[Route("{appId}/settings/crowdfund")]
public async Task<IActionResult> UpdateCrowdfund(string appId, UpdateCrowdfundViewModel vm)
public async Task<IActionResult> UpdateCrowdfund(string appId, UpdateCrowdfundViewModel vm, string command)
{
if (!string.IsNullOrEmpty( vm.TargetCurrency) && _currencies.GetCurrencyData(vm.TargetCurrency, false) == null)
ModelState.AddModelError(nameof(vm.TargetCurrency), "Invalid currency");
@ -156,16 +156,25 @@ namespace BTCPayServer.Controllers
app.TagAllInvoices = vm.UseAllStoreInvoices;
app.SetSettings(newSettings);
await _AppService.UpdateOrCreateApp(app);
_EventAggregator.Publish(new AppUpdated()
if (command == "save")
{
AppId = appId,
StoreId = app.StoreDataId,
Settings = newSettings
});
StatusMessage = "App updated";
return RedirectToAction(nameof(UpdateCrowdfund), new {appId});
await _AppService.UpdateOrCreateApp(app);
_EventAggregator.Publish(new AppUpdated()
{
AppId = appId,
StoreId = app.StoreDataId,
Settings = newSettings
});
TempData[WellKnownTempData.SuccessMessage] = "App updated";
return RedirectToAction(nameof(UpdateCrowdfund), new { appId });
}
else if (command == "viewapp")
{
return RedirectToAction(nameof(AppsPublicController.ViewCrowdfund), "AppsPublic", new { appId });
}
return NotFound();
}
}
}

@ -201,7 +201,7 @@ namespace BTCPayServer.Controllers
});
await _AppService.UpdateOrCreateApp(app);
StatusMessage = "App updated";
TempData[WellKnownTempData.SuccessMessage] = "App updated";
return RedirectToAction(nameof(UpdatePointOfSale), new { appId });
}

@ -19,7 +19,7 @@ using NBitcoin.DataEncoders;
namespace BTCPayServer.Controllers
{
[Authorize(AuthenticationSchemes = Policies.CookieAuthentication)]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[AutoValidateAntiforgeryToken]
[Route("apps")]
public partial class AppsController : Controller
@ -50,8 +50,6 @@ namespace BTCPayServer.Controllers
private readonly EmailSenderFactory _emailSenderFactory;
private AppService _AppService;
[TempData]
public string StatusMessage { get; set; }
public string CreatedAppId { get; set; }
public async Task<IActionResult> ListApps()
@ -71,7 +69,7 @@ namespace BTCPayServer.Controllers
if (appData == null)
return NotFound();
if (await _AppService.DeleteApp(appData))
StatusMessage = "App removed successfully";
TempData[WellKnownTempData.SuccessMessage] = "App removed successfully";
return RedirectToAction(nameof(ListApps));
}
@ -82,12 +80,12 @@ namespace BTCPayServer.Controllers
var stores = await _AppService.GetOwnedStores(GetUserId());
if (stores.Length == 0)
{
StatusMessage = new StatusMessageModel()
TempData.SetStatusMessageModel(new StatusMessageModel()
{
Html =
$"Error: You need to create at least one store. <a href='{(Url.Action("CreateStore", "UserStores"))}'>Create store</a>",
Severity = StatusMessageModel.StatusSeverity.Error
}.ToString();
});
return RedirectToAction(nameof(ListApps));
}
var vm = new CreateAppViewModel();
@ -102,12 +100,12 @@ namespace BTCPayServer.Controllers
var stores = await _AppService.GetOwnedStores(GetUserId());
if (stores.Length == 0)
{
StatusMessage = new StatusMessageModel()
TempData.SetStatusMessageModel(new StatusMessageModel()
{
Html =
$"Error: You need to create at least one store. <a href='{(Url.Action("CreateStore", "UserStores"))}'>Create store</a>",
Severity = StatusMessageModel.StatusSeverity.Error
}.ToString();
});
return RedirectToAction(nameof(ListApps));
}
var selectedStore = vm.SelectedStore;
@ -124,7 +122,7 @@ namespace BTCPayServer.Controllers
if (!stores.Any(s => s.Id == selectedStore))
{
StatusMessage = "Error: You are not owner of this store";
TempData[WellKnownTempData.ErrorMessage] = "You are not owner of this store";
return RedirectToAction(nameof(ListApps));
}
var appData = new AppData
@ -134,7 +132,7 @@ namespace BTCPayServer.Controllers
AppType = appType.ToString()
};
await _AppService.UpdateOrCreateApp(appData);
StatusMessage = "App successfully created";
TempData[WellKnownTempData.SuccessMessage] = "App successfully created";
CreatedAppId = appData.Id;
switch (appType)

Some files were not shown because too many files have changed in this diff Show More