Skip to content

Commit

Permalink
lyrebird v3.10.0 :rm mitmproxy from install require and support pytho…
Browse files Browse the repository at this point in the history
…n3.10 (#688)

* support py3.10; rm mitmproxy from install require

* update tests requirements

* Fix dm api code 400

* Fix UT: conf-api 400

* update e2e tests

* Add gh-pages publish action

* actions/checkout@2

* actions/checkout@v3

* Fix gh-pages actions path error

* update gh-pages job name

* Test PAT

* use new gh-pages plugin

* add new key github token

* use JamesIves/github-pages-deploy-action@v3

* update actions id

* add username for gh-pages publish action

* update gh-pages action

* update gh-pages action

* Add permissions for gh-pages action

* update github actions job name

* Add github token permissions setting

* update gh-pages action

* Add mitm installer

* Dockerfile: install mitmproxy into a special pythonpath; Fix e2e tests

* Add py3.11 support

* rm python 3.11 support

* rm mitm installer from cmdline

* rm unused import

* Fix code review comments

* Fix activate API error

* Add UT for datamanager api

* Fix no_mitm args error
  • Loading branch information
zhaoye authored Nov 3, 2022
1 parent 8e75eb5 commit 69771bd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 41 deletions.
20 changes: 0 additions & 20 deletions lyrebird/installer.py

This file was deleted.

12 changes: 5 additions & 7 deletions lyrebird/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
from lyrebird.notice_center import NoticeCenter
from lyrebird.plugins import PluginManager
from lyrebird.mitm.proxy_server import LyrebirdProxyServer
from lyrebird.mitm import init_mitm
from lyrebird.task import BackgroundTaskServer
from lyrebird.base_server import MultiProcessServerMessageDispatcher
from lyrebird import utils
from lyrebird import installer


logger = log.get_logger()

Expand Down Expand Up @@ -151,9 +150,6 @@ def thread_excepthook(args):
if args.sub_command == 'gen':
logger.debug('EXEC: Plugin project generator')
gen(args)
elif args.sub_command == 'install':
logger.debug('EXEC: Installer')
installer.install(args.extension_name)
else:
logger.debug('EXEC: LYREBIRD START')
run(args)
Expand Down Expand Up @@ -183,9 +179,11 @@ def run(args: argparse.Namespace):
application.server['task'] = BackgroundTaskServer()

# Start mitmproxy server
conf_no_mitm = application._cm.config.get('no_mitm', None)
# if set --no-mitm in commandline , skip start proxy server
# if set proxy.no_mitm in config file, skip start proxy server
conf_no_mitm = application._cm.config.get('proxy.no_mitm', False)
args_no_mitm = args.no_mitm
if conf_no_mitm is None:
if args_no_mitm:
should_start_mitm = not args_no_mitm
else:
should_start_mitm = not conf_no_mitm
Expand Down
2 changes: 1 addition & 1 deletion lyrebird/mitm/mitm_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def download_mitmproxy():

resp = requests.get(download_url, stream=True)
content_length = int(resp.headers.get('content-length'))
click.secho(f'\nmitmdupm not found\nStart downloading mitmproxy: {download_url}')
click.secho(f'\nmitmdump not found\nStart downloading mitmproxy: {download_url}')
with click.progressbar(length=content_length) as bar, tempfile.NamedTemporaryFile('w+b') as tempf:
for chunk in resp.iter_content(4*2048):
tempf.write(chunk)
Expand Down
1 change: 0 additions & 1 deletion lyrebird/mitm/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def run(self, queue, config, *args, **kwargs):
# Init logger
log.init(config)
logger = log.get_logger()
# TODO
mitm_path = kwargs.get('mitm_path')
self.start_mitmdump(config, logger, mitm_path)

Expand Down
10 changes: 8 additions & 2 deletions lyrebird/mock/blueprints/apis/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,14 @@ def get(self):
def put(self, group_id=None, action=None):
if action == 'activate':
# Only one group could be activated
if request.is_json and request.json.get('info'):
context.application.data_manager.activate(group_id, info=request.json.get('info'))
if request.is_json:
try:
info = request.json.get('info')
context.application.data_manager.activate(group_id, info=info)
except Exception:
# If a request have json content-type but dose not have body.
# Handle flask exception when parse json failed.
context.application.data_manager.activate(group_id)
else:
context.application.data_manager.activate(group_id)
elif action == 'deactivate':
Expand Down
27 changes: 17 additions & 10 deletions tests/test_dm_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,18 @@ def test_data_post(client):
'id': 'dataB-UUID',
'name': 'dataB',
'parent_id': 'root',
'data':
'data':
{
'id': 'dataB-UUID',
'name': 'dataB',
'rule': {
'request.data.sort': None,
'request.url': '(?=.*search)'
},
'request': {
'url': 'http://unittest.com/api/detail'
'id': 'dataB-UUID',
'name': 'dataB',
'rule': {
'request.data.sort': None,
'request.url': '(?=.*search)'
},
'request': {
'url': 'http://unittest.com/api/detail'
}
}
}
})
assert resp.json['code'] == 1000

Expand Down Expand Up @@ -195,6 +195,13 @@ def test_data_activate_with_info(client):
assert resp.json['code'] == 1000


def test_data_activate_without_body(client):
data_id = 'dataA-UUID'
action = 'activate'
resp = client.put(f'/api/mock/{data_id}/{action}', headers={'Content-Type': 'application/json'})
assert resp.json['code'] == 1000


def test_data_deactivate(client):
data_id = 'dataA-UUID'
action = 'deactivate'
Expand Down

0 comments on commit 69771bd

Please sign in to comment.