-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import hashlib | ||
import os | ||
import shutil | ||
from pathlib import Path | ||
|
||
|
@@ -6,7 +8,12 @@ | |
|
||
from cashu.core.base import Unit | ||
from cashu.core.crypto.keys import random_hash | ||
from cashu.core.errors import BlindAuthFailedError, BlindAuthRateLimitExceededError | ||
from cashu.core.crypto.secp import PrivateKey | ||
from cashu.core.errors import ( | ||
BlindAuthFailedError, | ||
BlindAuthRateLimitExceededError, | ||
ClearAuthFailedError, | ||
) | ||
from cashu.core.settings import settings | ||
from cashu.wallet.auth.auth import WalletAuth | ||
from cashu.wallet.wallet import Wallet | ||
|
@@ -111,6 +118,45 @@ async def test_wallet_auth_mint_manually(wallet: Wallet): | |
assert len(auth_wallet.proofs) == auth_wallet.mint_info.bat_max_mint | ||
|
||
|
||
@pytest.mark.skipif( | ||
not settings.mint_require_auth, | ||
reason="settings.mint_require_auth is False", | ||
) | ||
@pytest.mark.asyncio | ||
async def test_wallet_auth_mint_manually_invalid_cat(wallet: Wallet): | ||
auth_wallet = await WalletAuth.with_db( | ||
url=wallet.url, | ||
db=wallet.db.db_location, | ||
username="[email protected]", | ||
password="asdasd", | ||
) | ||
|
||
requires_auth = await auth_wallet.init_auth_wallet( | ||
wallet.mint_info, mint_auth_proofs=False | ||
) | ||
assert requires_auth | ||
assert len(auth_wallet.proofs) == 0 | ||
|
||
# invalidate CAT in the database | ||
auth_wallet.oidc_client.access_token = random_hash() | ||
|
||
# this is the code executed in auth_wallet.mint_blind_auth(): | ||
clear_auth_token = auth_wallet.oidc_client.access_token | ||
if not clear_auth_token: | ||
raise Exception("No clear auth token available.") | ||
|
||
amounts = auth_wallet.mint_info.bat_max_mint * [1] # 1 AUTH tokens | ||
secrets = [hashlib.sha256(os.urandom(32)).hexdigest() for _ in amounts] | ||
rs = [PrivateKey(privkey=os.urandom(32), raw=True) for _ in amounts] | ||
outputs, rs = auth_wallet._construct_outputs(amounts, secrets, rs) | ||
|
||
# should fail because of invalid CAT | ||
await assert_err( | ||
auth_wallet.blind_mint_blind_auth(clear_auth_token, outputs), | ||
ClearAuthFailedError.detail, | ||
) | ||
|
||
|
||
@pytest.mark.skipif( | ||
not settings.mint_require_auth, | ||
reason="settings.mint_require_auth is False", | ||
|