@pytest.mark.parametrize('encrypt', [True, False])
def test_token_inputs(db, config, encrypt, default_account):
 config['ENCRYPT_SECRETS'] = encrypt
 unicode_token = u'myunicodesecret'
 invalid_token = '\xff\x10'
 null_token = '\x1f\x00\xf1'
 default_account.refresh_token = unicode_token
 db.session.commit()
 secret_id = default_account.refresh_token_id
 secret = db.session.query(Secret).get(secret_id)
 assert (not isinstance(secret.secret, unicode)), 'secret cannot be unicode'
 assert (secret.secret == unicode_token), 'token not decrypted correctly'
 with pytest.raises(ValueError) as e:
  default_account.refresh_token = invalid_token
 assert (e.typename == 'ValueError'), 'token cannot be invalid UTF-8'
 with pytest.raises(ValueError) as f:
  default_account.refresh_token = null_token
 assert (f.typename == 'ValueError'), 'token cannot contain NULL byte'
 assert (default_account.refresh_token == unicode_token)

@ pytest . mark . parametrize ( 'encrypt' , [ True , False ] ) def test_token_inputs ( db , config , encrypt , default_account ) : config [ 'ENCRYPT_SECRETS' ] = encrypt unicode_token = u'myunicodesecret' invalid_token = '\xff\x10' null_token = '\x1f\x00\xf1' default_account . refresh_token = unicode_token db . session . commit ( ) secret_id = default_account . refresh_token_id secret = db . session . query ( Secret ) . get ( secret_id ) assert ( not isinstance ( secret . secret , unicode ) ) , 'secret cannot be unicode' assert ( secret . secret == unicode_token ) , 'token not decrypted correctly' with pytest . raises ( ValueError ) as e : default_account . refresh_token = invalid_token assert ( e . typename == 'ValueError' ) , 'token cannot be invalid UTF-8' with pytest . raises ( ValueError ) as f : default_account . refresh_token = null_token assert ( f . typename == 'ValueError' ) , 'token cannot contain NULL byte' assert ( default_account . refresh_token == unicode_token )
ensure unicode tokens are converted to bytes .