2018-06-05 12:18:16 +00:00
import pytest
2018-06-05 20:52:18 +00:00
import time
from mastodon . Mastodon import MastodonNotFoundError
2018-06-05 12:18:16 +00:00
def test_decrypt ( api ) :
priv = {
' auth ' : b ' \xe7 y \x0f p \xb9 \x92 \xe0 \xa0 \xc5 \xd5 ~Qr \xd7 \xaa \x16 ' ,
' privkey ' : 86377660131518823691452242868806126400423244879788569019894692873283793307753
}
# Yes, I am aware that there is an access token in there. It's not valid anymore.
encryption_header = " salt=O14vjCdbxxhRUTkrsp98vw "
crypto_key_header = " dh=BKz_CMlF6kVURVImPDsz3bNbTv-9QTGtXpE4Fd3wQGF44fVTj32-APndoccYdjXY2U-mdTen1PDm_pHacpEmD0M;p256ecdsa=BDSAB3e_l5Qp4X50UYSSrKiZFZWDAgHlWIDhgBjXJuUzb0HrpqoCdFhMCh4o2xYHTqpvyTJ3SfFtrILLiXXWT5k "
data = b ' \x10 \\ b< \xdd i \xac d \x86 \xc8 J1 \xb6 }5 \x01 K \x85 ; \xd2 \xd4 WzN \xab \x0b |3D \xe9 _YPcsG \x9f h \xae \xfe \xbb :z& \xc4 \x8e k \x89 \xde \xa2 \xdb F \xdc \xdd [p<h \x9e \x95 \x8d \xd4 \xf0 \xd0 \xc1 \x89 \t \x01 \xeb uV \xb1 \xa4 Fp \xe3 \xbf \x91 g \x93 \xbe \xe5 \xd4 \xee \xe2 \xb0 FaB \x8a \xd0 \x00 b \xe4 Q \x83 \xd5 \xd9 \x83 \x9a \x1d \xd5 j \xdb " \xc5 \xb0 \xf5 W \xa7 2r4r]aLs \xa8 \x8c \x1a \x19 h \xfe X)_t \xd4 p \xc9 \xd2 d \x1b ? \x19 \xc8 X( \x02 \xd5 \x18 \xe4 \x93 \xe2 \xda \x01 \xb4 b \xe4 \xd0 F \x08 ` \x13 ;> \xc4 \x89 \xbc \xc3 \x8e \xb8 \x9b J~ \xc4 }] \xdb \xdc \xf1 wY \x16 g \xf8 \x91 N \xee \xfd \x92 \x1e \xcd \xd2 ~ \xf2 \x06 \x89 \xcd \xa5 \xcd \x97 \xb7 { \xc5 \xe1 \xe4 \xb0 \x9f 7 \xc6 \x8a 5 \xda \xbb m \xce \xc5 \x8d \x93 `& \x0e \xa9 \x83 \xa2 |p; \xa4 \x8b ) \xc8 \x07 \r b!a \x82 \xf5 E \x92 \x00 Y { \xd4 \x94 \xf8 \xf0 \r \xb5 c \x86 \xfb \xd0 * \xbb \xa1 ! \x14 \xd5 \x11 \xc8 \xaf I \xb3 j \xca 7 \xc4 \x9c \xe0 \x9c 0 \x12 \xc0 \xd1 \x8a { \xcd \xc4 ~ \\ \xc2 \x99 \xf0 d) \x03 E \x91 ;m \xbe \xdb \x86 \xef \xd7 \xa7 > \xd1 a \xf1 \x83 ! \xae B \xaa \xf0 \xda \x1b ; \x86 \xd8 ;] \x9e \xe3 \xfa *! \x07 , \t \xbd \xe7 \xfc \xa7 \xa8 \xba [ \xcf \x89 e \xac \' \xdb \x88 g \xd9 \\ \xe4 C \x08 Lb \xb6 CAT \xcc ! \xa4 \xce \x92 t3 \x1c 1 \x01 '
decrypted = api . push_subscription_decrypt_push (
data ,
priv ,
encryption_header ,
crypto_key_header
)
assert decrypted
assert decrypted . title == ' You were mentioned by fake halcy '
2018-06-05 20:52:18 +00:00
@pytest.mark.vcr ( match_on = [ ' path ' ] )
def test_push_set ( api ) :
priv , pub = api . push_subscription_generate_keys ( )
2022-11-18 23:59:17 +00:00
sub = api . push_subscription_set ( " example.com " , pub , follow_events = True , favourite_events = True , reblog_events = True , mention_events = True , poll_events = True , follow_request_events = True , status_events = True , policy = ' none ' )
2018-06-05 20:52:18 +00:00
assert sub == api . push_subscription ( )
assert sub . endpoint == " https://example.com "
2022-11-18 23:59:17 +00:00
should_throw = False
try :
sub = api . push_subscription_set ( " example.com " , pub , follow_events = True , favourite_events = True , reblog_events = True , mention_events = True , poll_events = True , follow_request_events = True , status_events = True , policy = ' not a valid value ' )
should_throw = True
except :
pass
assert not should_throw
2018-06-05 20:52:18 +00:00
@pytest.mark.vcr ( match_on = [ ' path ' ] )
def test_push_update ( api ) :
priv , pub = api . push_subscription_generate_keys ( )
sub = api . push_subscription_set ( " example.com " , pub , follow_events = False ,
favourite_events = False , reblog_events = False ,
mention_events = False )
sub2 = api . push_subscription_update ( follow_events = True , favourite_events = True ,
reblog_events = True , mention_events = True )
time . sleep ( 1 )
assert sub2 == api . push_subscription ( )
sub3 = api . push_subscription_update ( follow_events = False , favourite_events = False ,
reblog_events = False , mention_events = False )
time . sleep ( 1 )
assert sub3 == api . push_subscription ( )
2019-10-11 21:59:24 +00:00
print ( sub3 )
print ( api . push_subscription ( ) )
2018-06-05 20:52:18 +00:00
2022-11-20 19:22:48 +00:00
assert sub3 . alerts . follow is False
assert sub3 . alerts . favourite is False
assert sub3 . alerts . reblog is False
assert sub3 . alerts . mention is False
assert sub2 . alerts . follow is True
assert sub2 . alerts . favourite is True
assert sub2 . alerts . reblog is True
assert sub2 . alerts . mention is True
2018-06-05 20:52:18 +00:00
@pytest.mark.vcr ( match_on = [ ' path ' ] )
def test_push_delete ( api ) :
priv , pub = api . push_subscription_generate_keys ( )
sub = api . push_subscription_set ( " example.com " , pub )
assert sub
api . push_subscription_delete ( )
with pytest . raises ( MastodonNotFoundError ) :
2019-05-10 22:55:40 +00:00
api . push_subscription ( )