diff --git a/lbry/blockchain/lbrycrd.py b/lbry/blockchain/lbrycrd.py index 62acedf10..71b6931ae 100644 --- a/lbry/blockchain/lbrycrd.py +++ b/lbry/blockchain/lbrycrd.py @@ -15,7 +15,7 @@ import zmq.asyncio from lbry.conf import Config from lbry.event import EventController -from lbry.error import LbrycrdEventSubscriptionError +from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError from .database import BlockchainDB from .ledger import Ledger, RegTestLedger @@ -248,6 +248,8 @@ class Lbrycrd: "params": params or [] } async with self.session.post(self.rpc_url, json=message) as resp: + if resp.status == 401: + raise LbrycrdUnauthorizedError() try: result = await resp.json() except aiohttp.ContentTypeError as e: diff --git a/lbry/error/README.md b/lbry/error/README.md index 791b63309..420e554bc 100644 --- a/lbry/error/README.md +++ b/lbry/error/README.md @@ -82,4 +82,5 @@ Code | Name | Message 702 | CurrencyConversion | {message} 703 | InvalidCurrency | Invalid currency: {currency} is not a supported currency. **8xx** | Lbrycrd | **Lbrycrd** +801 | LbrycrdUnauthorized | Failed to authenticate with lbrycrd. Perhaps wrong username or password? 811 | LbrycrdEventSubscription | Lbrycrd is not publishing '{event}' events. diff --git a/lbry/error/__init__.py b/lbry/error/__init__.py index 66fa6c0a7..57086d852 100644 --- a/lbry/error/__init__.py +++ b/lbry/error/__init__.py @@ -406,6 +406,12 @@ class LbrycrdError(BaseError): """ +class LbrycrdUnauthorizedError(LbrycrdError): + + def __init__(self): + super().__init__("Failed to authenticate with lbrycrd. Perhaps wrong username or password?") + + class LbrycrdEventSubscriptionError(LbrycrdError): def __init__(self, event): diff --git a/tests/integration/blockchain/test_blockchain.py b/tests/integration/blockchain/test_blockchain.py index aa0d4339d..9be8d1112 100644 --- a/tests/integration/blockchain/test_blockchain.py +++ b/tests/integration/blockchain/test_blockchain.py @@ -11,7 +11,7 @@ from lbry import Config, Database, RegTestLedger, Transaction, Output, Input from lbry.crypto.base58 import Base58 from lbry.schema.claim import Stream, Channel from lbry.schema.support import Support -from lbry.error import LbrycrdEventSubscriptionError +from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError from lbry.blockchain.lbrycrd import Lbrycrd from lbry.blockchain.sync import BlockchainSync from lbry.blockchain.dewies import dewies_to_lbc, lbc_to_dewies @@ -284,7 +284,16 @@ class SyncingBlockchainTestCase(BasicBlockchainTestCase): self.assertEqual(accepted or [], await self.get_accepted()) -class TestLbrycrdEvents(AsyncioTestCase): +class TestLbrycrdAPIs(AsyncioTestCase): + + async def test_unauthorized(self): + chain = Lbrycrd.temp_regtest() + await chain.ensure() + await chain.start() + await chain.get_new_address() + chain.conf.set(lbrycrd_rpc_pass='wrong') + with self.assertRaises(LbrycrdUnauthorizedError): + await chain.get_new_address() async def test_zmq(self): chain = Lbrycrd.temp_regtest()